|
发表于 2014-6-27 01:19:09
|
显示全部楼层
无线网卡驱动代码(部分):
struct header_struct {
/* 802.3 */
u8 dest[ETH_ALEN];
u8 src[ETH_ALEN];
u16 len;
/* 802.2 */
u8 dsap;
u8 ssap;
u8 ctrl;
/* SNAP */
u8 oui[3];
u16 ethertype;
} __attribute__ ((packed));
struct ieee802_11_mgmt {
u16 frame_ctl;
u16 duration_id;
u8 addr1[ETH_ALEN]; /* destination addr */
u8 addr2[ETH_ALEN]; /* source addr */
u8 addr3[ETH_ALEN]; /* BSSID */
u16 seq_ctl;
u8 data[1508];
u32 fcs;
} __attribute__ ((packed));
struct ieee802_11_beacon_data {
u8 timestamp[8]; // TSFTIMER
u16 beacon_interval; // Kms between TBTTs (Target Beacon Transmission Times)
u16 capability_information;
u8 data[1500]; /* contains: SSID (tag,length,value),
Supported Rates (tlv), channel */
} __attribute__ ((packed));
struct ieee802_11_auth_frame {
u16 algorithm;
u16 seq_nr;
u16 status;
u8 challenge[0];
} __attribute__ ((packed));
static
int auth_req(struct at76c503 *dev, struct bss_info *bss, int seq_nr, u8 *challenge)
{
struct at76c503_tx_buffer *tx_buffer;
struct ieee802_11_mgmt *mgmt;
struct ieee802_11_auth_frame *req;
int buf_len = (seq_nr != 3 ? AUTH_FRAME_SIZE :
AUTH_FRAME_SIZE + 1 + 1 + challenge[1]);
assert(bss != NULL);
assert(seq_nr != 3 || challenge != NULL);
tx_buffer = kmalloc(buf_len + MAX_PADDING_SIZE, GFP_ATOMIC);
if (!tx_buffer)
return -ENOMEM;
mgmt = (struct ieee802_11_mgmt *)&(tx_buffer->packet);
req = (struct ieee802_11_auth_frame *)&(mgmt->data);
/* make wireless header */
/* no need to care about endianness of constants - is taken care
of in ieee802_11.h */
/* first auth msg is not encrypted */
mgmt->frame_ctl = IEEE802_11_FTYPE_MGMT | IEEE802_11_STYPE_AUTH;
if (seq_nr == 3)
mgmt->frame_ctl |= IEEE802_11_FCTL_WEP;
mgmt->duration_id = cpu_to_le16(0x8000);
memcpy(mgmt->addr1, bss->bssid, ETH_ALEN);
memcpy(mgmt->addr2, dev->netdev->dev_addr, ETH_ALEN);
memcpy(mgmt->addr3, bss->bssid, ETH_ALEN);
mgmt->seq_ctl = 0;
req->algorithm = dev->auth_mode;
req->seq_nr = cpu_to_le16(seq_nr);
req->status = 0;
if (seq_nr == 3)
memcpy(req->challenge, challenge, 1+1+challenge[1]);
/* init. at76c503 tx header */
tx_buffer->wlength = cpu_to_le16(buf_len - AT76C503_TX_HDRLEN);
dbg(DBG_TX_MGMT, "%s: AuthReq bssid %s alg %d seq_nr %d",
dev->netdev->name, mac2str(mgmt->addr3),
req->algorithm, req->seq_nr);
if (seq_nr == 3) {
char obuf[18*3] __attribute__ ((unused));
dbg(DBG_TX_MGMT, "%s: AuthReq challenge: %s ...",
dev->netdev->name,
hex2str(obuf, req->challenge, sizeof(obuf)/3,' '));
}
/* either send immediately (if no data tx is pending
or put it in pending list */
return send_mgmt_bulk(dev, tx_buffer);
} /* auth_req */
数据结构在通信行业不是应用,那是相当广的应用。 |
|