mac80211.h revision c15a205070fac9fab0d9d4642b9342677b67f933
1/* 2 * mac80211 <-> driver interface 3 * 4 * Copyright 2002-2005, Devicescape Software, Inc. 5 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 6 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation. 11 */ 12 13#ifndef MAC80211_H 14#define MAC80211_H 15 16#include <linux/kernel.h> 17#include <linux/if_ether.h> 18#include <linux/skbuff.h> 19#include <linux/wireless.h> 20#include <linux/device.h> 21#include <linux/ieee80211.h> 22#include <net/wireless.h> 23#include <net/cfg80211.h> 24 25/* Note! Only ieee80211_tx_status_irqsafe() and ieee80211_rx_irqsafe() can be 26 * called in hardware interrupt context. The low-level driver must not call any 27 * other functions in hardware interrupt context. If there is a need for such 28 * call, the low-level driver should first ACK the interrupt and perform the 29 * IEEE 802.11 code call after this, e.g., from a scheduled tasklet (in 30 * software interrupt context). 31 */ 32 33/* 34 * Frame format used when passing frame between low-level hardware drivers 35 * and IEEE 802.11 driver the same as used in the wireless media, i.e., 36 * buffers start with IEEE 802.11 header and include the same octets that 37 * are sent over air. 38 * 39 * If hardware uses IEEE 802.3 headers (and perform 802.3 <-> 802.11 40 * conversion in firmware), upper layer 802.11 code needs to be changed to 41 * support this. 42 * 43 * If the receive frame format is not the same as the real frame sent 44 * on the wireless media (e.g., due to padding etc.), upper layer 802.11 code 45 * could be updated to provide support for such format assuming this would 46 * optimize the performance, e.g., by removing need to re-allocation and 47 * copying of the data. 48 */ 49 50#define IEEE80211_CHAN_W_SCAN 0x00000001 51#define IEEE80211_CHAN_W_ACTIVE_SCAN 0x00000002 52#define IEEE80211_CHAN_W_IBSS 0x00000004 53 54/* Channel information structure. Low-level driver is expected to fill in chan, 55 * freq, and val fields. Other fields will be filled in by 80211.o based on 56 * hostapd information and low-level driver does not need to use them. The 57 * limits for each channel will be provided in 'struct ieee80211_conf' when 58 * configuring the low-level driver with hw->config callback. If a device has 59 * a default regulatory domain, IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED 60 * can be set to let the driver configure all fields */ 61struct ieee80211_channel { 62 short chan; /* channel number (IEEE 802.11) */ 63 short freq; /* frequency in MHz */ 64 int val; /* hw specific value for the channel */ 65 int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */ 66 unsigned char power_level; 67 unsigned char antenna_max; 68}; 69 70#define IEEE80211_RATE_ERP 0x00000001 71#define IEEE80211_RATE_BASIC 0x00000002 72#define IEEE80211_RATE_PREAMBLE2 0x00000004 73#define IEEE80211_RATE_SUPPORTED 0x00000010 74#define IEEE80211_RATE_OFDM 0x00000020 75#define IEEE80211_RATE_CCK 0x00000040 76#define IEEE80211_RATE_MANDATORY 0x00000100 77 78#define IEEE80211_RATE_CCK_2 (IEEE80211_RATE_CCK | IEEE80211_RATE_PREAMBLE2) 79#define IEEE80211_RATE_MODULATION(f) \ 80 (f & (IEEE80211_RATE_CCK | IEEE80211_RATE_OFDM)) 81 82/* Low-level driver should set PREAMBLE2, OFDM and CCK flags. 83 * BASIC, SUPPORTED, ERP, and MANDATORY flags are set in 80211.o based on the 84 * configuration. */ 85struct ieee80211_rate { 86 int rate; /* rate in 100 kbps */ 87 int val; /* hw specific value for the rate */ 88 int flags; /* IEEE80211_RATE_ flags */ 89 int val2; /* hw specific value for the rate when using short preamble 90 * (only when IEEE80211_RATE_PREAMBLE2 flag is set, i.e., for 91 * 2, 5.5, and 11 Mbps) */ 92 signed char min_rssi_ack; 93 unsigned char min_rssi_ack_delta; 94 95 /* following fields are set by 80211.o and need not be filled by the 96 * low-level driver */ 97 int rate_inv; /* inverse of the rate (LCM(all rates) / rate) for 98 * optimizing channel utilization estimates */ 99}; 100 101/* 802.11g is backwards-compatible with 802.11b, so a wlan card can 102 * actually be both in 11b and 11g modes at the same time. */ 103enum ieee80211_phymode { 104 MODE_IEEE80211A, /* IEEE 802.11a */ 105 MODE_IEEE80211B, /* IEEE 802.11b only */ 106 MODE_IEEE80211G, /* IEEE 802.11g (and 802.11b compatibility) */ 107 108 /* keep last */ 109 NUM_IEEE80211_MODES 110}; 111 112struct ieee80211_hw_mode { 113 int mode; /* MODE_IEEE80211... */ 114 int num_channels; /* Number of channels (below) */ 115 struct ieee80211_channel *channels; /* Array of supported channels */ 116 int num_rates; /* Number of rates (below) */ 117 struct ieee80211_rate *rates; /* Array of supported rates */ 118 119 struct list_head list; /* Internal, don't touch */ 120}; 121 122struct ieee80211_tx_queue_params { 123 int aifs; /* 0 .. 255; -1 = use default */ 124 int cw_min; /* 2^n-1: 1, 3, 7, .. , 1023; 0 = use default */ 125 int cw_max; /* 2^n-1: 1, 3, 7, .. , 1023; 0 = use default */ 126 int burst_time; /* maximum burst time in 0.1 ms (i.e., 10 = 1 ms); 127 * 0 = disabled */ 128}; 129 130struct ieee80211_tx_queue_stats_data { 131 unsigned int len; /* num packets in queue */ 132 unsigned int limit; /* queue len (soft) limit */ 133 unsigned int count; /* total num frames sent */ 134}; 135 136enum { 137 IEEE80211_TX_QUEUE_DATA0, 138 IEEE80211_TX_QUEUE_DATA1, 139 IEEE80211_TX_QUEUE_DATA2, 140 IEEE80211_TX_QUEUE_DATA3, 141 IEEE80211_TX_QUEUE_DATA4, 142 IEEE80211_TX_QUEUE_SVP, 143 144 NUM_TX_DATA_QUEUES, 145 146/* due to stupidity in the sub-ioctl userspace interface, the items in 147 * this struct need to have fixed values. As soon as it is removed, we can 148 * fix these entries. */ 149 IEEE80211_TX_QUEUE_AFTER_BEACON = 6, 150 IEEE80211_TX_QUEUE_BEACON = 7 151}; 152 153struct ieee80211_tx_queue_stats { 154 struct ieee80211_tx_queue_stats_data data[NUM_TX_DATA_QUEUES]; 155}; 156 157struct ieee80211_low_level_stats { 158 unsigned int dot11ACKFailureCount; 159 unsigned int dot11RTSFailureCount; 160 unsigned int dot11FCSErrorCount; 161 unsigned int dot11RTSSuccessCount; 162}; 163 164/* Transmit control fields. This data structure is passed to low-level driver 165 * with each TX frame. The low-level driver is responsible for configuring 166 * the hardware to use given values (depending on what is supported). */ 167#define HW_KEY_IDX_INVALID -1 168 169struct ieee80211_tx_control { 170 int tx_rate; /* Transmit rate, given as the hw specific value for the 171 * rate (from struct ieee80211_rate) */ 172 int rts_cts_rate; /* Transmit rate for RTS/CTS frame, given as the hw 173 * specific value for the rate (from 174 * struct ieee80211_rate) */ 175 176#define IEEE80211_TXCTL_REQ_TX_STATUS (1<<0)/* request TX status callback for 177 * this frame */ 178#define IEEE80211_TXCTL_DO_NOT_ENCRYPT (1<<1) /* send this frame without 179 * encryption; e.g., for EAPOL 180 * frames */ 181#define IEEE80211_TXCTL_USE_RTS_CTS (1<<2) /* use RTS-CTS before sending 182 * frame */ 183#define IEEE80211_TXCTL_USE_CTS_PROTECT (1<<3) /* use CTS protection for the 184 * frame (e.g., for combined 185 * 802.11g / 802.11b networks) */ 186#define IEEE80211_TXCTL_NO_ACK (1<<4) /* tell the low level not to 187 * wait for an ack */ 188#define IEEE80211_TXCTL_RATE_CTRL_PROBE (1<<5) 189#define IEEE80211_TXCTL_CLEAR_DST_MASK (1<<6) 190#define IEEE80211_TXCTL_REQUEUE (1<<7) 191#define IEEE80211_TXCTL_FIRST_FRAGMENT (1<<8) /* this is a first fragment of 192 * the frame */ 193#define IEEE80211_TXCTL_TKIP_NEW_PHASE1_KEY (1<<9) 194#define IEEE80211_TXCTL_LONG_RETRY_LIMIT (1<<10) /* this frame should be send 195 * using the through 196 * set_retry_limit configured 197 * long retry value */ 198 u32 flags; /* tx control flags defined 199 * above */ 200 u8 retry_limit; /* 1 = only first attempt, 2 = one retry, .. 201 * This could be used when set_retry_limit 202 * is not implemented by the driver */ 203 u8 power_level; /* per-packet transmit power level, in dBm */ 204 u8 antenna_sel_tx; /* 0 = default/diversity, 1 = Ant0, 2 = Ant1 */ 205 s8 key_idx; /* HW_KEY_IDX_INVALID = do not encrypt, 206 * other values: keyidx from hw->set_key() */ 207 u8 icv_len; /* length of the ICV/MIC field in octets */ 208 u8 iv_len; /* length of the IV field in octets */ 209 u8 tkip_key[16]; /* generated phase2/phase1 key for hw TKIP */ 210 u8 queue; /* hardware queue to use for this frame; 211 * 0 = highest, hw->queues-1 = lowest */ 212 u8 sw_retry_attempt; /* number of times hw has tried to 213 * transmit frame (not incl. hw retries) */ 214 215 struct ieee80211_rate *rate; /* internal 80211.o rate */ 216 struct ieee80211_rate *rts_rate; /* internal 80211.o rate 217 * for RTS/CTS */ 218 int alt_retry_rate; /* retry rate for the last retries, given as the 219 * hw specific value for the rate (from 220 * struct ieee80211_rate). To be used to limit 221 * packet dropping when probing higher rates, if hw 222 * supports multiple retry rates. -1 = not used */ 223 int type; /* internal */ 224 int ifindex; /* internal */ 225}; 226 227/* Receive status. The low-level driver should provide this information 228 * (the subset supported by hardware) to the 802.11 code with each received 229 * frame. */ 230struct ieee80211_rx_status { 231 u64 mactime; 232 int freq; /* receive frequency in Mhz */ 233 int channel; 234 int phymode; 235 int ssi; 236 int signal; /* used as qual in statistics reporting */ 237 int noise; 238 int antenna; 239 int rate; 240#define RX_FLAG_MMIC_ERROR (1<<0) 241#define RX_FLAG_DECRYPTED (1<<1) 242#define RX_FLAG_RADIOTAP (1<<2) 243#define RX_FLAG_MMIC_STRIPPED (1<<3) 244#define RX_FLAG_IV_STRIPPED (1<<4) 245 int flag; 246}; 247 248/* Transmit status. The low-level driver should provide this information 249 * (the subset supported by hardware) to the 802.11 code for each transmit 250 * frame. */ 251struct ieee80211_tx_status { 252 /* copied ieee80211_tx_control structure */ 253 struct ieee80211_tx_control control; 254 255#define IEEE80211_TX_STATUS_TX_FILTERED (1<<0) 256#define IEEE80211_TX_STATUS_ACK (1<<1) /* whether the TX frame was ACKed */ 257 u32 flags; /* tx staus flags defined above */ 258 259 int ack_signal; /* measured signal strength of the ACK frame */ 260 int excessive_retries; 261 int retry_count; 262 263 int queue_length; /* information about TX queue */ 264 int queue_number; 265}; 266 267 268/** 269 * struct ieee80211_conf - configuration of the device 270 * 271 * This struct indicates how the driver shall configure the hardware. 272 * 273 * @radio_enabled: when zero, driver is required to switch off the radio. 274 */ 275struct ieee80211_conf { 276 int channel; /* IEEE 802.11 channel number */ 277 int freq; /* MHz */ 278 int channel_val; /* hw specific value for the channel */ 279 280 int phymode; /* MODE_IEEE80211A, .. */ 281 struct ieee80211_channel *chan; 282 struct ieee80211_hw_mode *mode; 283 unsigned int regulatory_domain; 284 int radio_enabled; 285 286 int beacon_int; 287 288#define IEEE80211_CONF_SHORT_SLOT_TIME (1<<0) /* use IEEE 802.11g Short Slot 289 * Time */ 290#define IEEE80211_CONF_SSID_HIDDEN (1<<1) /* do not broadcast the ssid */ 291#define IEEE80211_CONF_RADIOTAP (1<<2) /* use radiotap if supported 292 check this bit at RX time */ 293 u32 flags; /* configuration flags defined above */ 294 295 u8 power_level; /* transmit power limit for current 296 * regulatory domain; in dBm */ 297 u8 antenna_max; /* maximum antenna gain */ 298 299 /* 0 = default/diversity, 1 = Ant0, 2 = Ant1 */ 300 u8 antenna_sel_tx; 301 u8 antenna_sel_rx; 302}; 303 304/** 305 * enum ieee80211_if_types - types of 802.11 network interfaces 306 * 307 * @IEEE80211_IF_TYPE_AP: interface in AP mode. 308 * @IEEE80211_IF_TYPE_MGMT: special interface for communication with hostap 309 * daemon. Drivers should never see this type. 310 * @IEEE80211_IF_TYPE_STA: interface in STA (client) mode. 311 * @IEEE80211_IF_TYPE_IBSS: interface in IBSS (ad-hoc) mode. 312 * @IEEE80211_IF_TYPE_MNTR: interface in monitor (rfmon) mode. 313 * @IEEE80211_IF_TYPE_WDS: interface in WDS mode. 314 * @IEEE80211_IF_TYPE_VLAN: not used. 315 */ 316enum ieee80211_if_types { 317 IEEE80211_IF_TYPE_AP = 0x00000000, 318 IEEE80211_IF_TYPE_MGMT = 0x00000001, 319 IEEE80211_IF_TYPE_STA = 0x00000002, 320 IEEE80211_IF_TYPE_IBSS = 0x00000003, 321 IEEE80211_IF_TYPE_MNTR = 0x00000004, 322 IEEE80211_IF_TYPE_WDS = 0x5A580211, 323 IEEE80211_IF_TYPE_VLAN = 0x00080211, 324}; 325 326/** 327 * struct ieee80211_if_init_conf - initial configuration of an interface 328 * 329 * @if_id: internal interface ID. This number has no particular meaning to 330 * drivers and the only allowed usage is to pass it to 331 * ieee80211_beacon_get() and ieee80211_get_buffered_bc() functions. 332 * This field is not valid for monitor interfaces 333 * (interfaces of %IEEE80211_IF_TYPE_MNTR type). 334 * @type: one of &enum ieee80211_if_types constants. Determines the type of 335 * added/removed interface. 336 * @mac_addr: pointer to MAC address of the interface. This pointer is valid 337 * until the interface is removed (i.e. it cannot be used after 338 * remove_interface() callback was called for this interface). 339 * This pointer will be %NULL for monitor interfaces, be careful. 340 * 341 * This structure is used in add_interface() and remove_interface() 342 * callbacks of &struct ieee80211_hw. 343 * 344 * When you allow multiple interfaces to be added to your PHY, take care 345 * that the hardware can actually handle multiple MAC addresses. However, 346 * also take care that when there's no interface left with mac_addr != %NULL 347 * you remove the MAC address from the device to avoid acknowledging packets 348 * in pure monitor mode. 349 */ 350struct ieee80211_if_init_conf { 351 int if_id; 352 int type; 353 void *mac_addr; 354}; 355 356/** 357 * struct ieee80211_if_conf - configuration of an interface 358 * 359 * @type: type of the interface. This is always the same as was specified in 360 * &struct ieee80211_if_init_conf. The type of an interface never changes 361 * during the life of the interface; this field is present only for 362 * convenience. 363 * @bssid: BSSID of the network we are associated to/creating. 364 * @ssid: used (together with @ssid_len) by drivers for hardware that 365 * generate beacons independently. The pointer is valid only during the 366 * config_interface() call, so copy the value somewhere if you need 367 * it. 368 * @ssid_len: length of the @ssid field. 369 * @generic_elem: used (together with @generic_elem_len) by drivers for 370 * hardware that generate beacons independently. The pointer is valid 371 * only during the config_interface() call, so copy the value somewhere 372 * if you need it. 373 * @generic_elem_len: length of the generic element. 374 * @beacon: beacon template. Valid only if @host_gen_beacon_template in 375 * &struct ieee80211_hw is set. The driver is responsible of freeing 376 * the sk_buff. 377 * @beacon_control: tx_control for the beacon template, this field is only 378 * valid when the @beacon field was set. 379 * 380 * This structure is passed to the config_interface() callback of 381 * &struct ieee80211_hw. 382 */ 383struct ieee80211_if_conf { 384 int type; 385 u8 *bssid; 386 u8 *ssid; 387 size_t ssid_len; 388 u8 *generic_elem; 389 size_t generic_elem_len; 390 struct sk_buff *beacon; 391 struct ieee80211_tx_control *beacon_control; 392}; 393 394typedef enum { 395 ALG_NONE, 396 ALG_WEP, 397 ALG_TKIP, 398 ALG_CCMP, 399} ieee80211_key_alg; 400 401/* 402 * This flag indiciates that the station this key is being 403 * configured for may use QoS. If your hardware cannot handle 404 * that situation it should reject that key. 405 */ 406#define IEEE80211_KEY_FLAG_WMM_STA (1<<0) 407/* 408 * This flag should be set by the driver if it requires 409 * IV generation in software for this key. 410 */ 411#define IEEE80211_KEY_FLAG_GENERATE_IV (1<<1) 412/* 413 * This flag should be set by the driver if it requires 414 * MMIC generation in software for this key. 415 */ 416#define IEEE80211_KEY_FLAG_GENERATE_MMIC (1<<2) 417 418struct ieee80211_key_conf { 419 /* 420 * To be set by the driver to the key index it would like to 421 * get in the ieee80211_tx_control.key_idx which defaults 422 * to HW_KEY_IDX_INVALID so that shouldn't be used. 423 */ 424 int hw_key_idx; 425 426 /* key algorithm, ALG_NONE should never be seen by the driver */ 427 ieee80211_key_alg alg; 428 429 /* key flags, see above */ 430 u8 flags; 431 432 /* key index: 0-3 */ 433 s8 keyidx; 434 435 /* length of key material */ 436 u8 keylen; 437 438 /* the key material */ 439 u8 key[0]; 440}; 441 442#define IEEE80211_SEQ_COUNTER_RX 0 443#define IEEE80211_SEQ_COUNTER_TX 1 444 445typedef enum { 446 SET_KEY, DISABLE_KEY, 447} set_key_cmd; 448 449/* This is driver-visible part of the per-hw state the stack keeps. */ 450struct ieee80211_hw { 451 /* points to the cfg80211 wiphy for this piece. Note 452 * that you must fill in the perm_addr and dev fields 453 * of this structure, use the macros provided below. */ 454 struct wiphy *wiphy; 455 456 /* assigned by mac80211, don't write */ 457 struct ieee80211_conf conf; 458 459 /* Single thread workqueue available for driver use 460 * Allocated by mac80211 on registration */ 461 struct workqueue_struct *workqueue; 462 463 /* Pointer to the private area that was 464 * allocated with this struct for you. */ 465 void *priv; 466 467 /* The rest is information about your hardware */ 468 469 /* TODO: frame_type 802.11/802.3, sw_encryption requirements */ 470 471/* hole at 0 */ 472 473 /* 474 * The device only needs to be supplied with a beacon template. 475 * If you need the host to generate each beacon then don't use 476 * this flag and use ieee80211_beacon_get(). 477 */ 478#define IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE (1<<1) 479 480/* hole at 2 */ 481 482 /* Whether RX frames passed to ieee80211_rx() include FCS in the end */ 483#define IEEE80211_HW_RX_INCLUDES_FCS (1<<3) 484 485 /* Some wireless LAN chipsets buffer broadcast/multicast frames for 486 * power saving stations in the hardware/firmware and others rely on 487 * the host system for such buffering. This option is used to 488 * configure the IEEE 802.11 upper layer to buffer broadcast/multicast 489 * frames when there are power saving stations so that low-level driver 490 * can fetch them with ieee80211_get_buffered_bc(). */ 491#define IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING (1<<4) 492 493/* hole at 5 */ 494 495/* hole at 6 */ 496 497/* hole at 7 */ 498 499/* hole at 8 */ 500 501 /* Device is capable of performing full monitor mode even during 502 * normal operation. */ 503#define IEEE80211_HW_MONITOR_DURING_OPER (1<<9) 504 505 /* Device does not need BSSID filter set to broadcast in order to 506 * receive all probe responses while scanning */ 507#define IEEE80211_HW_NO_PROBE_FILTERING (1<<10) 508 509 /* Channels are already configured to the default regulatory domain 510 * specified in the device's EEPROM */ 511#define IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED (1<<11) 512 513 /* Do TKIP phase1 key mixing in stack to support cards only do 514 * phase2 key mixing when doing hwcrypto */ 515#define IEEE80211_HW_TKIP_REQ_PHASE1_KEY (1<<13) 516 /* Do TKIP phase1 and phase2 key mixing in stack and send the generated 517 * per-packet RC4 key with each TX frame when doing hwcrypto */ 518#define IEEE80211_HW_TKIP_REQ_PHASE2_KEY (1<<14) 519 520 u32 flags; /* hardware flags defined above */ 521 522 /* Set to the size of a needed device specific skb headroom for TX skbs. */ 523 unsigned int extra_tx_headroom; 524 525 /* This is the time in us to change channels 526 */ 527 int channel_change_time; 528 /* Maximum values for various statistics. 529 * Leave at 0 to indicate no support. Use negative numbers for dBm. */ 530 s8 max_rssi; 531 s8 max_signal; 532 s8 max_noise; 533 534 /* Number of available hardware TX queues for data packets. 535 * WMM requires at least four queues. */ 536 int queues; 537}; 538 539static inline void SET_IEEE80211_DEV(struct ieee80211_hw *hw, struct device *dev) 540{ 541 set_wiphy_dev(hw->wiphy, dev); 542} 543 544static inline void SET_IEEE80211_PERM_ADDR(struct ieee80211_hw *hw, u8 *addr) 545{ 546 memcpy(hw->wiphy->perm_addr, addr, ETH_ALEN); 547} 548 549/* Configuration block used by the low-level driver to tell the 802.11 code 550 * about supported hardware features and to pass function pointers to callback 551 * functions. */ 552struct ieee80211_ops { 553 /* Handler that 802.11 module calls for each transmitted frame. 554 * skb contains the buffer starting from the IEEE 802.11 header. 555 * The low-level driver should send the frame out based on 556 * configuration in the TX control data. 557 * Must be atomic. */ 558 int (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb, 559 struct ieee80211_tx_control *control); 560 561 /* Handler that is called when any netdevice attached to the hardware 562 * device is set UP for the first time. This can be used, e.g., to 563 * enable interrupts and beacon sending. */ 564 int (*open)(struct ieee80211_hw *hw); 565 566 /* Handler that is called when the last netdevice attached to the 567 * hardware device is set DOWN. This can be used, e.g., to disable 568 * interrupts and beacon sending. */ 569 int (*stop)(struct ieee80211_hw *hw); 570 571 /* Handler for asking a driver if a new interface can be added (or, 572 * more exactly, set UP). If the handler returns zero, the interface 573 * is added. Driver should perform any initialization it needs prior 574 * to returning zero. By returning non-zero addition of the interface 575 * is inhibited. Unless monitor_during_oper is set, it is guaranteed 576 * that monitor interfaces and normal interfaces are mutually 577 * exclusive. If assigned, the open() handler is called after 578 * add_interface() if this is the first device added. The 579 * add_interface() callback has to be assigned because it is the only 580 * way to obtain the requested MAC address for any interface. 581 */ 582 int (*add_interface)(struct ieee80211_hw *hw, 583 struct ieee80211_if_init_conf *conf); 584 585 /* Notify a driver that an interface is going down. The stop() handler 586 * is called prior to this if this is a last interface. */ 587 void (*remove_interface)(struct ieee80211_hw *hw, 588 struct ieee80211_if_init_conf *conf); 589 590 /* Handler for configuration requests. IEEE 802.11 code calls this 591 * function to change hardware configuration, e.g., channel. */ 592 int (*config)(struct ieee80211_hw *hw, struct ieee80211_conf *conf); 593 594 /* Handler for configuration requests related to interfaces (e.g. 595 * BSSID). */ 596 int (*config_interface)(struct ieee80211_hw *hw, 597 int if_id, struct ieee80211_if_conf *conf); 598 599 /* ieee80211 drivers do not have access to the &struct net_device 600 * that is (are) connected with their device. Hence (and because 601 * we need to combine the multicast lists and flags for multiple 602 * virtual interfaces), they cannot assign set_multicast_list. 603 * The parameters here replace dev->flags and dev->mc_count, 604 * dev->mc_list is replaced by calling ieee80211_get_mc_list_item. 605 * Must be atomic. */ 606 void (*set_multicast_list)(struct ieee80211_hw *hw, 607 unsigned short flags, int mc_count); 608 609 /* Set TIM bit handler. If the hardware/firmware takes care of beacon 610 * generation, IEEE 802.11 code uses this function to tell the 611 * low-level to set (or clear if set==0) TIM bit for the given aid. If 612 * host system is used to generate beacons, this handler is not used 613 * and low-level driver should set it to NULL. 614 * Must be atomic. */ 615 int (*set_tim)(struct ieee80211_hw *hw, int aid, int set); 616 617 /* 618 * Set encryption key. 619 * 620 * This is called to enable hardware acceleration of encryption and 621 * decryption. The address will be the broadcast address for default 622 * keys, the other station's hardware address for individual keys or 623 * the zero address for keys that will be used only for transmission. 624 * 625 * The local_address parameter will always be set to our own address, 626 * this is only relevant if you support multiple local addresses. 627 * 628 * When transmitting, the TX control data will use the hw_key_idx 629 * selected by the low-level driver. 630 * 631 * Return 0 if the key is now in use, -EOPNOTSUPP or -ENOSPC if it 632 * couldn't be added; if you return 0 then hw_key_idx must be 633 * assigned to something other than HW_KEY_IDX_INVALID. When the cmd 634 * is DISABLE_KEY then it must succeed. 635 * 636 * This callback can sleep, and is only called between add_interface 637 * and remove_interface calls, i.e. while the interface with the 638 * given local_address is enabled. 639 * 640 * The ieee80211_key_conf structure pointed to by the key parameter 641 * is guaranteed to be valid until another call to set_key removes 642 * it, but it can only be used as a cookie to differentiate keys. 643 */ 644 int (*set_key)(struct ieee80211_hw *hw, set_key_cmd cmd, 645 const u8 *local_address, const u8 *address, 646 struct ieee80211_key_conf *key); 647 648 /* Enable/disable IEEE 802.1X. This item requests wlan card to pass 649 * unencrypted EAPOL-Key frames even when encryption is configured. 650 * If the wlan card does not require such a configuration, this 651 * function pointer can be set to NULL. */ 652 int (*set_ieee8021x)(struct ieee80211_hw *hw, int use_ieee8021x); 653 654 /* Set port authorization state (IEEE 802.1X PAE) to be authorized 655 * (authorized=1) or unauthorized (authorized=0). This function can be 656 * used if the wlan hardware or low-level driver implements PAE. 657 * 80211.o module will anyway filter frames based on authorization 658 * state, so this function pointer can be NULL if low-level driver does 659 * not require event notification about port state changes. 660 * Currently unused. */ 661 int (*set_port_auth)(struct ieee80211_hw *hw, u8 *addr, 662 int authorized); 663 664 /* Ask the hardware to service the scan request, no need to start 665 * the scan state machine in stack. */ 666 int (*hw_scan)(struct ieee80211_hw *hw, u8 *ssid, size_t len); 667 668 /* return low-level statistics */ 669 int (*get_stats)(struct ieee80211_hw *hw, 670 struct ieee80211_low_level_stats *stats); 671 672 /* For devices that generate their own beacons and probe response 673 * or association responses this updates the state of privacy_invoked 674 * returns 0 for success or an error number */ 675 int (*set_privacy_invoked)(struct ieee80211_hw *hw, 676 int privacy_invoked); 677 678 /* For devices that have internal sequence counters, allow 802.11 679 * code to access the current value of a counter */ 680 int (*get_sequence_counter)(struct ieee80211_hw *hw, 681 u8* addr, u8 keyidx, u8 txrx, 682 u32* iv32, u16* iv16); 683 684 /* Configuration of RTS threshold (if device needs it) */ 685 int (*set_rts_threshold)(struct ieee80211_hw *hw, u32 value); 686 687 /* Configuration of fragmentation threshold. 688 * Assign this if the device does fragmentation by itself, 689 * if this method is assigned then the stack will not do 690 * fragmentation. */ 691 int (*set_frag_threshold)(struct ieee80211_hw *hw, u32 value); 692 693 /* Configuration of retry limits (if device needs it) */ 694 int (*set_retry_limit)(struct ieee80211_hw *hw, 695 u32 short_retry, u32 long_retr); 696 697 /* Number of STAs in STA table notification (NULL = disabled). 698 * Must be atomic. */ 699 void (*sta_table_notification)(struct ieee80211_hw *hw, 700 int num_sta); 701 702 /* Handle ERP IE change notifications. Must be atomic. */ 703 void (*erp_ie_changed)(struct ieee80211_hw *hw, u8 changes, 704 int cts_protection, int preamble); 705 706 /* Flags for the erp_ie_changed changes parameter */ 707#define IEEE80211_ERP_CHANGE_PROTECTION (1<<0) /* protection flag changed */ 708#define IEEE80211_ERP_CHANGE_PREAMBLE (1<<1) /* barker preamble mode changed */ 709 710 /* Configure TX queue parameters (EDCF (aifs, cw_min, cw_max), 711 * bursting) for a hardware TX queue. 712 * queue = IEEE80211_TX_QUEUE_*. 713 * Must be atomic. */ 714 int (*conf_tx)(struct ieee80211_hw *hw, int queue, 715 const struct ieee80211_tx_queue_params *params); 716 717 /* Get statistics of the current TX queue status. This is used to get 718 * number of currently queued packets (queue length), maximum queue 719 * size (limit), and total number of packets sent using each TX queue 720 * (count). 721 * Currently unused. */ 722 int (*get_tx_stats)(struct ieee80211_hw *hw, 723 struct ieee80211_tx_queue_stats *stats); 724 725 /* Get the current TSF timer value from firmware/hardware. Currently, 726 * this is only used for IBSS mode debugging and, as such, is not a 727 * required function. 728 * Must be atomic. */ 729 u64 (*get_tsf)(struct ieee80211_hw *hw); 730 731 /* Reset the TSF timer and allow firmware/hardware to synchronize with 732 * other STAs in the IBSS. This is only used in IBSS mode. This 733 * function is optional if the firmware/hardware takes full care of 734 * TSF synchronization. */ 735 void (*reset_tsf)(struct ieee80211_hw *hw); 736 737 /* Setup beacon data for IBSS beacons. Unlike access point (Master), 738 * IBSS uses a fixed beacon frame which is configured using this 739 * function. This handler is required only for IBSS mode. */ 740 int (*beacon_update)(struct ieee80211_hw *hw, 741 struct sk_buff *skb, 742 struct ieee80211_tx_control *control); 743 744 /* Determine whether the last IBSS beacon was sent by us. This is 745 * needed only for IBSS mode and the result of this function is used to 746 * determine whether to reply to Probe Requests. */ 747 int (*tx_last_beacon)(struct ieee80211_hw *hw); 748}; 749 750/* Allocate a new hardware device. This must be called once for each 751 * hardware device. The returned pointer must be used to refer to this 752 * device when calling other functions. 802.11 code allocates a private data 753 * area for the low-level driver. The size of this area is given as 754 * priv_data_len. 755 */ 756struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 757 const struct ieee80211_ops *ops); 758 759/* Register hardware device to the IEEE 802.11 code and kernel. Low-level 760 * drivers must call this function before using any other IEEE 802.11 761 * function except ieee80211_register_hwmode. */ 762int ieee80211_register_hw(struct ieee80211_hw *hw); 763 764/* driver can use this and ieee80211_get_rx_led_name to get the 765 * name of the registered LEDs after ieee80211_register_hw 766 * was called. 767 * This is useful to set the default trigger on the LED class 768 * device that your driver should export for each LED the device 769 * has, that way the default behaviour will be as expected but 770 * the user can still change it/turn off the LED etc. 771 */ 772#ifdef CONFIG_MAC80211_LEDS 773extern char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw); 774extern char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw); 775#endif 776static inline char *ieee80211_get_tx_led_name(struct ieee80211_hw *hw) 777{ 778#ifdef CONFIG_MAC80211_LEDS 779 return __ieee80211_get_tx_led_name(hw); 780#else 781 return NULL; 782#endif 783} 784 785static inline char *ieee80211_get_rx_led_name(struct ieee80211_hw *hw) 786{ 787#ifdef CONFIG_MAC80211_LEDS 788 return __ieee80211_get_rx_led_name(hw); 789#else 790 return NULL; 791#endif 792} 793 794/* Register a new hardware PHYMODE capability to the stack. */ 795int ieee80211_register_hwmode(struct ieee80211_hw *hw, 796 struct ieee80211_hw_mode *mode); 797 798/* Unregister a hardware device. This function instructs 802.11 code to free 799 * allocated resources and unregister netdevices from the kernel. */ 800void ieee80211_unregister_hw(struct ieee80211_hw *hw); 801 802/* Free everything that was allocated including private data of a driver. */ 803void ieee80211_free_hw(struct ieee80211_hw *hw); 804 805/* Receive frame callback function. The low-level driver uses this function to 806 * send received frames to the IEEE 802.11 code. Receive buffer (skb) must 807 * start with IEEE 802.11 header. */ 808void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 809 struct ieee80211_rx_status *status); 810void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, 811 struct sk_buff *skb, 812 struct ieee80211_rx_status *status); 813 814/* Transmit status callback function. The low-level driver must call this 815 * function to report transmit status for all the TX frames that had 816 * req_tx_status set in the transmit control fields. In addition, this should 817 * be called at least for all unicast frames to provide information for TX rate 818 * control algorithm. In order to maintain all statistics, this function is 819 * recommended to be called after each frame, including multicast/broadcast, is 820 * sent. */ 821void ieee80211_tx_status(struct ieee80211_hw *hw, 822 struct sk_buff *skb, 823 struct ieee80211_tx_status *status); 824void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw, 825 struct sk_buff *skb, 826 struct ieee80211_tx_status *status); 827 828/** 829 * ieee80211_beacon_get - beacon generation function 830 * @hw: pointer obtained from ieee80211_alloc_hw(). 831 * @if_id: interface ID from &struct ieee80211_if_init_conf. 832 * @control: will be filled with information needed to send this beacon. 833 * 834 * If the beacon frames are generated by the host system (i.e., not in 835 * hardware/firmware), the low-level driver uses this function to receive 836 * the next beacon frame from the 802.11 code. The low-level is responsible 837 * for calling this function before beacon data is needed (e.g., based on 838 * hardware interrupt). Returned skb is used only once and low-level driver 839 * is responsible of freeing it. 840 */ 841struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw, 842 int if_id, 843 struct ieee80211_tx_control *control); 844 845/** 846 * ieee80211_rts_get - RTS frame generation function 847 * @hw: pointer obtained from ieee80211_alloc_hw(). 848 * @if_id: interface ID from &struct ieee80211_if_init_conf. 849 * @frame: pointer to the frame that is going to be protected by the RTS. 850 * @frame_len: the frame length (in octets). 851 * @frame_txctl: &struct ieee80211_tx_control of the frame. 852 * @rts: The buffer where to store the RTS frame. 853 * 854 * If the RTS frames are generated by the host system (i.e., not in 855 * hardware/firmware), the low-level driver uses this function to receive 856 * the next RTS frame from the 802.11 code. The low-level is responsible 857 * for calling this function before and RTS frame is needed. 858 */ 859void ieee80211_rts_get(struct ieee80211_hw *hw, int if_id, 860 const void *frame, size_t frame_len, 861 const struct ieee80211_tx_control *frame_txctl, 862 struct ieee80211_rts *rts); 863 864/** 865 * ieee80211_rts_duration - Get the duration field for an RTS frame 866 * @hw: pointer obtained from ieee80211_alloc_hw(). 867 * @if_id: interface ID from &struct ieee80211_if_init_conf. 868 * @frame_len: the length of the frame that is going to be protected by the RTS. 869 * @frame_txctl: &struct ieee80211_tx_control of the frame. 870 * 871 * If the RTS is generated in firmware, but the host system must provide 872 * the duration field, the low-level driver uses this function to receive 873 * the duration field value in little-endian byteorder. 874 */ 875__le16 ieee80211_rts_duration(struct ieee80211_hw *hw, int if_id, 876 size_t frame_len, 877 const struct ieee80211_tx_control *frame_txctl); 878 879/** 880 * ieee80211_ctstoself_get - CTS-to-self frame generation function 881 * @hw: pointer obtained from ieee80211_alloc_hw(). 882 * @if_id: interface ID from &struct ieee80211_if_init_conf. 883 * @frame: pointer to the frame that is going to be protected by the CTS-to-self. 884 * @frame_len: the frame length (in octets). 885 * @frame_txctl: &struct ieee80211_tx_control of the frame. 886 * @cts: The buffer where to store the CTS-to-self frame. 887 * 888 * If the CTS-to-self frames are generated by the host system (i.e., not in 889 * hardware/firmware), the low-level driver uses this function to receive 890 * the next CTS-to-self frame from the 802.11 code. The low-level is responsible 891 * for calling this function before and CTS-to-self frame is needed. 892 */ 893void ieee80211_ctstoself_get(struct ieee80211_hw *hw, int if_id, 894 const void *frame, size_t frame_len, 895 const struct ieee80211_tx_control *frame_txctl, 896 struct ieee80211_cts *cts); 897 898/** 899 * ieee80211_ctstoself_duration - Get the duration field for a CTS-to-self frame 900 * @hw: pointer obtained from ieee80211_alloc_hw(). 901 * @if_id: interface ID from &struct ieee80211_if_init_conf. 902 * @frame_len: the length of the frame that is going to be protected by the CTS-to-self. 903 * @frame_txctl: &struct ieee80211_tx_control of the frame. 904 * 905 * If the CTS-to-self is generated in firmware, but the host system must provide 906 * the duration field, the low-level driver uses this function to receive 907 * the duration field value in little-endian byteorder. 908 */ 909__le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, int if_id, 910 size_t frame_len, 911 const struct ieee80211_tx_control *frame_txctl); 912 913/** 914 * ieee80211_generic_frame_duration - Calculate the duration field for a frame 915 * @hw: pointer obtained from ieee80211_alloc_hw(). 916 * @if_id: interface ID from &struct ieee80211_if_init_conf. 917 * @frame_len: the length of the frame. 918 * @rate: the rate (in 100kbps) at which the frame is going to be transmitted. 919 * 920 * Calculate the duration field of some generic frame, given its 921 * length and transmission rate (in 100kbps). 922 */ 923__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, int if_id, 924 size_t frame_len, 925 int rate); 926 927/** 928 * ieee80211_get_buffered_bc - accessing buffered broadcast and multicast frames 929 * @hw: pointer as obtained from ieee80211_alloc_hw(). 930 * @if_id: interface ID from &struct ieee80211_if_init_conf. 931 * @control: will be filled with information needed to send returned frame. 932 * 933 * Function for accessing buffered broadcast and multicast frames. If 934 * hardware/firmware does not implement buffering of broadcast/multicast 935 * frames when power saving is used, 802.11 code buffers them in the host 936 * memory. The low-level driver uses this function to fetch next buffered 937 * frame. In most cases, this is used when generating beacon frame. This 938 * function returns a pointer to the next buffered skb or NULL if no more 939 * buffered frames are available. 940 * 941 * Note: buffered frames are returned only after DTIM beacon frame was 942 * generated with ieee80211_beacon_get() and the low-level driver must thus 943 * call ieee80211_beacon_get() first. ieee80211_get_buffered_bc() returns 944 * NULL if the previous generated beacon was not DTIM, so the low-level driver 945 * does not need to check for DTIM beacons separately and should be able to 946 * use common code for all beacons. 947 */ 948struct sk_buff * 949ieee80211_get_buffered_bc(struct ieee80211_hw *hw, int if_id, 950 struct ieee80211_tx_control *control); 951 952/* Given an sk_buff with a raw 802.11 header at the data pointer this function 953 * returns the 802.11 header length in bytes (not including encryption 954 * headers). If the data in the sk_buff is too short to contain a valid 802.11 955 * header the function returns 0. 956 */ 957int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb); 958 959/* Like ieee80211_get_hdrlen_from_skb() but takes a FC in CPU order. */ 960int ieee80211_get_hdrlen(u16 fc); 961 962/** 963 * ieee80211_wake_queue - wake specific queue 964 * @hw: pointer as obtained from ieee80211_alloc_hw(). 965 * @queue: queue number (counted from zero). 966 * 967 * Drivers should use this function instead of netif_wake_queue. 968 */ 969void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue); 970 971/** 972 * ieee80211_stop_queue - stop specific queue 973 * @hw: pointer as obtained from ieee80211_alloc_hw(). 974 * @queue: queue number (counted from zero). 975 * 976 * Drivers should use this function instead of netif_stop_queue. 977 */ 978void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue); 979 980/** 981 * ieee80211_start_queues - start all queues 982 * @hw: pointer to as obtained from ieee80211_alloc_hw(). 983 * 984 * Drivers should use this function instead of netif_start_queue. 985 */ 986void ieee80211_start_queues(struct ieee80211_hw *hw); 987 988/** 989 * ieee80211_stop_queues - stop all queues 990 * @hw: pointer as obtained from ieee80211_alloc_hw(). 991 * 992 * Drivers should use this function instead of netif_stop_queue. 993 */ 994void ieee80211_stop_queues(struct ieee80211_hw *hw); 995 996/** 997 * ieee80211_wake_queues - wake all queues 998 * @hw: pointer as obtained from ieee80211_alloc_hw(). 999 * 1000 * Drivers should use this function instead of netif_wake_queue. 1001 */ 1002void ieee80211_wake_queues(struct ieee80211_hw *hw); 1003 1004/** 1005 * ieee80211_get_mc_list_item - iteration over items in multicast list 1006 * @hw: pointer as obtained from ieee80211_alloc_hw(). 1007 * @prev: value returned by previous call to ieee80211_get_mc_list_item() or 1008 * NULL to start a new iteration. 1009 * @ptr: pointer to buffer of void * type for internal usage of 1010 * ieee80211_get_mc_list_item(). 1011 * 1012 * Iterates over items in multicast list of given device. To get the first 1013 * item, pass NULL in @prev and in *@ptr. In subsequent calls, pass the 1014 * value returned by previous call in @prev. Don't alter *@ptr during 1015 * iteration. When there are no more items, NULL is returned. 1016 */ 1017struct dev_mc_list * 1018ieee80211_get_mc_list_item(struct ieee80211_hw *hw, 1019 struct dev_mc_list *prev, 1020 void **ptr); 1021 1022/* called by driver to notify scan status completed */ 1023void ieee80211_scan_completed(struct ieee80211_hw *hw); 1024 1025/* return a pointer to the source address (SA) */ 1026static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr) 1027{ 1028 u8 *raw = (u8 *) hdr; 1029 u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */ 1030 1031 switch (tofrom) { 1032 case 2: 1033 return hdr->addr3; 1034 case 3: 1035 return hdr->addr4; 1036 } 1037 return hdr->addr2; 1038} 1039 1040/* return a pointer to the destination address (DA) */ 1041static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr) 1042{ 1043 u8 *raw = (u8 *) hdr; 1044 u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */ 1045 1046 if (to_ds) 1047 return hdr->addr3; 1048 return hdr->addr1; 1049} 1050 1051static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr) 1052{ 1053 return (le16_to_cpu(hdr->frame_control) & 1054 IEEE80211_FCTL_MOREFRAGS) != 0; 1055} 1056 1057#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x" 1058#define MAC_ARG(x) ((u8*)(x))[0], ((u8*)(x))[1], ((u8*)(x))[2], \ 1059 ((u8*)(x))[3], ((u8*)(x))[4], ((u8*)(x))[5] 1060 1061#endif /* MAC80211_H */ 1062