iwl_mvm.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. /* Intel 7265D/3165 firmware command layer: see iwl_mvm.h.
  2. *
  3. * Follows Linux iwlmvm for the 7265D-29 API (no unified image, LMAC scan,
  4. * DQA queues, old station API, ADD_STA v7, ADD_STA_KEY v1, PHY context v1,
  5. * MAC context v1, TX_CMD v6, legacy RX_PHY + RX_MPDU):
  6. *
  7. * INIT image: ALIVE -> BT config -> NVM (HW + SW sections) -> TX antennas
  8. * -> PHY_CONFIGURATION -> CALIB_RES_NOTIF_PHY_DB ... INIT_COMPLETE
  9. * runtime image: ALIVE -> TX antennas -> PHY DB replay -> PHY config ->
  10. * BT config -> DQA enable -> aux station -> PHY context -> device power
  11. * (CAM) -> MCC "ZZ" -> MAC context (station)
  12. *
  13. * Legacy rates only (no LQ table, no aggregation): management frames at
  14. * 1 Mb/s CCK (2.4 GHz) or 6 Mb/s OFDM, data at 12 Mb/s OFDM. */
  15. #include "iwl_mvm.h"
  16. #include "iwl_trans.h"
  17. #include "mm.h"
  18. #include "serial.h"
  19. /* ---- command ids (fw/api/commands.h) ------------------------------------ */
  20. #define UCODE_ALIVE_NTFY 0x01
  21. #define REPLY_ERROR 0x02
  22. #define INIT_COMPLETE_NOTIF 0x04
  23. #define PHY_CONTEXT_CMD 0x08
  24. #define ADD_STA_KEY 0x17
  25. #define ADD_STA 0x18
  26. #define REMOVE_STA 0x19
  27. #define TX_CMD 0x1c
  28. #define SCD_QUEUE_CFG 0x1d
  29. #define MAC_CONTEXT_CMD 0x28
  30. #define TIME_EVENT_CMD 0x29
  31. #define TIME_EVENT_NOTIFICATION 0x2a
  32. #define BINDING_CONTEXT_CMD 0x2b
  33. #define TIME_QUOTA_CMD 0x2c
  34. #define SCAN_OFFLOAD_REQUEST_CMD 0x51
  35. #define SCAN_OFFLOAD_ABORT_CMD 0x52
  36. #define PHY_CONFIGURATION_CMD 0x6a
  37. #define CALIB_RES_NOTIF_PHY_DB 0x6b
  38. #define PHY_DB_CMD 0x6c
  39. #define SCAN_OFFLOAD_COMPLETE 0x6d
  40. #define POWER_TABLE_CMD 0x77
  41. #define NVM_ACCESS_CMD 0x88
  42. #define TX_ANT_CONFIGURATION_CMD 0x98
  43. #define BT_CONFIG 0x9b
  44. #define REPLY_RX_PHY_CMD 0xc0
  45. #define REPLY_RX_MPDU_CMD 0xc1
  46. #define MCC_UPDATE_CMD 0xc8
  47. #define DQA_ENABLE_CMD ((5u << 8) | 0x00) /* DATA_PATH_GROUP */
  48. #define ACTION_ADD 1
  49. #define ACTION_MODIFY 2
  50. #define ACTION_REMOVE 3
  51. #define CTXT_INVALID 0xffffffffu
  52. #define MAC_INDEX_AUX 4
  53. #define RATE_CCK (1u << 9)
  54. #define RATE_ANT_A (1u << 14)
  55. #define PLCP_1M 10
  56. #define PLCP_6M 13
  57. #define PLCP_12M 5
  58. #define TX_FLG_ACK (1u << 3)
  59. #define TX_FLG_SEQ_CTL (1u << 13)
  60. #define TX_FLG_BT_DIS (1u << 12)
  61. /* ---- wire structures (packed, little endian) --------------------------- */
  62. #define PACKED __attribute__((packed))
  63. struct phy_ctx_cmd { /* PHY_CONTEXT_CMD_API_VER_1 */
  64. unsigned int id_and_color, action, apply_time, tx_param_color;
  65. unsigned char band, channel, width, ctrl_pos;
  66. unsigned int txchain_info, rxchain_info, acquisition_data, dsp_cfg_flags;
  67. } PACKED;
  68. struct ac_qos {
  69. unsigned short cw_min, cw_max;
  70. unsigned char aifsn, fifos_mask;
  71. unsigned short edca_txop;
  72. } PACKED;
  73. struct mac_ctx_cmd { /* MAC_CONTEXT_CMD_API_S_VER_1 */
  74. unsigned int id_and_color, action, mac_type, tsf_id;
  75. unsigned char node_addr[6];
  76. unsigned short res0;
  77. unsigned char bssid_addr[6];
  78. unsigned short res1;
  79. unsigned int cck_rates, ofdm_rates, protection_flags;
  80. unsigned int cck_short_preamble, short_slot, filter_flags, qos_flags;
  81. struct ac_qos ac[5];
  82. /* struct iwl_mac_data_sta (+ p2p ctwin padding of the union) */
  83. unsigned int is_assoc, dtim_time;
  84. unsigned int dtim_tsf_lo, dtim_tsf_hi;
  85. unsigned int bi, res2, dtim_interval, data_policy, listen_interval;
  86. unsigned int assoc_id, assoc_beacon_arrive_time;
  87. unsigned int union_pad;
  88. } PACKED;
  89. struct binding_cmd { /* BINDING_CMD_API_S_VER_1 */
  90. unsigned int id_and_color, action, macs[3], phy;
  91. } PACKED;
  92. struct quota_cmd { /* TIME_QUOTA_ALLOCATION_CMD v1 */
  93. struct { unsigned int id_and_color, quota, max_duration; } q[4];
  94. } PACKED;
  95. struct add_sta_cmd { /* ADD_STA_CMD_API_S_VER_7 */
  96. unsigned char add_modify, awake_acs;
  97. unsigned short tid_disable_tx;
  98. unsigned int mac_id_n_color;
  99. unsigned char addr[6];
  100. unsigned short res2;
  101. unsigned char sta_id, modify_mask;
  102. unsigned short res3;
  103. unsigned int station_flags, station_flags_msk;
  104. unsigned char add_ba_tid, remove_ba_tid;
  105. unsigned short add_ba_ssn, sleep_tx_count, sleep_state_flags;
  106. unsigned short assoc_id, beamform_flags;
  107. unsigned int tfd_queue_msk;
  108. } PACKED;
  109. struct sta_key_cmd { /* ADD_MODIFY_STA_KEY_API_S_VER_1 */
  110. unsigned char sta_id, key_offset;
  111. unsigned short key_flags;
  112. unsigned char key[32];
  113. unsigned char rx_secur_seq_cnt[16];
  114. unsigned char tkip_rx_tsc_byte2, res;
  115. unsigned short tkip_rx_ttak[5];
  116. } PACKED;
  117. struct scd_cfg_cmd { /* SCD_QUEUE_CFG_CMD_API_S_VER_1 */
  118. unsigned char token, sta_id, tid, scd_queue, action, aggregate;
  119. unsigned char tx_fifo, window;
  120. unsigned short ssn, res;
  121. } PACKED;
  122. struct time_event_cmd { /* MAC_TIME_EVENT_CMD_API_S_VER_2 */
  123. unsigned int id_and_color, action, id, apply_time, max_delay;
  124. unsigned int depends_on, interval, duration;
  125. unsigned char repeat, max_frags;
  126. unsigned short policy;
  127. } PACKED;
  128. struct tx_cmd { /* TX_CMD_API_S_VER_6 */
  129. unsigned short len, offload_assist;
  130. unsigned int tx_flags;
  131. unsigned char try_cnt, btkill_cnt;
  132. unsigned short scratch_res;
  133. unsigned int rate_n_flags;
  134. unsigned char sta_id, sec_ctl, initial_rate_index, res2;
  135. unsigned char key[16];
  136. unsigned int res3, life_time, dram_lsb_ptr;
  137. unsigned char dram_msb_ptr, rts_retry_limit, data_retry_limit, tid_tspec;
  138. unsigned short pm_frame_timeout, res4;
  139. } PACKED;
  140. struct scan_req_lmac { /* SCAN_REQUEST_FIXED_PART_API_S_VER_7 */
  141. unsigned int res1;
  142. unsigned char n_channels, active_dwell, passive_dwell, fragmented_dwell;
  143. unsigned char extended_dwell, res2;
  144. unsigned short rx_chain_select;
  145. unsigned int scan_flags, max_out_time, suspend_time;
  146. unsigned int flags, filter_flags;
  147. struct { unsigned int tx_flags, rate_n_flags;
  148. unsigned char sta_id, res[3]; } tx_cmd[2];
  149. struct { unsigned char id, len, ssid[32]; } direct_scan[20];
  150. unsigned int scan_prio, iter_num, delay;
  151. struct { unsigned short delay; unsigned char iterations, full_scan_mul; }
  152. schedule[2];
  153. struct { unsigned short flags, non_ebs_ratio; } channel_opt[2];
  154. } PACKED;
  155. struct scan_chan_lmac {
  156. unsigned int flags;
  157. unsigned short channel_num, iter_count;
  158. unsigned int iter_interval;
  159. } PACKED;
  160. typedef char chk1[sizeof(struct mac_ctx_cmd) == 148 ? 1 : -1];
  161. typedef char chk2[sizeof(struct add_sta_cmd) == 44 ? 1 : -1];
  162. typedef char chk3[sizeof(struct sta_key_cmd) == 64 ? 1 : -1];
  163. typedef char chk4[sizeof(struct tx_cmd) == 56 ? 1 : -1];
  164. typedef char chk5[sizeof(struct scan_req_lmac) == 764 ? 1 : -1];
  165. typedef char chk6[sizeof(struct phy_ctx_cmd) == 36 ? 1 : -1];
  166. /* ---- state ------------------------------------------------------------- */
  167. #define PHYDB_PAGES 8
  168. #define NVM_CHUNK 2048
  169. static struct {
  170. int up;
  171. const char *state;
  172. unsigned char mac[6];
  173. unsigned char bssid[6];
  174. unsigned int chan; /* current PHY context channel */
  175. int bound; /* binding + quota active */
  176. int ap_sta; /* AP station added */
  177. unsigned int alive_status, scd_base, err_table;
  178. int alive;
  179. int init_complete;
  180. unsigned char *phydb; /* [type u16][chg u16][len u16][pad][data] */
  181. unsigned int phydb_len;
  182. unsigned char *scratch; /* 8 KB command scratch */
  183. int scanning, scan_ok;
  184. int last_rssi, last_chan;
  185. int te_started;
  186. unsigned char tk[16];
  187. int have_tk;
  188. unsigned int valid_tx_ant, valid_rx_ant;
  189. } M;
  190. static void logs(const char *s)
  191. {
  192. iwl_log(s);
  193. }
  194. static void put16(unsigned char *p, unsigned int v)
  195. {
  196. p[0] = v; p[1] = v >> 8;
  197. }
  198. static unsigned int get16(const unsigned char *p)
  199. {
  200. return p[0] | (p[1] << 8);
  201. }
  202. static unsigned int get32(const unsigned char *p)
  203. {
  204. return p[0] | (p[1] << 8) | (p[2] << 16) | ((unsigned int)p[3] << 24);
  205. }
  206. static int cmd(unsigned int id, const void *data, unsigned int len)
  207. {
  208. return iwl_send_cmd(id, data, len, 0, 0) < 0 ? -1 : 0;
  209. }
  210. /* Command with a 32-bit status response (iwl_mvm_send_cmd_pdu_status). */
  211. static int cmd_status(unsigned int id, const void *data, unsigned int len,
  212. unsigned int *status)
  213. {
  214. unsigned char r[4] = { 0, 0, 0, 0 };
  215. int n = iwl_send_cmd(id, data, len, r, 4);
  216. if (n < 0)
  217. return -1;
  218. *status = get32(r);
  219. return 0;
  220. }
  221. /* ---- PHY DB ------------------------------------------------------------ */
  222. static void phydb_store(const unsigned char *d, unsigned int n)
  223. {
  224. unsigned int type, len, chg = 0, rec;
  225. if (n < 4 || !M.phydb)
  226. return;
  227. type = get16(d);
  228. len = get16(d + 2);
  229. if (len + 4 > n)
  230. return;
  231. if ((type == 4 || type == 5) && len >= 2)
  232. chg = get16(d + 4);
  233. rec = (8 + len + 3) & ~3u;
  234. if (M.phydb_len + rec > PHYDB_PAGES * 4096) {
  235. logs("phy db full");
  236. return;
  237. }
  238. put16(M.phydb + M.phydb_len, type);
  239. put16(M.phydb + M.phydb_len + 2, chg);
  240. put16(M.phydb + M.phydb_len + 4, len);
  241. iwl_memcpy(M.phydb + M.phydb_len + 8, d + 4, len);
  242. M.phydb_len += rec;
  243. }
  244. static int phydb_send_type(unsigned int type)
  245. {
  246. unsigned int chg, off, sent = 0, maxchg = 0;
  247. for (off = 0; off < M.phydb_len;) {
  248. unsigned int len = get16(M.phydb + off + 4);
  249. if (get16(M.phydb + off) == type && get16(M.phydb + off + 2) > maxchg)
  250. maxchg = get16(M.phydb + off + 2);
  251. off += (8 + len + 3) & ~3u;
  252. }
  253. for (chg = 0; chg <= maxchg; chg++) {
  254. for (off = 0; off < M.phydb_len;) {
  255. unsigned int len = get16(M.phydb + off + 4);
  256. if (get16(M.phydb + off) == type &&
  257. get16(M.phydb + off + 2) == chg) {
  258. /* struct iwl_phy_db_cmd: type, length, data */
  259. put16(M.scratch, type);
  260. put16(M.scratch + 2, len);
  261. iwl_memcpy(M.scratch + 4, M.phydb + off + 8, len);
  262. if (cmd(PHY_DB_CMD, M.scratch, 4 + len) < 0)
  263. return -1;
  264. sent++;
  265. }
  266. off += (8 + len + 3) & ~3u;
  267. }
  268. if (type < 4)
  269. break;
  270. }
  271. if (!sent && type < 4) {
  272. logs("phy db section missing");
  273. return -1;
  274. }
  275. return 0;
  276. }
  277. /* ---- RX dispatch -------------------------------------------------------- */
  278. static void rx_mpdu(const struct iwl_pkt *pkt)
  279. {
  280. unsigned int plen = iwl_pkt_payload_len(pkt), len, status;
  281. const unsigned char *d = pkt->data;
  282. if (plen < 8)
  283. return;
  284. len = get16(d);
  285. if (4 + len + 4 > plen)
  286. return;
  287. status = get32(d + 4 + len);
  288. if (!(status & IWL_RX_CRC_OK) || !(status & IWL_RX_OVERRUN_OK))
  289. return;
  290. wifi_rx_frame(d + 4, len, M.last_rssi, status, (unsigned int)M.last_chan);
  291. }
  292. static void rx_phy(const struct iwl_pkt *pkt)
  293. {
  294. const unsigned char *d = pkt->data;
  295. int ea, eb, best;
  296. unsigned int energy;
  297. if (iwl_pkt_payload_len(pkt) < 68)
  298. return;
  299. M.last_chan = get16(d + 22);
  300. /* non_cfg_phy[IWL_RX_INFO_ENERGY_ANT_ABC_IDX = 1]: energy per chain,
  301. * in -dBm (0 = no measurement). */
  302. energy = get32(d + 24 + 4);
  303. ea = energy & 0xff;
  304. eb = (energy >> 8) & 0xff;
  305. ea = ea ? -ea : -128;
  306. eb = eb ? -eb : -128;
  307. best = ea > eb ? ea : eb;
  308. M.last_rssi = best;
  309. }
  310. static void rx_handler(const struct iwl_pkt *pkt)
  311. {
  312. const unsigned char *d = pkt->data;
  313. unsigned int n = iwl_pkt_payload_len(pkt);
  314. if (pkt->group > 1)
  315. return;
  316. switch (pkt->cmd) {
  317. case UCODE_ALIVE_NTFY:
  318. if (n >= 44) {
  319. M.alive_status = get16(d);
  320. M.err_table = get32(d + 20);
  321. M.scd_base = get32(d + 40);
  322. M.alive = 1;
  323. }
  324. break;
  325. case INIT_COMPLETE_NOTIF:
  326. M.init_complete = 1;
  327. break;
  328. case CALIB_RES_NOTIF_PHY_DB:
  329. phydb_store(d, n);
  330. break;
  331. case REPLY_RX_PHY_CMD:
  332. rx_phy(pkt);
  333. break;
  334. case REPLY_RX_MPDU_CMD:
  335. rx_mpdu(pkt);
  336. break;
  337. case TX_CMD:
  338. /* struct iwl_mvm_tx_resp_v3: status at byte 32. */
  339. iwl_tx_reclaim((pkt->seq >> 8) & 0x1f, pkt->seq & 0xff);
  340. if (n > 33 && (d[32] & 0xff) != 1 && (d[32] & 0xff) != 2) {
  341. serial_puts(SERIAL_COM1, "iwl: tx status ");
  342. serial_puthex(SERIAL_COM1, get16(d + 32));
  343. serial_puts(SERIAL_COM1, "\n");
  344. }
  345. break;
  346. case SCAN_OFFLOAD_COMPLETE:
  347. M.scanning = 0;
  348. M.scan_ok = n >= 3 && d[2] == 1;
  349. wifi_scan_done(M.scan_ok);
  350. break;
  351. case TIME_EVENT_NOTIFICATION:
  352. /* struct iwl_time_event_notif: action at 16 (1 = start). */
  353. if (n >= 24 && (get32(d + 16) & 1))
  354. M.te_started = 1;
  355. break;
  356. case REPLY_ERROR:
  357. if (n >= 8) {
  358. serial_puts(SERIAL_COM1, "iwl: REPLY_ERROR type ");
  359. serial_puthex(SERIAL_COM1, get32(d));
  360. serial_puts(SERIAL_COM1, " cmd ");
  361. serial_puthex(SERIAL_COM1, d[4]);
  362. serial_puts(SERIAL_COM1, "\n");
  363. }
  364. break;
  365. default:
  366. break;
  367. }
  368. }
  369. int iwl_mvm_poll(void)
  370. {
  371. return iwl_rx_poll();
  372. }
  373. /* ---- bring-up ---------------------------------------------------------- */
  374. static void dump_error_log(void)
  375. {
  376. unsigned int i;
  377. if (!M.err_table || M.err_table >= 0x01000000u)
  378. return;
  379. serial_puts(SERIAL_COM1, "iwl: error log:");
  380. for (i = 0; i < 16; i++) {
  381. serial_puts(SERIAL_COM1, " ");
  382. serial_puthex(SERIAL_COM1, iwl_mem_rd32(M.err_table + i * 4));
  383. }
  384. serial_puts(SERIAL_COM1, "\n");
  385. }
  386. static int load_and_wait_alive(int img)
  387. {
  388. unsigned int t;
  389. M.alive = 0;
  390. if (iwl_load_fw(img) < 0)
  391. return -1;
  392. for (t = 0; t < 2000 && !M.alive; t++) {
  393. if (iwl_rx_poll() < 0)
  394. break;
  395. if (!M.alive)
  396. iwl_udelay(1000);
  397. }
  398. if (!M.alive) {
  399. logs("no ALIVE from firmware");
  400. return -1;
  401. }
  402. if (M.alive_status != 0xcafe) {
  403. iwl_loghex("ALIVE status", M.alive_status);
  404. return -1;
  405. }
  406. iwl_fw_alive(M.scd_base);
  407. return 0;
  408. }
  409. static int send_tx_ant(void)
  410. {
  411. unsigned int v = M.valid_tx_ant;
  412. return cmd(TX_ANT_CONFIGURATION_CMD, &v, 4);
  413. }
  414. static int send_phy_cfg(int img)
  415. {
  416. const struct iwl_fw_info *fw = iwl_fw();
  417. unsigned int c[3];
  418. c[0] = (fw->phy_sku & ~0x00ff0000u) | (M.valid_tx_ant << 16) |
  419. (M.valid_rx_ant << 20);
  420. c[1] = fw->flow_trigger[img == IWL_IMG_INIT ? 1 : 0];
  421. c[2] = fw->event_trigger[img == IWL_IMG_INIT ? 1 : 0];
  422. return cmd(PHY_CONFIGURATION_CMD, c, sizeof(c));
  423. }
  424. static int send_bt_config(void)
  425. {
  426. unsigned int c[2] = { 3 /* BT_COEX_WIFI */, 0 };
  427. return cmd(BT_CONFIG, c, sizeof(c));
  428. }
  429. static int nvm_read(unsigned int section, unsigned char *out,
  430. unsigned int max)
  431. {
  432. unsigned int off = 0;
  433. unsigned char req[8];
  434. while (off < max) {
  435. int n;
  436. unsigned int got, status;
  437. req[0] = 0; /* NVM_READ_OPCODE */
  438. req[1] = 0; /* target: cached */
  439. put16(req + 2, section);
  440. put16(req + 4, off);
  441. put16(req + 6, NVM_CHUNK);
  442. n = iwl_send_cmd(NVM_ACCESS_CMD, req, 8, M.scratch, 8 + NVM_CHUNK);
  443. if (n < 8)
  444. return -1;
  445. status = get16(M.scratch + 6);
  446. got = get16(M.scratch + 2);
  447. if (status) {
  448. if (off)
  449. break; /* section size is a multiple of 2 KB */
  450. return -1;
  451. }
  452. if (got > NVM_CHUNK || off + got > max)
  453. got = off + got > max ? max - off : got;
  454. iwl_memcpy(out + off, M.scratch + 8, got);
  455. off += got;
  456. if (got < NVM_CHUNK)
  457. break;
  458. }
  459. return (int)off;
  460. }
  461. static int read_nvm(void)
  462. {
  463. unsigned char *buf = M.scratch + 4096; /* 4 KB is plenty for HW */
  464. const unsigned char *a;
  465. int n;
  466. /* NVM HW section (nvm_hw_section_num = 0 on the 7000 family): the MAC
  467. * address is at word 0x15, stored as little-endian 16-bit words. */
  468. n = nvm_read(0, buf, 4096 - 2048);
  469. if (n < (0x15 + 3) * 2) {
  470. logs("NVM HW section read failed");
  471. return -1;
  472. }
  473. a = buf + 0x15 * 2;
  474. M.mac[0] = a[1]; M.mac[1] = a[0];
  475. M.mac[2] = a[3]; M.mac[3] = a[2];
  476. M.mac[4] = a[5]; M.mac[5] = a[4];
  477. if ((M.mac[0] & 1) || !(M.mac[0] | M.mac[1] | M.mac[2] | M.mac[3] |
  478. M.mac[4] | M.mac[5])) {
  479. logs("NVM MAC address invalid");
  480. return -1;
  481. }
  482. return 0;
  483. }
  484. static int run_init_image(void)
  485. {
  486. unsigned int t;
  487. M.state = "init image";
  488. if (iwl_start_hw() < 0)
  489. return -1;
  490. M.phydb_len = 0;
  491. M.init_complete = 0;
  492. if (load_and_wait_alive(IWL_IMG_INIT) < 0)
  493. return -1;
  494. if (send_bt_config() < 0 || read_nvm() < 0)
  495. return -1;
  496. if (iwl_rfkill()) {
  497. logs("radio is off (hardware RF-kill)");
  498. return -1;
  499. }
  500. if (send_tx_ant() < 0 || send_phy_cfg(IWL_IMG_INIT) < 0)
  501. return -1;
  502. for (t = 0; t < 2000 && !M.init_complete; t++) {
  503. if (iwl_rx_poll() < 0)
  504. break;
  505. if (!M.init_complete)
  506. iwl_udelay(1000);
  507. }
  508. if (!M.init_complete) {
  509. logs("INIT calibration did not complete");
  510. dump_error_log();
  511. return -1;
  512. }
  513. return 0;
  514. }
  515. static int enable_queue(int q, unsigned int sta, unsigned int tid,
  516. unsigned int fifo)
  517. {
  518. struct scd_cfg_cmd c;
  519. iwl_memzero(&c, sizeof(c));
  520. iwl_txq_enable(q, 0);
  521. c.sta_id = sta;
  522. c.tid = tid;
  523. c.scd_queue = q;
  524. c.action = 1; /* SCD_CFG_ENABLE_QUEUE */
  525. c.tx_fifo = fifo;
  526. c.window = 64;
  527. c.ssn = iwl_txq_wptr(q);
  528. return cmd(SCD_QUEUE_CFG, &c, sizeof(c));
  529. }
  530. static int add_sta(struct add_sta_cmd *c)
  531. {
  532. unsigned int status = 0;
  533. if (cmd_status(ADD_STA, c, sizeof(*c), &status) < 0)
  534. return -1;
  535. if ((status & 0xff) != 1) {
  536. iwl_loghex("ADD_STA failed, status", status);
  537. return -1;
  538. }
  539. return 0;
  540. }
  541. static int add_aux_sta(void)
  542. {
  543. struct add_sta_cmd c;
  544. if (enable_queue(IWL_Q_AUX, IWL_STA_AUX, 8, 5 /* MCAST FIFO */) < 0)
  545. return -1;
  546. iwl_memzero(&c, sizeof(c));
  547. c.sta_id = IWL_STA_AUX;
  548. c.mac_id_n_color = MAC_INDEX_AUX;
  549. c.tfd_queue_msk = 1u << IWL_Q_AUX;
  550. c.tid_disable_tx = 0xffff;
  551. return add_sta(&c);
  552. }
  553. static int phy_ctx(unsigned int action, unsigned int chan)
  554. {
  555. struct phy_ctx_cmd c;
  556. unsigned int rx = M.valid_rx_ant;
  557. iwl_memzero(&c, sizeof(c));
  558. c.id_and_color = 0;
  559. c.action = action;
  560. c.band = chan <= 14 ? 1 : 0; /* PHY_BAND_24 / PHY_BAND_5 */
  561. c.channel = chan;
  562. c.width = 0; /* 20 MHz */
  563. c.ctrl_pos = 0;
  564. c.txchain_info = M.valid_tx_ant;
  565. /* valid chains, idle/active count 1 (no MIMO) */
  566. c.rxchain_info = (rx << 1) | (1u << 10) | (1u << 12);
  567. if (cmd(PHY_CONTEXT_CMD, &c, sizeof(c)) < 0)
  568. return -1;
  569. M.chan = chan;
  570. return 0;
  571. }
  572. static void fill_mac(struct mac_ctx_cmd *c, unsigned int action, int assoc,
  573. unsigned short aid, unsigned int bi, unsigned int dtim)
  574. {
  575. unsigned int i;
  576. iwl_memzero(c, sizeof(*c));
  577. c->id_and_color = 0;
  578. c->action = action;
  579. c->mac_type = 5; /* FW_MAC_TYPE_BSS_STA */
  580. c->tsf_id = 0;
  581. iwl_memcpy(c->node_addr, M.mac, 6);
  582. if (M.ap_sta || assoc)
  583. iwl_memcpy(c->bssid_addr, M.bssid, 6);
  584. else
  585. for (i = 0; i < 6; i++)
  586. c->bssid_addr[i] = 0xff;
  587. /* ACK rates: 1/2/5.5/11 CCK, 6/12/24 OFDM (iwl_mvm_ack_rates). */
  588. c->cck_rates = M.chan && M.chan > 14 ? 0 : 0x0f;
  589. c->ofdm_rates = 0x15;
  590. c->short_slot = (1u << 4);
  591. /* Non-QoS EDCA (mac80211 defaults): CW 15/1023, AIFS 2, per-AC FIFO. */
  592. for (i = 0; i < 4; i++) {
  593. c->ac[i].cw_min = 15;
  594. c->ac[i].cw_max = 1023;
  595. c->ac[i].aifsn = 2;
  596. c->ac[i].fifos_mask = 1u << i;
  597. }
  598. c->filter_flags = (1u << 2); /* ACCEPT_GRP */
  599. if (assoc) {
  600. c->is_assoc = 1;
  601. c->assoc_id = aid;
  602. } else {
  603. c->filter_flags |= (1u << 6); /* IN_BEACON */
  604. }
  605. c->bi = bi;
  606. c->dtim_interval = bi * (dtim ? dtim : 1);
  607. c->listen_interval = 10;
  608. }
  609. static int mac_ctx(unsigned int action, int assoc, unsigned short aid,
  610. unsigned int bi, unsigned int dtim)
  611. {
  612. struct mac_ctx_cmd c;
  613. fill_mac(&c, action, assoc, aid, bi, dtim);
  614. return cmd(MAC_CONTEXT_CMD, &c, sizeof(c));
  615. }
  616. static int run_rt_image(void)
  617. {
  618. unsigned int one = 0;
  619. unsigned char mcc[28]; /* LAR_UPDATE_MCC_CMD_API_S_VER_2 */
  620. M.state = "runtime image";
  621. iwl_stop_device();
  622. if (iwl_start_hw() < 0)
  623. return -1;
  624. if (load_and_wait_alive(IWL_IMG_RT) < 0)
  625. return -1;
  626. if (send_tx_ant() < 0)
  627. return -1;
  628. if (phydb_send_type(1) < 0 || phydb_send_type(2) < 0 ||
  629. phydb_send_type(4) < 0 || phydb_send_type(5) < 0)
  630. return -1;
  631. if (send_phy_cfg(IWL_IMG_RT) < 0 || send_bt_config() < 0)
  632. return -1;
  633. if (cmd(DQA_ENABLE_CMD, &one, 4) < 0) /* cmd_queue = 0 */
  634. return -1;
  635. if (add_aux_sta() < 0)
  636. return -1;
  637. if (phy_ctx(ACTION_ADD, 1) < 0)
  638. return -1;
  639. one = 0; /* device power: CAM */
  640. if (cmd(POWER_TABLE_CMD, &one, 4) < 0)
  641. return -1;
  642. /* LAR: ask for the current (NVM default) regulatory domain. */
  643. iwl_memzero(mcc, sizeof(mcc));
  644. mcc[0] = 'Z'; mcc[1] = 'Z'; /* le16: 'Z' << 8 | 'Z' */
  645. mcc[2] = 0x10; /* MCC_SOURCE_GET_CURRENT */
  646. if (iwl_send_cmd(MCC_UPDATE_CMD, mcc, sizeof(mcc), 0, 0) < 0)
  647. logs("MCC update failed (continuing)");
  648. if (mac_ctx(ACTION_ADD, 0, 0, 100, 1) < 0)
  649. return -1;
  650. return 0;
  651. }
  652. int iwl_mvm_up(unsigned char mac[6])
  653. {
  654. const struct iwl_fw_info *fw;
  655. if (M.up) {
  656. iwl_memcpy(mac, M.mac, 6);
  657. return 0;
  658. }
  659. if (iwl_probe() < 0) {
  660. M.state = "no card";
  661. return -1;
  662. }
  663. if (iwl_fw_parse() < 0) {
  664. M.state = "firmware missing";
  665. return -1;
  666. }
  667. fw = iwl_fw();
  668. if (!M.phydb) {
  669. M.phydb = (unsigned char *)mm_alloc_pages(PHYDB_PAGES);
  670. M.scratch = (unsigned char *)mm_alloc_pages(2);
  671. if (!M.phydb || !M.scratch) {
  672. M.state = "out of memory";
  673. return -1;
  674. }
  675. }
  676. M.valid_tx_ant = (fw->phy_sku >> 16) & 0xf;
  677. M.valid_rx_ant = (fw->phy_sku >> 20) & 0xf;
  678. if (!M.valid_tx_ant)
  679. M.valid_tx_ant = 1;
  680. if (!M.valid_rx_ant)
  681. M.valid_rx_ant = 1;
  682. iwl_set_rx_handler(rx_handler);
  683. if (run_init_image() < 0 || run_rt_image() < 0) {
  684. dump_error_log();
  685. iwl_stop_device();
  686. if (M.state && M.state[0] != 'r' && M.state[0] != 'i')
  687. return -1;
  688. M.state = "firmware start failed";
  689. return -1;
  690. }
  691. M.up = 1;
  692. M.bound = M.ap_sta = 0;
  693. M.state = "ready";
  694. iwl_memcpy(mac, M.mac, 6);
  695. logs("firmware running");
  696. return 0;
  697. }
  698. int iwl_mvm_is_up(void)
  699. {
  700. return M.up;
  701. }
  702. const char *iwl_mvm_state(void)
  703. {
  704. return M.state ? M.state : "down";
  705. }
  706. void iwl_mvm_down(void)
  707. {
  708. if (iwl_present())
  709. iwl_stop_device();
  710. M.up = 0;
  711. M.scanning = 0;
  712. M.bound = M.ap_sta = 0;
  713. M.have_tk = 0;
  714. M.state = "down";
  715. }
  716. /* ---- scan -------------------------------------------------------------- */
  717. static const unsigned char scan_channels[] = {
  718. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  719. 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120,
  720. 124, 128, 132, 136, 140, 149, 153, 157, 161, 165,
  721. };
  722. int iwl_mvm_scan_running(void)
  723. {
  724. return M.scanning;
  725. }
  726. int iwl_mvm_scan_start(void)
  727. {
  728. struct scan_req_lmac *c;
  729. struct scan_chan_lmac *ch;
  730. unsigned char *preq, *buf;
  731. unsigned int i, n = sizeof(scan_channels), total, rx = M.valid_rx_ant;
  732. static const unsigned char rates24[] = { 1, 8, 0x82, 0x84, 0x8b, 0x96,
  733. 0x0c, 0x12, 0x18, 0x24,
  734. 50, 4, 0x30, 0x48, 0x60, 0x6c };
  735. static const unsigned char rates5[] = { 1, 8, 0x8c, 0x12, 0x98, 0x24,
  736. 0xb0, 0x48, 0x60, 0x6c };
  737. if (!M.up || M.scanning)
  738. return -1;
  739. if (n > 40)
  740. n = 40; /* n_scan_channels TLV */
  741. buf = M.scratch;
  742. iwl_memzero(buf, 4096);
  743. c = (struct scan_req_lmac *)buf;
  744. c->n_channels = n;
  745. c->active_dwell = 10;
  746. c->passive_dwell = 110;
  747. c->fragmented_dwell = 44;
  748. c->extended_dwell = 90;
  749. c->rx_chain_select = (rx << 1) | (rx << 7) | (rx << 4) | 1;
  750. /* PASS_ALL | EXTENDED_DWELL */
  751. c->scan_flags = (1u << 0) | (1u << 7);
  752. c->flags = 1; /* first channel: 2.4 GHz */
  753. c->filter_flags = (1u << 2) | (1u << 6); /* ACCEPT_GRP | IN_BEACON */
  754. c->tx_cmd[0].tx_flags = TX_FLG_SEQ_CTL | TX_FLG_BT_DIS;
  755. c->tx_cmd[0].rate_n_flags = PLCP_1M | RATE_CCK | RATE_ANT_A;
  756. c->tx_cmd[0].sta_id = IWL_STA_AUX;
  757. c->tx_cmd[1].tx_flags = TX_FLG_SEQ_CTL | TX_FLG_BT_DIS;
  758. c->tx_cmd[1].rate_n_flags = PLCP_6M | RATE_ANT_A;
  759. c->tx_cmd[1].sta_id = IWL_STA_AUX;
  760. c->scan_prio = 6; /* IWL_SCAN_PRIORITY_EXT_6 */
  761. c->iter_num = 1;
  762. c->schedule[0].iterations = 1;
  763. c->schedule[0].full_scan_mul = 1;
  764. ch = (struct scan_chan_lmac *)(buf + sizeof(*c));
  765. for (i = 0; i < n; i++) {
  766. ch[i].channel_num = scan_channels[i];
  767. ch[i].iter_count = 1;
  768. ch[i].flags = 1u << 28; /* UNIFIED_SCAN_CHANNEL_PARTIAL */
  769. }
  770. /* struct iwl_scan_probe_req_v1 after n_scan_channels (40) entries:
  771. * mac_header, band_data[2], common_data segments, then 512 bytes. */
  772. preq = buf + sizeof(*c) + 40 * sizeof(struct scan_chan_lmac);
  773. {
  774. unsigned char *f = preq + 16;
  775. unsigned int o = 0;
  776. f[0] = 0x40; /* probe request */
  777. for (i = 0; i < 6; i++) {
  778. f[4 + i] = 0xff;
  779. f[10 + i] = M.mac[i];
  780. f[16 + i] = 0xff;
  781. }
  782. f[24] = 0; /* SSID IE, filled by fw */
  783. f[25] = 0;
  784. put16(preq + 0, 0); /* mac_header offset */
  785. put16(preq + 2, 26); /* + empty SSID */
  786. o = 26;
  787. iwl_memcpy(f + o, rates24, sizeof(rates24));
  788. put16(preq + 4, o);
  789. put16(preq + 6, sizeof(rates24));
  790. o += sizeof(rates24);
  791. iwl_memcpy(f + o, rates5, sizeof(rates5));
  792. put16(preq + 8, o);
  793. put16(preq + 10, sizeof(rates5));
  794. o += sizeof(rates5);
  795. put16(preq + 12, o); /* common data: none */
  796. put16(preq + 14, 0);
  797. }
  798. total = sizeof(*c) + 40 * sizeof(struct scan_chan_lmac) + 16 + 512;
  799. M.scanning = 1;
  800. M.scan_ok = 0;
  801. if (cmd(SCAN_OFFLOAD_REQUEST_CMD, buf, total) < 0) {
  802. M.scanning = 0;
  803. return -1;
  804. }
  805. return 0;
  806. }
  807. /* ---- connection --------------------------------------------------------- */
  808. static int bind_and_quota(unsigned int action)
  809. {
  810. struct binding_cmd b;
  811. struct quota_cmd q;
  812. unsigned int status = 0, i;
  813. /* Removal: drop the quota first, then the binding (Linux order in
  814. * iwl_mvm_unassign_vif_chanctx()). */
  815. if (action == ACTION_REMOVE) {
  816. for (i = 0; i < 4; i++) {
  817. q.q[i].id_and_color = CTXT_INVALID;
  818. q.q[i].quota = 0;
  819. q.q[i].max_duration = 0;
  820. }
  821. if (cmd(TIME_QUOTA_CMD, &q, sizeof(q)) < 0)
  822. return -1;
  823. }
  824. b.id_and_color = 0; /* binding id = PHY context 0 */
  825. b.action = action;
  826. b.macs[0] = action == ACTION_REMOVE ? CTXT_INVALID : 0;
  827. b.macs[1] = b.macs[2] = CTXT_INVALID;
  828. b.phy = 0;
  829. if (cmd_status(BINDING_CONTEXT_CMD, &b, sizeof(b), &status) < 0 || status) {
  830. iwl_loghex("binding failed, status", status);
  831. return -1;
  832. }
  833. if (action == ACTION_REMOVE)
  834. return 0;
  835. for (i = 0; i < 4; i++) {
  836. q.q[i].id_and_color = CTXT_INVALID;
  837. q.q[i].quota = 0;
  838. q.q[i].max_duration = 0;
  839. }
  840. q.q[0].id_and_color = 0;
  841. q.q[0].quota = 128;
  842. return cmd(TIME_QUOTA_CMD, &q, sizeof(q));
  843. }
  844. static int add_ap_sta(int modify, unsigned short aid)
  845. {
  846. struct add_sta_cmd c;
  847. iwl_memzero(&c, sizeof(c));
  848. c.add_modify = modify ? 1 : 0;
  849. c.sta_id = IWL_STA_AP;
  850. c.mac_id_n_color = 0;
  851. iwl_memcpy(c.addr, M.bssid, 6);
  852. c.tid_disable_tx = 0xffff;
  853. c.station_flags_msk = (3u << 26) | (3u << 28) | (1u << 17);
  854. c.tfd_queue_msk = 1u << IWL_Q_BSS;
  855. c.assoc_id = aid;
  856. return add_sta(&c);
  857. }
  858. static int remove_sta(unsigned int id)
  859. {
  860. unsigned char c[4] = { (unsigned char)id, 0, 0, 0 };
  861. unsigned int status;
  862. return cmd_status(REMOVE_STA, c, 4, &status);
  863. }
  864. int iwl_mvm_prepare_connect(const unsigned char bssid[6], unsigned int chan,
  865. unsigned int beacon_int)
  866. {
  867. struct time_event_cmd te;
  868. unsigned int t;
  869. if (!M.up)
  870. return -1;
  871. if (M.ap_sta)
  872. iwl_mvm_disconnect();
  873. iwl_memcpy(M.bssid, bssid, 6);
  874. if (phy_ctx(ACTION_MODIFY, chan) < 0)
  875. return -1;
  876. if (!M.bound) {
  877. if (bind_and_quota(ACTION_ADD) < 0)
  878. return -1;
  879. M.bound = 1;
  880. }
  881. if (enable_queue(IWL_Q_BSS, IWL_STA_AP, 0, 1 /* BE FIFO */) < 0)
  882. return -1;
  883. if (add_ap_sta(0, 0) < 0)
  884. return -1;
  885. M.ap_sta = 1;
  886. if (mac_ctx(ACTION_MODIFY, 0, 0, beacon_int, 1) < 0)
  887. return -1;
  888. /* Session protection: stay on the channel for the auth/assoc
  889. * exchange (TE_BSS_STA_AGGRESSIVE_ASSOC, ~1 s). */
  890. iwl_memzero(&te, sizeof(te));
  891. te.id_and_color = 0;
  892. te.action = ACTION_ADD;
  893. te.id = 0;
  894. te.max_delay = 500;
  895. te.interval = 1;
  896. te.duration = 1000;
  897. te.repeat = 1;
  898. te.max_frags = 0;
  899. te.policy = (1u << 0) | (1u << 1) | (1u << 11);
  900. M.te_started = 0;
  901. if (cmd(TIME_EVENT_CMD, &te, sizeof(te)) < 0)
  902. return -1;
  903. for (t = 0; t < 600 && !M.te_started; t++) {
  904. if (iwl_rx_poll() < 0)
  905. return -1;
  906. if (!M.te_started)
  907. iwl_udelay(1000);
  908. }
  909. if (!M.te_started)
  910. logs("time event did not start (continuing)");
  911. return 0;
  912. }
  913. int iwl_mvm_set_assoc(unsigned short aid, unsigned int beacon_int,
  914. unsigned int dtim)
  915. {
  916. if (!M.ap_sta)
  917. return -1;
  918. if (add_ap_sta(1, aid) < 0)
  919. return -1;
  920. return mac_ctx(ACTION_MODIFY, 1, aid, beacon_int, dtim);
  921. }
  922. void iwl_mvm_disconnect(void)
  923. {
  924. if (!M.up)
  925. return;
  926. if (M.ap_sta) {
  927. struct scd_cfg_cmd c;
  928. /* Disable the queue, then remove the station (iwl_mvm_rm_sta()
  929. * order); the next connect enables the queue again. */
  930. iwl_memzero(&c, sizeof(c));
  931. c.sta_id = IWL_STA_AP;
  932. c.tid = 0;
  933. c.scd_queue = IWL_Q_BSS;
  934. c.action = 0; /* SCD_CFG_DISABLE_QUEUE */
  935. cmd(SCD_QUEUE_CFG, &c, sizeof(c));
  936. remove_sta(IWL_STA_AP);
  937. M.ap_sta = 0;
  938. }
  939. M.have_tk = 0;
  940. mac_ctx(ACTION_MODIFY, 0, 0, 100, 1);
  941. if (M.bound) {
  942. bind_and_quota(ACTION_REMOVE);
  943. M.bound = 0;
  944. }
  945. }
  946. /* ---- TX ---------------------------------------------------------------- */
  947. static int tx_frame(const unsigned char *frame, unsigned int len, int mgmt,
  948. int protect)
  949. {
  950. struct tx_cmd c;
  951. int q = M.ap_sta ? IWL_Q_BSS : IWL_Q_AUX;
  952. unsigned int sta = M.ap_sta ? IWL_STA_AP : IWL_STA_AUX;
  953. int bcast = frame[4] & 1;
  954. unsigned int stype = (frame[0] >> 4) & 0xf;
  955. iwl_memzero(&c, sizeof(c));
  956. c.len = len;
  957. c.tx_flags = TX_FLG_SEQ_CTL | (bcast ? 0 : TX_FLG_ACK);
  958. if (mgmt) {
  959. c.rate_n_flags = M.chan <= 14 ? (PLCP_1M | RATE_CCK | RATE_ANT_A)
  960. : (PLCP_6M | RATE_ANT_A);
  961. c.tid_tspec = 8; /* IWL_MAX_TID_COUNT */
  962. c.pm_frame_timeout = (stype == 0 || stype == 2) ? 3 : 2;
  963. } else {
  964. c.rate_n_flags = PLCP_12M | RATE_ANT_A;
  965. c.tid_tspec = 0; /* IWL_TID_NON_QOS */
  966. c.pm_frame_timeout = 0;
  967. }
  968. c.sta_id = sta;
  969. c.life_time = 0xffffffffu;
  970. c.rts_retry_limit = 60;
  971. c.data_retry_limit = mgmt ? 3 : 15;
  972. if (protect) {
  973. if (!M.have_tk)
  974. return -1;
  975. c.sec_ctl = 0x02; /* TX_CMD_SEC_CCM */
  976. iwl_memcpy(c.key, M.tk, 16);
  977. }
  978. return iwl_tx(q, &c, sizeof(c), frame, len, sta, protect ? 8 : 0);
  979. }
  980. int iwl_mvm_tx_mgmt(const unsigned char *frame, unsigned int len)
  981. {
  982. return M.up ? tx_frame(frame, len, 1, 0) : -1;
  983. }
  984. int iwl_mvm_tx_data(const unsigned char *frame, unsigned int len, int protect)
  985. {
  986. return M.up && M.ap_sta ? tx_frame(frame, len, 0, protect) : -1;
  987. }
  988. /* ---- keys -------------------------------------------------------------- */
  989. int iwl_mvm_set_key(int pairwise, int keyidx, const unsigned char key[16],
  990. const unsigned char rsc[6])
  991. {
  992. struct sta_key_cmd c;
  993. unsigned int status = 0;
  994. if (!M.ap_sta)
  995. return -1;
  996. iwl_memzero(&c, sizeof(c));
  997. c.sta_id = IWL_STA_AP;
  998. c.key_offset = pairwise ? 0 : (unsigned char)(1 + (keyidx & 3));
  999. c.key_flags = (unsigned short)(((keyidx & 3) << 8) | (1u << 3) | 2u);
  1000. if (!pairwise)
  1001. c.key_flags |= 1u << 14; /* STA_KEY_MULTICAST */
  1002. iwl_memcpy(c.key, key, 16);
  1003. if (rsc) {
  1004. /* API v1: PN bytes 0,1 then a 2-byte hole, then 2..5. */
  1005. c.rx_secur_seq_cnt[0] = rsc[0];
  1006. c.rx_secur_seq_cnt[1] = rsc[1];
  1007. c.rx_secur_seq_cnt[4] = rsc[2];
  1008. c.rx_secur_seq_cnt[5] = rsc[3];
  1009. c.rx_secur_seq_cnt[6] = rsc[4];
  1010. c.rx_secur_seq_cnt[7] = rsc[5];
  1011. }
  1012. if (cmd_status(ADD_STA_KEY, &c, sizeof(c), &status) < 0 ||
  1013. (status & 0xff) != 1) {
  1014. iwl_loghex("ADD_STA_KEY failed, status", status);
  1015. return -1;
  1016. }
  1017. if (pairwise) {
  1018. iwl_memcpy(M.tk, key, 16);
  1019. M.have_tk = 1;
  1020. }
  1021. return 0;
  1022. }
  1023. void iwl_mvm_clear_keys(void)
  1024. {
  1025. M.have_tk = 0;
  1026. }