summaryrefslogtreecommitdiffstats
path: root/m168_firmware/zd1211.h
blob: 94ac8e9a4bdbc76019bdb316250a99525db62e22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef WIFI_ZD1211_H_
#define WIFI_ZD1211_H_

#include "util.h"

#include <stdint.h>
#include <string.h>


/* 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_ */
bues.ch cgit interface