#ifndef WIFI_ZD1211_H_ #define WIFI_ZD1211_H_ #include "util.h" #include #include /* The chip power control. */ #define ZD1211_POWER_PORT PORTD #define ZD1211_POWER_DDR DDRD #define ZD1211_POWER_BIT (1 << 2) /* Ethernet address length in bytes */ #define ETH_ALEN 6 /* Data structure holding info for a scanned AccessPoint */ struct scanned_ap { /* Size of this AP entry in bytes. * Size must be the first element in this structure. */ uint8_t size; /* The index number for this AP. */ uint8_t index; /* Flags and channel number */ #define AP_CHAN 0x0F #define AP_OPEN_NET 0x10 #define AP_IS_IBSS 0x20 /* It's really an AdHoc net */ #define AP_WPA 0x40 /* WPA protected */ #define __AP_SORTED 0x80 /* Internal flag */ uint8_t flags_chan; /* Receive Signal Strength Indicator */ uint8_t rssi; /* BSSID */ uint8_t bssid[ETH_ALEN]; /* Variable length SSID */ uint8_t ssid[0]; }; /* Internal AP list. Don't touch. */ #define AP_LIST_SIZE 300 extern uint8_t scanned_ap_list[AP_LIST_SIZE + 1]; /* Check if a pointer is in the range of the scanned_ap_list array. * This check assumes that ((uint8_t *)ap >= scanned_ap_list) is always true. */ #define is_valid_ap_ptr(ap) \ ((uint8_t *)(ap) + sizeof(struct scanned_ap) < scanned_ap_list + AP_LIST_SIZE) /* Iterate over each AccessPoint in the list using "ap" as iterator. */ #define for_each_ap(ap) \ for ((ap) = (struct scanned_ap *)scanned_ap_list; \ is_valid_ap_ptr(ap) && (ap)->size; \ (ap) = (struct scanned_ap *)((uint8_t *)(ap) + (ap)->size)) /* Get the length of the SSID */ static inline uint8_t ap_ssid_length(const struct scanned_ap *ap) { return ap->size - offsetof(struct scanned_ap, ssid); } void zd1211_init(void); /* Scan for new APs. * Returns a negative error number or the number of APs found. */ int16_t zd1211_scan(void); /* This function checks if the USB connector on the zd1211 board * is connected to a computer. It does this by looking at the * UART TXD pin. If that's pulled high, the USB is connected. * Note that this does _not_ work while scanning! */ bool zd1211_usb_is_plugged_in(void); /* Get a data structure for a scanned AP */ const struct scanned_ap * zd1211_fetch_ap(uint8_t index); /* Compare two ethernet addresses */ static inline uint8_t compare_ether_addr(const uint8_t *a, const uint8_t *b) { return memcmp(a, b, ETH_ALEN); } #endif /* WIFI_ZD1211_H_ */