1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * NXP Wireless LAN device driver: station command handling 4 * 5 * Copyright 2011-2020 NXP 6 */ 7 8 #include "decl.h" 9 #include "ioctl.h" 10 #include "util.h" 11 #include "fw.h" 12 #include "main.h" 13 #include "wmm.h" 14 #include "11n.h" 15 #include "11ac.h" 16 17 static bool drcs; 18 module_param(drcs, bool, 0644); 19 MODULE_PARM_DESC(drcs, "multi-channel operation:1, single-channel operation:0"); 20 21 static bool disable_auto_ds; 22 module_param(disable_auto_ds, bool, 0); 23 MODULE_PARM_DESC(disable_auto_ds, 24 "deepsleep enabled=0(default), deepsleep disabled=1"); 25 /* 26 * This function prepares command to set/get RSSI information. 27 * 28 * Preparation includes - 29 * - Setting command ID, action and proper size 30 * - Setting data/beacon average factors 31 * - Resetting SNR/NF/RSSI values in private structure 32 * - Ensuring correct endian-ness 33 */ 34 static int 35 mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv, 36 struct host_cmd_ds_command *cmd, u16 cmd_action) 37 { 38 cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO); 39 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) + 40 S_DS_GEN); 41 cmd->params.rssi_info.action = cpu_to_le16(cmd_action); 42 cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor); 43 cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor); 44 45 /* Reset SNR/NF/RSSI values in private structure */ 46 priv->data_rssi_last = 0; 47 priv->data_nf_last = 0; 48 priv->data_rssi_avg = 0; 49 priv->data_nf_avg = 0; 50 priv->bcn_rssi_last = 0; 51 priv->bcn_nf_last = 0; 52 priv->bcn_rssi_avg = 0; 53 priv->bcn_nf_avg = 0; 54 55 return 0; 56 } 57 58 /* 59 * This function prepares command to set MAC control. 60 * 61 * Preparation includes - 62 * - Setting command ID, action and proper size 63 * - Ensuring correct endian-ness 64 */ 65 static int mwifiex_cmd_mac_control(struct mwifiex_private *priv, 66 struct host_cmd_ds_command *cmd, 67 u16 cmd_action, u32 *action) 68 { 69 struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl; 70 71 if (cmd_action != HostCmd_ACT_GEN_SET) { 72 mwifiex_dbg(priv->adapter, ERROR, 73 "mac_control: only support set cmd\n"); 74 return -1; 75 } 76 77 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL); 78 cmd->size = 79 cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN); 80 mac_ctrl->action = cpu_to_le32(*action); 81 82 return 0; 83 } 84 85 /* 86 * This function prepares command to set/get SNMP MIB. 87 * 88 * Preparation includes - 89 * - Setting command ID, action and proper size 90 * - Setting SNMP MIB OID number and value 91 * (as required) 92 * - Ensuring correct endian-ness 93 * 94 * The following SNMP MIB OIDs are supported - 95 * - FRAG_THRESH_I : Fragmentation threshold 96 * - RTS_THRESH_I : RTS threshold 97 * - SHORT_RETRY_LIM_I : Short retry limit 98 * - DOT11D_I : 11d support 99 */ 100 static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv, 101 struct host_cmd_ds_command *cmd, 102 u16 cmd_action, u32 cmd_oid, 103 u16 *ul_temp) 104 { 105 struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib; 106 107 mwifiex_dbg(priv->adapter, CMD, 108 "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid); 109 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB); 110 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib) 111 - 1 + S_DS_GEN); 112 113 snmp_mib->oid = cpu_to_le16((u16)cmd_oid); 114 if (cmd_action == HostCmd_ACT_GEN_GET) { 115 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET); 116 snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE); 117 le16_unaligned_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE); 118 } else if (cmd_action == HostCmd_ACT_GEN_SET) { 119 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET); 120 snmp_mib->buf_size = cpu_to_le16(sizeof(u16)); 121 put_unaligned_le16(*ul_temp, snmp_mib->value); 122 le16_unaligned_add_cpu(&cmd->size, sizeof(u16)); 123 } 124 125 mwifiex_dbg(priv->adapter, CMD, 126 "cmd: SNMP_CMD: Action=0x%x, OID=0x%x,\t" 127 "OIDSize=0x%x, Value=0x%x\n", 128 cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size), 129 get_unaligned_le16(snmp_mib->value)); 130 return 0; 131 } 132 133 /* 134 * This function prepares command to get log. 135 * 136 * Preparation includes - 137 * - Setting command ID and proper size 138 * - Ensuring correct endian-ness 139 */ 140 static int 141 mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd) 142 { 143 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG); 144 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) + 145 S_DS_GEN); 146 return 0; 147 } 148 149 /* 150 * This function prepares command to set/get Tx data rate configuration. 151 * 152 * Preparation includes - 153 * - Setting command ID, action and proper size 154 * - Setting configuration index, rate scope and rate drop pattern 155 * parameters (as required) 156 * - Ensuring correct endian-ness 157 */ 158 static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv, 159 struct host_cmd_ds_command *cmd, 160 u16 cmd_action, const u16 *pbitmap_rates) 161 { 162 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg; 163 struct mwifiex_rate_scope *rate_scope; 164 struct mwifiex_rate_drop_pattern *rate_drop; 165 u32 i; 166 167 cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG); 168 169 rate_cfg->action = cpu_to_le16(cmd_action); 170 rate_cfg->cfg_index = 0; 171 172 rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg + 173 sizeof(struct host_cmd_ds_tx_rate_cfg)); 174 rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE); 175 rate_scope->length = cpu_to_le16 176 (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header)); 177 if (!pbitmap_rates) 178 pbitmap_rates = priv->bitmap_rates; 179 180 rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]); 181 rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]); 182 183 for (i = 0; i < ARRAY_SIZE(rate_scope->ht_mcs_rate_bitmap); i++) 184 rate_scope->ht_mcs_rate_bitmap[i] = cpu_to_le16(pbitmap_rates[2 + i]); 185 186 if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) { 187 for (i = 0; i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap); i++) 188 rate_scope->vht_mcs_rate_bitmap[i] = 189 cpu_to_le16(pbitmap_rates[10 + i]); 190 } 191 192 rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope + 193 sizeof(struct mwifiex_rate_scope)); 194 rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL); 195 rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode)); 196 rate_drop->rate_drop_mode = 0; 197 198 cmd->size = 199 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) + 200 sizeof(struct mwifiex_rate_scope) + 201 sizeof(struct mwifiex_rate_drop_pattern)); 202 203 return 0; 204 } 205 206 /* 207 * This function prepares command to set/get Tx power configuration. 208 * 209 * Preparation includes - 210 * - Setting command ID, action and proper size 211 * - Setting Tx power mode, power group TLV 212 * (as required) 213 * - Ensuring correct endian-ness 214 */ 215 static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd, 216 u16 cmd_action, 217 struct host_cmd_ds_txpwr_cfg *txp) 218 { 219 struct mwifiex_types_power_group *pg_tlv; 220 struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg; 221 222 cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG); 223 cmd->size = 224 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg)); 225 switch (cmd_action) { 226 case HostCmd_ACT_GEN_SET: 227 if (txp->mode) { 228 pg_tlv = (struct mwifiex_types_power_group 229 *) ((unsigned long) txp + 230 sizeof(struct host_cmd_ds_txpwr_cfg)); 231 memmove(cmd_txp_cfg, txp, 232 sizeof(struct host_cmd_ds_txpwr_cfg) + 233 sizeof(struct mwifiex_types_power_group) + 234 le16_to_cpu(pg_tlv->length)); 235 236 pg_tlv = (struct mwifiex_types_power_group *) ((u8 *) 237 cmd_txp_cfg + 238 sizeof(struct host_cmd_ds_txpwr_cfg)); 239 cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) + 240 sizeof(struct mwifiex_types_power_group) + 241 le16_to_cpu(pg_tlv->length)); 242 } else { 243 memmove(cmd_txp_cfg, txp, sizeof(*txp)); 244 } 245 cmd_txp_cfg->action = cpu_to_le16(cmd_action); 246 break; 247 case HostCmd_ACT_GEN_GET: 248 cmd_txp_cfg->action = cpu_to_le16(cmd_action); 249 break; 250 } 251 252 return 0; 253 } 254 255 /* 256 * This function prepares command to get RF Tx power. 257 */ 258 static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv, 259 struct host_cmd_ds_command *cmd, 260 u16 cmd_action, void *data_buf) 261 { 262 struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp; 263 264 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr) 265 + S_DS_GEN); 266 cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR); 267 txp->action = cpu_to_le16(cmd_action); 268 269 return 0; 270 } 271 272 /* 273 * This function prepares command to set rf antenna. 274 */ 275 static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv, 276 struct host_cmd_ds_command *cmd, 277 u16 cmd_action, 278 struct mwifiex_ds_ant_cfg *ant_cfg) 279 { 280 struct host_cmd_ds_rf_ant_mimo *ant_mimo = &cmd->params.ant_mimo; 281 struct host_cmd_ds_rf_ant_siso *ant_siso = &cmd->params.ant_siso; 282 283 cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA); 284 285 switch (cmd_action) { 286 case HostCmd_ACT_GEN_SET: 287 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) { 288 cmd->size = cpu_to_le16(sizeof(struct 289 host_cmd_ds_rf_ant_mimo) 290 + S_DS_GEN); 291 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX); 292 ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg-> 293 tx_ant); 294 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX); 295 ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg-> 296 rx_ant); 297 } else { 298 cmd->size = cpu_to_le16(sizeof(struct 299 host_cmd_ds_rf_ant_siso) + 300 S_DS_GEN); 301 ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH); 302 ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant); 303 } 304 break; 305 case HostCmd_ACT_GEN_GET: 306 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) { 307 cmd->size = cpu_to_le16(sizeof(struct 308 host_cmd_ds_rf_ant_mimo) + 309 S_DS_GEN); 310 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_GET_TX); 311 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_GET_RX); 312 } else { 313 cmd->size = cpu_to_le16(sizeof(struct 314 host_cmd_ds_rf_ant_siso) + 315 S_DS_GEN); 316 ant_siso->action = cpu_to_le16(HostCmd_ACT_GET_BOTH); 317 } 318 break; 319 } 320 return 0; 321 } 322 323 /* 324 * This function prepares command to set Host Sleep configuration. 325 * 326 * Preparation includes - 327 * - Setting command ID and proper size 328 * - Setting Host Sleep action, conditions, ARP filters 329 * (as required) 330 * - Ensuring correct endian-ness 331 */ 332 static int 333 mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv, 334 struct host_cmd_ds_command *cmd, 335 u16 cmd_action, 336 struct mwifiex_hs_config_param *hscfg_param) 337 { 338 struct mwifiex_adapter *adapter = priv->adapter; 339 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg; 340 u8 *tlv = (u8 *)hs_cfg + sizeof(struct host_cmd_ds_802_11_hs_cfg_enh); 341 struct mwifiex_ps_param_in_hs *psparam_tlv = NULL; 342 bool hs_activate = false; 343 u16 size; 344 345 if (!hscfg_param) 346 /* New Activate command */ 347 hs_activate = true; 348 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH); 349 350 if (!hs_activate && 351 (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) && 352 ((adapter->arp_filter_size > 0) && 353 (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) { 354 mwifiex_dbg(adapter, CMD, 355 "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n", 356 adapter->arp_filter_size); 357 memcpy(((u8 *) hs_cfg) + 358 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh), 359 adapter->arp_filter, adapter->arp_filter_size); 360 size = adapter->arp_filter_size + 361 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh) 362 + S_DS_GEN; 363 tlv = (u8 *)hs_cfg 364 + sizeof(struct host_cmd_ds_802_11_hs_cfg_enh) 365 + adapter->arp_filter_size; 366 } else { 367 size = S_DS_GEN + sizeof(struct host_cmd_ds_802_11_hs_cfg_enh); 368 } 369 if (hs_activate) { 370 hs_cfg->action = cpu_to_le16(HS_ACTIVATE); 371 hs_cfg->params.hs_activate.resp_ctrl = cpu_to_le16(RESP_NEEDED); 372 373 adapter->hs_activated_manually = true; 374 mwifiex_dbg(priv->adapter, CMD, 375 "cmd: Activating host sleep manually\n"); 376 } else { 377 hs_cfg->action = cpu_to_le16(HS_CONFIGURE); 378 hs_cfg->params.hs_config.conditions = hscfg_param->conditions; 379 hs_cfg->params.hs_config.gpio = hscfg_param->gpio; 380 hs_cfg->params.hs_config.gap = hscfg_param->gap; 381 382 size += sizeof(struct mwifiex_ps_param_in_hs); 383 psparam_tlv = (struct mwifiex_ps_param_in_hs *)tlv; 384 psparam_tlv->header.type = 385 cpu_to_le16(TLV_TYPE_PS_PARAMS_IN_HS); 386 psparam_tlv->header.len = 387 cpu_to_le16(sizeof(struct mwifiex_ps_param_in_hs) 388 - sizeof(struct mwifiex_ie_types_header)); 389 psparam_tlv->hs_wake_int = cpu_to_le32(HS_DEF_WAKE_INTERVAL); 390 psparam_tlv->hs_inact_timeout = 391 cpu_to_le32(HS_DEF_INACTIVITY_TIMEOUT); 392 393 mwifiex_dbg(adapter, CMD, 394 "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n", 395 hs_cfg->params.hs_config.conditions, 396 hs_cfg->params.hs_config.gpio, 397 hs_cfg->params.hs_config.gap); 398 } 399 cmd->size = cpu_to_le16(size); 400 401 return 0; 402 } 403 404 /* 405 * This function prepares command to set/get MAC address. 406 * 407 * Preparation includes - 408 * - Setting command ID, action and proper size 409 * - Setting MAC address (for SET only) 410 * - Ensuring correct endian-ness 411 */ 412 static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv, 413 struct host_cmd_ds_command *cmd, 414 u16 cmd_action) 415 { 416 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS); 417 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) + 418 S_DS_GEN); 419 cmd->result = 0; 420 421 cmd->params.mac_addr.action = cpu_to_le16(cmd_action); 422 423 if (cmd_action == HostCmd_ACT_GEN_SET) 424 memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr, 425 ETH_ALEN); 426 return 0; 427 } 428 429 /* 430 * This function prepares command to set MAC multicast address. 431 * 432 * Preparation includes - 433 * - Setting command ID, action and proper size 434 * - Setting MAC multicast address 435 * - Ensuring correct endian-ness 436 */ 437 static int 438 mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd, 439 u16 cmd_action, 440 struct mwifiex_multicast_list *mcast_list) 441 { 442 struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr; 443 444 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) + 445 S_DS_GEN); 446 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR); 447 448 mcast_addr->action = cpu_to_le16(cmd_action); 449 mcast_addr->num_of_adrs = 450 cpu_to_le16((u16) mcast_list->num_multicast_addr); 451 memcpy(mcast_addr->mac_list, mcast_list->mac_list, 452 mcast_list->num_multicast_addr * ETH_ALEN); 453 454 return 0; 455 } 456 457 /* 458 * This function prepares command to deauthenticate. 459 * 460 * Preparation includes - 461 * - Setting command ID and proper size 462 * - Setting AP MAC address and reason code 463 * - Ensuring correct endian-ness 464 */ 465 static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv, 466 struct host_cmd_ds_command *cmd, 467 u8 *mac) 468 { 469 struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth; 470 471 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE); 472 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate) 473 + S_DS_GEN); 474 475 /* Set AP MAC address */ 476 memcpy(deauth->mac_addr, mac, ETH_ALEN); 477 478 mwifiex_dbg(priv->adapter, CMD, "cmd: Deauth: %pM\n", deauth->mac_addr); 479 480 deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING); 481 482 return 0; 483 } 484 485 /* 486 * This function prepares command to stop Ad-Hoc network. 487 * 488 * Preparation includes - 489 * - Setting command ID and proper size 490 * - Ensuring correct endian-ness 491 */ 492 static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd) 493 { 494 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP); 495 cmd->size = cpu_to_le16(S_DS_GEN); 496 return 0; 497 } 498 499 /* 500 * This function sets WEP key(s) to key parameter TLV(s). 501 * 502 * Multi-key parameter TLVs are supported, so we can send multiple 503 * WEP keys in a single buffer. 504 */ 505 static int 506 mwifiex_set_keyparamset_wep(struct mwifiex_private *priv, 507 struct mwifiex_ie_type_key_param_set *key_param_set, 508 u16 *key_param_len) 509 { 510 int cur_key_param_len; 511 u8 i; 512 513 /* Multi-key_param_set TLV is supported */ 514 for (i = 0; i < NUM_WEP_KEYS; i++) { 515 if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) || 516 (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) { 517 key_param_set->type = 518 cpu_to_le16(TLV_TYPE_KEY_MATERIAL); 519 /* Key_param_set WEP fixed length */ 520 #define KEYPARAMSET_WEP_FIXED_LEN 8 521 key_param_set->length = cpu_to_le16((u16) 522 (priv->wep_key[i]. 523 key_length + 524 KEYPARAMSET_WEP_FIXED_LEN)); 525 key_param_set->key_type_id = 526 cpu_to_le16(KEY_TYPE_ID_WEP); 527 key_param_set->key_info = 528 cpu_to_le16(KEY_ENABLED | KEY_UNICAST | 529 KEY_MCAST); 530 key_param_set->key_len = 531 cpu_to_le16(priv->wep_key[i].key_length); 532 /* Set WEP key index */ 533 key_param_set->key[0] = i; 534 /* Set default Tx key flag */ 535 if (i == 536 (priv-> 537 wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK)) 538 key_param_set->key[1] = 1; 539 else 540 key_param_set->key[1] = 0; 541 memmove(&key_param_set->key[2], 542 priv->wep_key[i].key_material, 543 priv->wep_key[i].key_length); 544 545 cur_key_param_len = priv->wep_key[i].key_length + 546 KEYPARAMSET_WEP_FIXED_LEN + 547 sizeof(struct mwifiex_ie_types_header); 548 *key_param_len += (u16) cur_key_param_len; 549 key_param_set = 550 (struct mwifiex_ie_type_key_param_set *) 551 ((u8 *)key_param_set + 552 cur_key_param_len); 553 } else if (!priv->wep_key[i].key_length) { 554 continue; 555 } else { 556 mwifiex_dbg(priv->adapter, ERROR, 557 "key%d Length = %d is incorrect\n", 558 (i + 1), priv->wep_key[i].key_length); 559 return -1; 560 } 561 } 562 563 return 0; 564 } 565 566 /* This function populates key material v2 command 567 * to set network key for AES & CMAC AES. 568 */ 569 static int mwifiex_set_aes_key_v2(struct mwifiex_private *priv, 570 struct host_cmd_ds_command *cmd, 571 struct mwifiex_ds_encrypt_key *enc_key, 572 struct host_cmd_ds_802_11_key_material_v2 *km) 573 { 574 struct mwifiex_adapter *adapter = priv->adapter; 575 u16 size, len = KEY_PARAMS_FIXED_LEN; 576 577 if (enc_key->is_igtk_key) { 578 mwifiex_dbg(adapter, INFO, 579 "%s: Set CMAC AES Key\n", __func__); 580 if (enc_key->is_rx_seq_valid) 581 memcpy(km->key_param_set.key_params.cmac_aes.ipn, 582 enc_key->pn, enc_key->pn_len); 583 km->key_param_set.key_info &= cpu_to_le16(~KEY_MCAST); 584 km->key_param_set.key_info |= cpu_to_le16(KEY_IGTK); 585 km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC; 586 km->key_param_set.key_params.cmac_aes.key_len = 587 cpu_to_le16(enc_key->key_len); 588 memcpy(km->key_param_set.key_params.cmac_aes.key, 589 enc_key->key_material, enc_key->key_len); 590 len += sizeof(struct mwifiex_cmac_aes_param); 591 } else if (enc_key->is_igtk_def_key) { 592 mwifiex_dbg(adapter, INFO, 593 "%s: Set CMAC default Key index\n", __func__); 594 km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC_DEF; 595 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK; 596 } else { 597 mwifiex_dbg(adapter, INFO, 598 "%s: Set AES Key\n", __func__); 599 if (enc_key->is_rx_seq_valid) 600 memcpy(km->key_param_set.key_params.aes.pn, 601 enc_key->pn, enc_key->pn_len); 602 km->key_param_set.key_type = KEY_TYPE_ID_AES; 603 km->key_param_set.key_params.aes.key_len = 604 cpu_to_le16(enc_key->key_len); 605 memcpy(km->key_param_set.key_params.aes.key, 606 enc_key->key_material, enc_key->key_len); 607 len += sizeof(struct mwifiex_aes_param); 608 } 609 610 km->key_param_set.len = cpu_to_le16(len); 611 size = len + sizeof(struct mwifiex_ie_types_header) + 612 sizeof(km->action) + S_DS_GEN; 613 cmd->size = cpu_to_le16(size); 614 615 return 0; 616 } 617 618 /* This function prepares command to set/get/reset network key(s). 619 * This function prepares key material command for V2 format. 620 * Preparation includes - 621 * - Setting command ID, action and proper size 622 * - Setting WEP keys, WAPI keys or WPA keys along with required 623 * encryption (TKIP, AES) (as required) 624 * - Ensuring correct endian-ness 625 */ 626 static int 627 mwifiex_cmd_802_11_key_material_v2(struct mwifiex_private *priv, 628 struct host_cmd_ds_command *cmd, 629 u16 cmd_action, u32 cmd_oid, 630 struct mwifiex_ds_encrypt_key *enc_key) 631 { 632 struct mwifiex_adapter *adapter = priv->adapter; 633 u8 *mac = enc_key->mac_addr; 634 u16 key_info, len = KEY_PARAMS_FIXED_LEN; 635 struct host_cmd_ds_802_11_key_material_v2 *km = 636 &cmd->params.key_material_v2; 637 638 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL); 639 km->action = cpu_to_le16(cmd_action); 640 641 if (cmd_action == HostCmd_ACT_GEN_GET) { 642 mwifiex_dbg(adapter, INFO, "%s: Get key\n", __func__); 643 km->key_param_set.key_idx = 644 enc_key->key_index & KEY_INDEX_MASK; 645 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2); 646 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN); 647 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN); 648 649 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST) 650 key_info = KEY_UNICAST; 651 else 652 key_info = KEY_MCAST; 653 654 if (enc_key->is_igtk_key) 655 key_info |= KEY_IGTK; 656 657 km->key_param_set.key_info = cpu_to_le16(key_info); 658 659 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) + 660 S_DS_GEN + KEY_PARAMS_FIXED_LEN + 661 sizeof(km->action)); 662 return 0; 663 } 664 665 memset(&km->key_param_set, 0, 666 sizeof(struct mwifiex_ie_type_key_param_set_v2)); 667 668 if (enc_key->key_disable) { 669 mwifiex_dbg(adapter, INFO, "%s: Remove key\n", __func__); 670 km->action = cpu_to_le16(HostCmd_ACT_GEN_REMOVE); 671 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2); 672 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN); 673 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK; 674 key_info = KEY_MCAST | KEY_UNICAST; 675 km->key_param_set.key_info = cpu_to_le16(key_info); 676 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN); 677 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) + 678 S_DS_GEN + KEY_PARAMS_FIXED_LEN + 679 sizeof(km->action)); 680 return 0; 681 } 682 683 km->action = cpu_to_le16(HostCmd_ACT_GEN_SET); 684 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK; 685 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2); 686 key_info = KEY_ENABLED; 687 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN); 688 689 if (enc_key->key_len <= WLAN_KEY_LEN_WEP104) { 690 mwifiex_dbg(adapter, INFO, "%s: Set WEP Key\n", __func__); 691 len += sizeof(struct mwifiex_wep_param); 692 km->key_param_set.len = cpu_to_le16(len); 693 km->key_param_set.key_type = KEY_TYPE_ID_WEP; 694 695 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { 696 key_info |= KEY_MCAST | KEY_UNICAST; 697 } else { 698 if (enc_key->is_current_wep_key) { 699 key_info |= KEY_MCAST | KEY_UNICAST; 700 if (km->key_param_set.key_idx == 701 (priv->wep_key_curr_index & KEY_INDEX_MASK)) 702 key_info |= KEY_DEFAULT; 703 } else { 704 if (is_broadcast_ether_addr(mac)) 705 key_info |= KEY_MCAST; 706 else 707 key_info |= KEY_UNICAST | KEY_DEFAULT; 708 } 709 } 710 km->key_param_set.key_info = cpu_to_le16(key_info); 711 712 km->key_param_set.key_params.wep.key_len = 713 cpu_to_le16(enc_key->key_len); 714 memcpy(km->key_param_set.key_params.wep.key, 715 enc_key->key_material, enc_key->key_len); 716 717 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) + 718 len + sizeof(km->action) + S_DS_GEN); 719 return 0; 720 } 721 722 if (is_broadcast_ether_addr(mac)) 723 key_info |= KEY_MCAST | KEY_RX_KEY; 724 else 725 key_info |= KEY_UNICAST | KEY_TX_KEY | KEY_RX_KEY; 726 727 if (enc_key->is_wapi_key) { 728 mwifiex_dbg(adapter, INFO, "%s: Set WAPI Key\n", __func__); 729 km->key_param_set.key_type = KEY_TYPE_ID_WAPI; 730 memcpy(km->key_param_set.key_params.wapi.pn, enc_key->pn, 731 PN_LEN); 732 km->key_param_set.key_params.wapi.key_len = 733 cpu_to_le16(enc_key->key_len); 734 memcpy(km->key_param_set.key_params.wapi.key, 735 enc_key->key_material, enc_key->key_len); 736 if (is_broadcast_ether_addr(mac)) 737 priv->sec_info.wapi_key_on = true; 738 739 if (!priv->sec_info.wapi_key_on) 740 key_info |= KEY_DEFAULT; 741 km->key_param_set.key_info = cpu_to_le16(key_info); 742 743 len += sizeof(struct mwifiex_wapi_param); 744 km->key_param_set.len = cpu_to_le16(len); 745 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) + 746 len + sizeof(km->action) + S_DS_GEN); 747 return 0; 748 } 749 750 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) { 751 key_info |= KEY_DEFAULT; 752 /* Enable unicast bit for WPA-NONE/ADHOC_AES */ 753 if (!priv->sec_info.wpa2_enabled && 754 !is_broadcast_ether_addr(mac)) 755 key_info |= KEY_UNICAST; 756 } else { 757 /* Enable default key for WPA/WPA2 */ 758 if (!priv->wpa_is_gtk_set) 759 key_info |= KEY_DEFAULT; 760 } 761 762 km->key_param_set.key_info = cpu_to_le16(key_info); 763 764 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) 765 return mwifiex_set_aes_key_v2(priv, cmd, enc_key, km); 766 767 if (enc_key->key_len == WLAN_KEY_LEN_TKIP) { 768 mwifiex_dbg(adapter, INFO, 769 "%s: Set TKIP Key\n", __func__); 770 if (enc_key->is_rx_seq_valid) 771 memcpy(km->key_param_set.key_params.tkip.pn, 772 enc_key->pn, enc_key->pn_len); 773 km->key_param_set.key_type = KEY_TYPE_ID_TKIP; 774 km->key_param_set.key_params.tkip.key_len = 775 cpu_to_le16(enc_key->key_len); 776 memcpy(km->key_param_set.key_params.tkip.key, 777 enc_key->key_material, enc_key->key_len); 778 779 len += sizeof(struct mwifiex_tkip_param); 780 km->key_param_set.len = cpu_to_le16(len); 781 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) + 782 len + sizeof(km->action) + S_DS_GEN); 783 } 784 785 return 0; 786 } 787 788 /* 789 * This function prepares command to set/get/reset network key(s). 790 * This function prepares key material command for V1 format. 791 * 792 * Preparation includes - 793 * - Setting command ID, action and proper size 794 * - Setting WEP keys, WAPI keys or WPA keys along with required 795 * encryption (TKIP, AES) (as required) 796 * - Ensuring correct endian-ness 797 */ 798 static int 799 mwifiex_cmd_802_11_key_material_v1(struct mwifiex_private *priv, 800 struct host_cmd_ds_command *cmd, 801 u16 cmd_action, u32 cmd_oid, 802 struct mwifiex_ds_encrypt_key *enc_key) 803 { 804 struct host_cmd_ds_802_11_key_material *key_material = 805 &cmd->params.key_material; 806 struct host_cmd_tlv_mac_addr *tlv_mac; 807 u16 key_param_len = 0, cmd_size; 808 int ret = 0; 809 810 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL); 811 key_material->action = cpu_to_le16(cmd_action); 812 813 if (cmd_action == HostCmd_ACT_GEN_GET) { 814 cmd->size = 815 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN); 816 return ret; 817 } 818 819 if (!enc_key) { 820 struct host_cmd_ds_802_11_key_material_wep *key_material_wep = 821 (struct host_cmd_ds_802_11_key_material_wep *)key_material; 822 memset(key_material_wep->key_param_set, 0, 823 sizeof(key_material_wep->key_param_set)); 824 ret = mwifiex_set_keyparamset_wep(priv, 825 &key_material_wep->key_param_set[0], 826 &key_param_len); 827 cmd->size = cpu_to_le16(key_param_len + 828 sizeof(key_material_wep->action) + S_DS_GEN); 829 return ret; 830 } else 831 memset(&key_material->key_param_set, 0, 832 sizeof(struct mwifiex_ie_type_key_param_set)); 833 if (enc_key->is_wapi_key) { 834 struct mwifiex_ie_type_key_param_set *set; 835 836 mwifiex_dbg(priv->adapter, INFO, "info: Set WAPI Key\n"); 837 set = &key_material->key_param_set; 838 set->key_type_id = cpu_to_le16(KEY_TYPE_ID_WAPI); 839 if (cmd_oid == KEY_INFO_ENABLED) 840 set->key_info = cpu_to_le16(KEY_ENABLED); 841 else 842 set->key_info = cpu_to_le16(!KEY_ENABLED); 843 844 set->key[0] = enc_key->key_index; 845 if (!priv->sec_info.wapi_key_on) 846 set->key[1] = 1; 847 else 848 /* set 0 when re-key */ 849 set->key[1] = 0; 850 851 if (!is_broadcast_ether_addr(enc_key->mac_addr)) { 852 /* WAPI pairwise key: unicast */ 853 set->key_info |= cpu_to_le16(KEY_UNICAST); 854 } else { /* WAPI group key: multicast */ 855 set->key_info |= cpu_to_le16(KEY_MCAST); 856 priv->sec_info.wapi_key_on = true; 857 } 858 859 set->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL); 860 set->key_len = cpu_to_le16(WAPI_KEY_LEN); 861 memcpy(&set->key[2], enc_key->key_material, enc_key->key_len); 862 memcpy(&set->key[2 + enc_key->key_len], enc_key->pn, PN_LEN); 863 set->length = cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN); 864 865 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) + 866 sizeof(struct mwifiex_ie_types_header); 867 cmd->size = cpu_to_le16(sizeof(key_material->action) 868 + S_DS_GEN + key_param_len); 869 return ret; 870 } 871 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) { 872 if (enc_key->is_igtk_key) { 873 mwifiex_dbg(priv->adapter, CMD, "cmd: CMAC_AES\n"); 874 key_material->key_param_set.key_type_id = 875 cpu_to_le16(KEY_TYPE_ID_AES_CMAC); 876 if (cmd_oid == KEY_INFO_ENABLED) 877 key_material->key_param_set.key_info = 878 cpu_to_le16(KEY_ENABLED); 879 else 880 key_material->key_param_set.key_info = 881 cpu_to_le16(!KEY_ENABLED); 882 883 key_material->key_param_set.key_info |= 884 cpu_to_le16(KEY_IGTK); 885 } else { 886 mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_AES\n"); 887 key_material->key_param_set.key_type_id = 888 cpu_to_le16(KEY_TYPE_ID_AES); 889 if (cmd_oid == KEY_INFO_ENABLED) 890 key_material->key_param_set.key_info = 891 cpu_to_le16(KEY_ENABLED); 892 else 893 key_material->key_param_set.key_info = 894 cpu_to_le16(!KEY_ENABLED); 895 896 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST) 897 /* AES pairwise key: unicast */ 898 key_material->key_param_set.key_info |= 899 cpu_to_le16(KEY_UNICAST); 900 else /* AES group key: multicast */ 901 key_material->key_param_set.key_info |= 902 cpu_to_le16(KEY_MCAST); 903 } 904 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) { 905 mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_TKIP\n"); 906 key_material->key_param_set.key_type_id = 907 cpu_to_le16(KEY_TYPE_ID_TKIP); 908 key_material->key_param_set.key_info = 909 cpu_to_le16(KEY_ENABLED); 910 911 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST) 912 /* TKIP pairwise key: unicast */ 913 key_material->key_param_set.key_info |= 914 cpu_to_le16(KEY_UNICAST); 915 else /* TKIP group key: multicast */ 916 key_material->key_param_set.key_info |= 917 cpu_to_le16(KEY_MCAST); 918 } 919 920 if (key_material->key_param_set.key_type_id) { 921 key_material->key_param_set.type = 922 cpu_to_le16(TLV_TYPE_KEY_MATERIAL); 923 key_material->key_param_set.key_len = 924 cpu_to_le16((u16) enc_key->key_len); 925 memcpy(key_material->key_param_set.key, enc_key->key_material, 926 enc_key->key_len); 927 key_material->key_param_set.length = 928 cpu_to_le16((u16) enc_key->key_len + 929 KEYPARAMSET_FIXED_LEN); 930 931 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN) 932 + sizeof(struct mwifiex_ie_types_header); 933 934 if (le16_to_cpu(key_material->key_param_set.key_type_id) == 935 KEY_TYPE_ID_AES_CMAC) { 936 struct mwifiex_cmac_param *param = 937 (void *)key_material->key_param_set.key; 938 939 memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN); 940 memcpy(param->key, enc_key->key_material, 941 WLAN_KEY_LEN_AES_CMAC); 942 943 key_param_len = sizeof(struct mwifiex_cmac_param); 944 key_material->key_param_set.key_len = 945 cpu_to_le16(key_param_len); 946 key_param_len += KEYPARAMSET_FIXED_LEN; 947 key_material->key_param_set.length = 948 cpu_to_le16(key_param_len); 949 key_param_len += sizeof(struct mwifiex_ie_types_header); 950 } 951 952 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN 953 + key_param_len); 954 955 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { 956 tlv_mac = (void *)((u8 *)&key_material->key_param_set + 957 key_param_len); 958 tlv_mac->header.type = 959 cpu_to_le16(TLV_TYPE_STA_MAC_ADDR); 960 tlv_mac->header.len = cpu_to_le16(ETH_ALEN); 961 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN); 962 cmd_size = key_param_len + S_DS_GEN + 963 sizeof(key_material->action) + 964 sizeof(struct host_cmd_tlv_mac_addr); 965 } else { 966 cmd_size = key_param_len + S_DS_GEN + 967 sizeof(key_material->action); 968 } 969 cmd->size = cpu_to_le16(cmd_size); 970 } 971 972 return ret; 973 } 974 975 /* Wrapper function for setting network key depending upon FW KEY API version */ 976 static int 977 mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv, 978 struct host_cmd_ds_command *cmd, 979 u16 cmd_action, u32 cmd_oid, 980 struct mwifiex_ds_encrypt_key *enc_key) 981 { 982 if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2) 983 return mwifiex_cmd_802_11_key_material_v2(priv, cmd, 984 cmd_action, cmd_oid, 985 enc_key); 986 987 else 988 return mwifiex_cmd_802_11_key_material_v1(priv, cmd, 989 cmd_action, cmd_oid, 990 enc_key); 991 } 992 993 /* 994 * This function prepares command to set/get 11d domain information. 995 * 996 * Preparation includes - 997 * - Setting command ID, action and proper size 998 * - Setting domain information fields (for SET only) 999 * - Ensuring correct endian-ness 1000 */ 1001 static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv, 1002 struct host_cmd_ds_command *cmd, 1003 u16 cmd_action) 1004 { 1005 struct mwifiex_adapter *adapter = priv->adapter; 1006 struct host_cmd_ds_802_11d_domain_info *domain_info = 1007 &cmd->params.domain_info; 1008 struct mwifiex_ietypes_domain_param_set *domain = 1009 &domain_info->domain; 1010 u8 no_of_triplet = adapter->domain_reg.no_of_triplet; 1011 1012 mwifiex_dbg(adapter, INFO, 1013 "info: 11D: no_of_triplet=0x%x\n", no_of_triplet); 1014 1015 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO); 1016 domain_info->action = cpu_to_le16(cmd_action); 1017 if (cmd_action == HostCmd_ACT_GEN_GET) { 1018 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN); 1019 return 0; 1020 } 1021 1022 /* Set domain info fields */ 1023 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY); 1024 memcpy(domain->country_code, adapter->domain_reg.country_code, 1025 sizeof(domain->country_code)); 1026 1027 domain->header.len = 1028 cpu_to_le16((no_of_triplet * 1029 sizeof(struct ieee80211_country_ie_triplet)) 1030 + sizeof(domain->country_code)); 1031 1032 if (no_of_triplet) { 1033 memcpy(domain->triplet, adapter->domain_reg.triplet, 1034 no_of_triplet * sizeof(struct 1035 ieee80211_country_ie_triplet)); 1036 1037 cmd->size = cpu_to_le16(sizeof(domain_info->action) + 1038 le16_to_cpu(domain->header.len) + 1039 sizeof(struct mwifiex_ie_types_header) 1040 + S_DS_GEN); 1041 } else { 1042 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN); 1043 } 1044 1045 return 0; 1046 } 1047 1048 /* 1049 * This function prepares command to set/get IBSS coalescing status. 1050 * 1051 * Preparation includes - 1052 * - Setting command ID, action and proper size 1053 * - Setting status to enable or disable (for SET only) 1054 * - Ensuring correct endian-ness 1055 */ 1056 static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd, 1057 u16 cmd_action, u16 *enable) 1058 { 1059 struct host_cmd_ds_802_11_ibss_status *ibss_coal = 1060 &(cmd->params.ibss_coalescing); 1061 1062 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS); 1063 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) + 1064 S_DS_GEN); 1065 cmd->result = 0; 1066 ibss_coal->action = cpu_to_le16(cmd_action); 1067 1068 switch (cmd_action) { 1069 case HostCmd_ACT_GEN_SET: 1070 if (enable) 1071 ibss_coal->enable = cpu_to_le16(*enable); 1072 else 1073 ibss_coal->enable = 0; 1074 break; 1075 1076 /* In other case.. Nothing to do */ 1077 case HostCmd_ACT_GEN_GET: 1078 default: 1079 break; 1080 } 1081 1082 return 0; 1083 } 1084 1085 /* This function prepares command buffer to get/set memory location value. 1086 */ 1087 static int 1088 mwifiex_cmd_mem_access(struct host_cmd_ds_command *cmd, u16 cmd_action, 1089 void *pdata_buf) 1090 { 1091 struct mwifiex_ds_mem_rw *mem_rw = (void *)pdata_buf; 1092 struct host_cmd_ds_mem_access *mem_access = (void *)&cmd->params.mem; 1093 1094 cmd->command = cpu_to_le16(HostCmd_CMD_MEM_ACCESS); 1095 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mem_access) + 1096 S_DS_GEN); 1097 1098 mem_access->action = cpu_to_le16(cmd_action); 1099 mem_access->addr = cpu_to_le32(mem_rw->addr); 1100 mem_access->value = cpu_to_le32(mem_rw->value); 1101 1102 return 0; 1103 } 1104 1105 /* 1106 * This function prepares command to set/get register value. 1107 * 1108 * Preparation includes - 1109 * - Setting command ID, action and proper size 1110 * - Setting register offset (for both GET and SET) and 1111 * register value (for SET only) 1112 * - Ensuring correct endian-ness 1113 * 1114 * The following type of registers can be accessed with this function - 1115 * - MAC register 1116 * - BBP register 1117 * - RF register 1118 * - PMIC register 1119 * - CAU register 1120 * - EEPROM 1121 */ 1122 static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd, 1123 u16 cmd_action, void *data_buf) 1124 { 1125 struct mwifiex_ds_reg_rw *reg_rw = data_buf; 1126 1127 switch (le16_to_cpu(cmd->command)) { 1128 case HostCmd_CMD_MAC_REG_ACCESS: 1129 { 1130 struct host_cmd_ds_mac_reg_access *mac_reg; 1131 1132 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN); 1133 mac_reg = &cmd->params.mac_reg; 1134 mac_reg->action = cpu_to_le16(cmd_action); 1135 mac_reg->offset = cpu_to_le16((u16) reg_rw->offset); 1136 mac_reg->value = cpu_to_le32(reg_rw->value); 1137 break; 1138 } 1139 case HostCmd_CMD_BBP_REG_ACCESS: 1140 { 1141 struct host_cmd_ds_bbp_reg_access *bbp_reg; 1142 1143 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN); 1144 bbp_reg = &cmd->params.bbp_reg; 1145 bbp_reg->action = cpu_to_le16(cmd_action); 1146 bbp_reg->offset = cpu_to_le16((u16) reg_rw->offset); 1147 bbp_reg->value = (u8) reg_rw->value; 1148 break; 1149 } 1150 case HostCmd_CMD_RF_REG_ACCESS: 1151 { 1152 struct host_cmd_ds_rf_reg_access *rf_reg; 1153 1154 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN); 1155 rf_reg = &cmd->params.rf_reg; 1156 rf_reg->action = cpu_to_le16(cmd_action); 1157 rf_reg->offset = cpu_to_le16((u16) reg_rw->offset); 1158 rf_reg->value = (u8) reg_rw->value; 1159 break; 1160 } 1161 case HostCmd_CMD_PMIC_REG_ACCESS: 1162 { 1163 struct host_cmd_ds_pmic_reg_access *pmic_reg; 1164 1165 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN); 1166 pmic_reg = &cmd->params.pmic_reg; 1167 pmic_reg->action = cpu_to_le16(cmd_action); 1168 pmic_reg->offset = cpu_to_le16((u16) reg_rw->offset); 1169 pmic_reg->value = (u8) reg_rw->value; 1170 break; 1171 } 1172 case HostCmd_CMD_CAU_REG_ACCESS: 1173 { 1174 struct host_cmd_ds_rf_reg_access *cau_reg; 1175 1176 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN); 1177 cau_reg = &cmd->params.rf_reg; 1178 cau_reg->action = cpu_to_le16(cmd_action); 1179 cau_reg->offset = cpu_to_le16((u16) reg_rw->offset); 1180 cau_reg->value = (u8) reg_rw->value; 1181 break; 1182 } 1183 case HostCmd_CMD_802_11_EEPROM_ACCESS: 1184 { 1185 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf; 1186 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom = 1187 &cmd->params.eeprom; 1188 1189 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN); 1190 cmd_eeprom->action = cpu_to_le16(cmd_action); 1191 cmd_eeprom->offset = cpu_to_le16(rd_eeprom->offset); 1192 cmd_eeprom->byte_count = cpu_to_le16(rd_eeprom->byte_count); 1193 cmd_eeprom->value = 0; 1194 break; 1195 } 1196 default: 1197 return -1; 1198 } 1199 1200 return 0; 1201 } 1202 1203 /* 1204 * This function prepares command to set PCI-Express 1205 * host buffer configuration 1206 * 1207 * Preparation includes - 1208 * - Setting command ID, action and proper size 1209 * - Setting host buffer configuration 1210 * - Ensuring correct endian-ness 1211 */ 1212 static int 1213 mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv, 1214 struct host_cmd_ds_command *cmd, u16 action) 1215 { 1216 struct host_cmd_ds_pcie_details *host_spec = 1217 &cmd->params.pcie_host_spec; 1218 struct pcie_service_card *card = priv->adapter->card; 1219 1220 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS); 1221 cmd->size = cpu_to_le16(sizeof(struct 1222 host_cmd_ds_pcie_details) + S_DS_GEN); 1223 cmd->result = 0; 1224 1225 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details)); 1226 1227 if (action != HostCmd_ACT_GEN_SET) 1228 return 0; 1229 1230 /* Send the ring base addresses and count to firmware */ 1231 host_spec->txbd_addr_lo = cpu_to_le32((u32)(card->txbd_ring_pbase)); 1232 host_spec->txbd_addr_hi = 1233 cpu_to_le32((u32)(((u64)card->txbd_ring_pbase) >> 32)); 1234 host_spec->txbd_count = cpu_to_le32(MWIFIEX_MAX_TXRX_BD); 1235 host_spec->rxbd_addr_lo = cpu_to_le32((u32)(card->rxbd_ring_pbase)); 1236 host_spec->rxbd_addr_hi = 1237 cpu_to_le32((u32)(((u64)card->rxbd_ring_pbase) >> 32)); 1238 host_spec->rxbd_count = cpu_to_le32(MWIFIEX_MAX_TXRX_BD); 1239 host_spec->evtbd_addr_lo = cpu_to_le32((u32)(card->evtbd_ring_pbase)); 1240 host_spec->evtbd_addr_hi = 1241 cpu_to_le32((u32)(((u64)card->evtbd_ring_pbase) >> 32)); 1242 host_spec->evtbd_count = cpu_to_le32(MWIFIEX_MAX_EVT_BD); 1243 if (card->sleep_cookie_vbase) { 1244 host_spec->sleep_cookie_addr_lo = 1245 cpu_to_le32((u32)(card->sleep_cookie_pbase)); 1246 host_spec->sleep_cookie_addr_hi = cpu_to_le32((u32)(((u64) 1247 (card->sleep_cookie_pbase)) >> 32)); 1248 mwifiex_dbg(priv->adapter, INFO, 1249 "sleep_cook_lo phy addr: 0x%x\n", 1250 host_spec->sleep_cookie_addr_lo); 1251 } 1252 1253 return 0; 1254 } 1255 1256 /* 1257 * This function prepares command for event subscription, configuration 1258 * and query. Events can be subscribed or unsubscribed. Current subscribed 1259 * events can be queried. Also, current subscribed events are reported in 1260 * every FW response. 1261 */ 1262 static int 1263 mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv, 1264 struct host_cmd_ds_command *cmd, 1265 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg) 1266 { 1267 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt; 1268 struct mwifiex_ie_types_rssi_threshold *rssi_tlv; 1269 u16 event_bitmap; 1270 u8 *pos; 1271 1272 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT); 1273 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) + 1274 S_DS_GEN); 1275 1276 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action); 1277 mwifiex_dbg(priv->adapter, CMD, 1278 "cmd: action: %d\n", subsc_evt_cfg->action); 1279 1280 /*For query requests, no configuration TLV structures are to be added.*/ 1281 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET) 1282 return 0; 1283 1284 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events); 1285 1286 event_bitmap = subsc_evt_cfg->events; 1287 mwifiex_dbg(priv->adapter, CMD, "cmd: event bitmap : %16x\n", 1288 event_bitmap); 1289 1290 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) || 1291 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) && 1292 (event_bitmap == 0)) { 1293 mwifiex_dbg(priv->adapter, ERROR, 1294 "Error: No event specified\t" 1295 "for bitwise action type\n"); 1296 return -EINVAL; 1297 } 1298 1299 /* 1300 * Append TLV structures for each of the specified events for 1301 * subscribing or re-configuring. This is not required for 1302 * bitwise unsubscribing request. 1303 */ 1304 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) 1305 return 0; 1306 1307 pos = ((u8 *)subsc_evt) + 1308 sizeof(struct host_cmd_ds_802_11_subsc_evt); 1309 1310 if (event_bitmap & BITMASK_BCN_RSSI_LOW) { 1311 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos; 1312 1313 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW); 1314 rssi_tlv->header.len = 1315 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) - 1316 sizeof(struct mwifiex_ie_types_header)); 1317 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value; 1318 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq; 1319 1320 mwifiex_dbg(priv->adapter, EVENT, 1321 "Cfg Beacon Low Rssi event,\t" 1322 "RSSI:-%d dBm, Freq:%d\n", 1323 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value, 1324 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq); 1325 1326 pos += sizeof(struct mwifiex_ie_types_rssi_threshold); 1327 le16_unaligned_add_cpu(&cmd->size, 1328 sizeof( 1329 struct mwifiex_ie_types_rssi_threshold)); 1330 } 1331 1332 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) { 1333 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos; 1334 1335 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH); 1336 rssi_tlv->header.len = 1337 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) - 1338 sizeof(struct mwifiex_ie_types_header)); 1339 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value; 1340 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq; 1341 1342 mwifiex_dbg(priv->adapter, EVENT, 1343 "Cfg Beacon High Rssi event,\t" 1344 "RSSI:-%d dBm, Freq:%d\n", 1345 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value, 1346 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq); 1347 1348 pos += sizeof(struct mwifiex_ie_types_rssi_threshold); 1349 le16_unaligned_add_cpu(&cmd->size, 1350 sizeof( 1351 struct mwifiex_ie_types_rssi_threshold)); 1352 } 1353 1354 return 0; 1355 } 1356 1357 static int 1358 mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv, 1359 struct mwifiex_mef_entry *mef_entry, 1360 u8 **buffer) 1361 { 1362 struct mwifiex_mef_filter *filter = mef_entry->filter; 1363 int i, byte_len; 1364 u8 *stack_ptr = *buffer; 1365 1366 for (i = 0; i < MWIFIEX_MEF_MAX_FILTERS; i++) { 1367 filter = &mef_entry->filter[i]; 1368 if (!filter->filt_type) 1369 break; 1370 put_unaligned_le32((u32)filter->repeat, stack_ptr); 1371 stack_ptr += 4; 1372 *stack_ptr = TYPE_DNUM; 1373 stack_ptr += 1; 1374 1375 byte_len = filter->byte_seq[MWIFIEX_MEF_MAX_BYTESEQ]; 1376 memcpy(stack_ptr, filter->byte_seq, byte_len); 1377 stack_ptr += byte_len; 1378 *stack_ptr = byte_len; 1379 stack_ptr += 1; 1380 *stack_ptr = TYPE_BYTESEQ; 1381 stack_ptr += 1; 1382 put_unaligned_le32((u32)filter->offset, stack_ptr); 1383 stack_ptr += 4; 1384 *stack_ptr = TYPE_DNUM; 1385 stack_ptr += 1; 1386 1387 *stack_ptr = filter->filt_type; 1388 stack_ptr += 1; 1389 1390 if (filter->filt_action) { 1391 *stack_ptr = filter->filt_action; 1392 stack_ptr += 1; 1393 } 1394 1395 if (stack_ptr - *buffer > STACK_NBYTES) 1396 return -1; 1397 } 1398 1399 *buffer = stack_ptr; 1400 return 0; 1401 } 1402 1403 static int 1404 mwifiex_cmd_mef_cfg(struct mwifiex_private *priv, 1405 struct host_cmd_ds_command *cmd, 1406 struct mwifiex_ds_mef_cfg *mef) 1407 { 1408 struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg; 1409 struct mwifiex_fw_mef_entry *mef_entry = NULL; 1410 u8 *pos = (u8 *)mef_cfg; 1411 u16 i; 1412 1413 cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG); 1414 1415 mef_cfg->criteria = cpu_to_le32(mef->criteria); 1416 mef_cfg->num_entries = cpu_to_le16(mef->num_entries); 1417 pos += sizeof(*mef_cfg); 1418 1419 for (i = 0; i < mef->num_entries; i++) { 1420 mef_entry = (struct mwifiex_fw_mef_entry *)pos; 1421 mef_entry->mode = mef->mef_entry[i].mode; 1422 mef_entry->action = mef->mef_entry[i].action; 1423 pos += sizeof(*mef_entry); 1424 1425 if (mwifiex_cmd_append_rpn_expression(priv, 1426 &mef->mef_entry[i], &pos)) 1427 return -1; 1428 1429 mef_entry->exprsize = 1430 cpu_to_le16(pos - mef_entry->expr); 1431 } 1432 cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN); 1433 1434 return 0; 1435 } 1436 1437 /* This function parse cal data from ASCII to hex */ 1438 static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst) 1439 { 1440 u8 *s = src, *d = dst; 1441 1442 while (s - src < len) { 1443 if (*s && (isspace(*s) || *s == '\t')) { 1444 s++; 1445 continue; 1446 } 1447 if (isxdigit(*s)) { 1448 *d++ = simple_strtol(s, NULL, 16); 1449 s += 2; 1450 } else { 1451 s++; 1452 } 1453 } 1454 1455 return d - dst; 1456 } 1457 1458 int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv, 1459 struct device_node *node, const char *prefix) 1460 { 1461 #ifdef CONFIG_OF 1462 struct property *prop; 1463 size_t len = strlen(prefix); 1464 int ret; 1465 1466 /* look for all matching property names */ 1467 for_each_property_of_node(node, prop) { 1468 if (len > strlen(prop->name) || 1469 strncmp(prop->name, prefix, len)) 1470 continue; 1471 1472 /* property header is 6 bytes, data must fit in cmd buffer */ 1473 if (prop->value && prop->length > 6 && 1474 prop->length <= MWIFIEX_SIZE_OF_CMD_BUFFER - S_DS_GEN) { 1475 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA, 1476 HostCmd_ACT_GEN_SET, 0, 1477 prop, true); 1478 if (ret) 1479 return ret; 1480 } 1481 } 1482 #endif 1483 return 0; 1484 } 1485 1486 static int mwifiex_rgpower_table_advance_to_content(u8 **pos, const u8 *data, 1487 const size_t size) 1488 { 1489 while (*pos - data < size) { 1490 /* skip spaces, tabs and empty lines */ 1491 if (**pos == '\r' || **pos == '\n' || **pos == '\0' || 1492 isspace(**pos)) { 1493 (*pos)++; 1494 continue; 1495 } 1496 /* skip line comments */ 1497 if (**pos == '#') { 1498 *pos = strchr(*pos, '\n'); 1499 if (!*pos) 1500 return -EINVAL; 1501 (*pos)++; 1502 continue; 1503 } 1504 return 0; 1505 } 1506 return 0; 1507 } 1508 1509 int mwifiex_send_rgpower_table(struct mwifiex_private *priv, const u8 *data, 1510 const size_t size) 1511 { 1512 int ret = 0; 1513 bool start_raw = false; 1514 u8 *ptr, *token, *pos = NULL; 1515 u8 *_data __free(kfree) = NULL; 1516 struct mwifiex_adapter *adapter = priv->adapter; 1517 struct mwifiex_ds_misc_cmd *hostcmd __free(kfree) = NULL; 1518 1519 hostcmd = kzalloc_obj(*hostcmd); 1520 if (!hostcmd) 1521 return -ENOMEM; 1522 1523 _data = kmemdup(data, size, GFP_KERNEL); 1524 if (!_data) 1525 return -ENOMEM; 1526 1527 pos = _data; 1528 ptr = hostcmd->cmd; 1529 while ((pos - _data) < size) { 1530 ret = mwifiex_rgpower_table_advance_to_content(&pos, _data, size); 1531 if (ret) { 1532 mwifiex_dbg( 1533 adapter, ERROR, 1534 "%s: failed to advance to content in rgpower table\n", 1535 __func__); 1536 return ret; 1537 } 1538 1539 if (*pos == '}' && start_raw) { 1540 hostcmd->len = get_unaligned_le16(&hostcmd->cmd[2]); 1541 ret = mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, false); 1542 if (ret) { 1543 mwifiex_dbg(adapter, ERROR, 1544 "%s: failed to send hostcmd %d\n", 1545 __func__, ret); 1546 return ret; 1547 } 1548 1549 memset(hostcmd->cmd, 0, MWIFIEX_SIZE_OF_CMD_BUFFER); 1550 ptr = hostcmd->cmd; 1551 start_raw = false; 1552 pos++; 1553 continue; 1554 } 1555 1556 if (!start_raw) { 1557 pos = strchr(pos, '='); 1558 if (pos) { 1559 pos = strchr(pos, '{'); 1560 if (pos) { 1561 start_raw = true; 1562 pos++; 1563 continue; 1564 } 1565 } 1566 mwifiex_dbg(adapter, ERROR, 1567 "%s: syntax error in hostcmd\n", __func__); 1568 return -EINVAL; 1569 } 1570 1571 while ((*pos != '\r' && *pos != '\n') && 1572 (token = strsep((char **)&pos, " "))) { 1573 if (ptr - hostcmd->cmd >= MWIFIEX_SIZE_OF_CMD_BUFFER) { 1574 mwifiex_dbg(adapter, ERROR, 1575 "%s: hostcmd is larger than %d, aborting\n", 1576 __func__, MWIFIEX_SIZE_OF_CMD_BUFFER); 1577 return -ENOMEM; 1578 } 1579 1580 ret = kstrtou8(token, 16, ptr); 1581 if (ret < 0) { 1582 mwifiex_dbg(adapter, ERROR, 1583 "%s: failed to parse hostcmd %d token: %s\n", 1584 __func__, ret, token); 1585 return ret; 1586 } 1587 ptr++; 1588 } 1589 } 1590 1591 return ret; 1592 } 1593 1594 /* This function prepares command of set_cfg_data. */ 1595 static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv, 1596 struct host_cmd_ds_command *cmd, void *data_buf) 1597 { 1598 struct mwifiex_adapter *adapter = priv->adapter; 1599 struct property *prop = data_buf; 1600 u32 len; 1601 u8 *data = (u8 *)cmd + S_DS_GEN; 1602 int ret; 1603 struct host_cmd_ds_802_11_cfg_data *pcfg_data; 1604 1605 if (prop) { 1606 len = prop->length; 1607 ret = of_property_read_u8_array(adapter->dt_node, prop->name, 1608 data, len); 1609 if (ret) 1610 return ret; 1611 1612 cmd->size = cpu_to_le16(S_DS_GEN + len); 1613 mwifiex_dbg(adapter, INFO, 1614 "download cfg_data from device tree: %s\n", 1615 prop->name); 1616 } else if (adapter->cal_data->data && adapter->cal_data->size > 0) { 1617 len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data, 1618 adapter->cal_data->size, 1619 data + sizeof(*pcfg_data)); 1620 pcfg_data = &cmd->params.cfg_data; 1621 pcfg_data->action = cpu_to_le16(HOST_CMD_ACT_GEN_SET); 1622 pcfg_data->type = cpu_to_le16(MWIFIEX_CFG_TYPE_CAL); 1623 pcfg_data->data_len = cpu_to_le16(len); 1624 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(*pcfg_data) + len); 1625 mwifiex_dbg(adapter, INFO, 1626 "download cfg_data from config file\n"); 1627 } else { 1628 return -1; 1629 } 1630 1631 cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA); 1632 1633 return 0; 1634 } 1635 1636 static int 1637 mwifiex_cmd_set_mc_policy(struct mwifiex_private *priv, 1638 struct host_cmd_ds_command *cmd, 1639 u16 cmd_action, void *data_buf) 1640 { 1641 struct host_cmd_ds_multi_chan_policy *mc_pol = &cmd->params.mc_policy; 1642 const u16 *drcs_info = data_buf; 1643 1644 mc_pol->action = cpu_to_le16(cmd_action); 1645 mc_pol->policy = cpu_to_le16(*drcs_info); 1646 cmd->command = cpu_to_le16(HostCmd_CMD_MC_POLICY); 1647 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_multi_chan_policy) + 1648 S_DS_GEN); 1649 return 0; 1650 } 1651 1652 static int mwifiex_cmd_robust_coex(struct mwifiex_private *priv, 1653 struct host_cmd_ds_command *cmd, 1654 u16 cmd_action, bool *is_timeshare) 1655 { 1656 struct host_cmd_ds_robust_coex *coex = &cmd->params.coex; 1657 struct mwifiex_ie_types_robust_coex *coex_tlv; 1658 1659 cmd->command = cpu_to_le16(HostCmd_CMD_ROBUST_COEX); 1660 cmd->size = cpu_to_le16(sizeof(*coex) + sizeof(*coex_tlv) + S_DS_GEN); 1661 1662 coex->action = cpu_to_le16(cmd_action); 1663 coex_tlv = (struct mwifiex_ie_types_robust_coex *) 1664 ((u8 *)coex + sizeof(*coex)); 1665 coex_tlv->header.type = cpu_to_le16(TLV_TYPE_ROBUST_COEX); 1666 coex_tlv->header.len = cpu_to_le16(sizeof(coex_tlv->mode)); 1667 1668 if (coex->action == HostCmd_ACT_GEN_GET) 1669 return 0; 1670 1671 if (*is_timeshare) 1672 coex_tlv->mode = cpu_to_le32(MWIFIEX_COEX_MODE_TIMESHARE); 1673 else 1674 coex_tlv->mode = cpu_to_le32(MWIFIEX_COEX_MODE_SPATIAL); 1675 1676 return 0; 1677 } 1678 1679 static int mwifiex_cmd_gtk_rekey_offload(struct mwifiex_private *priv, 1680 struct host_cmd_ds_command *cmd, 1681 u16 cmd_action, 1682 struct cfg80211_gtk_rekey_data *data) 1683 { 1684 struct host_cmd_ds_gtk_rekey_params *rekey = &cmd->params.rekey; 1685 u64 rekey_ctr; 1686 1687 cmd->command = cpu_to_le16(HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG); 1688 cmd->size = cpu_to_le16(sizeof(*rekey) + S_DS_GEN); 1689 1690 rekey->action = cpu_to_le16(cmd_action); 1691 if (cmd_action == HostCmd_ACT_GEN_SET) { 1692 memcpy(rekey->kek, data->kek, NL80211_KEK_LEN); 1693 memcpy(rekey->kck, data->kck, NL80211_KCK_LEN); 1694 rekey_ctr = be64_to_cpup((__be64 *)data->replay_ctr); 1695 rekey->replay_ctr_low = cpu_to_le32((u32)rekey_ctr); 1696 rekey->replay_ctr_high = 1697 cpu_to_le32((u32)((u64)rekey_ctr >> 32)); 1698 } 1699 1700 return 0; 1701 } 1702 1703 static int mwifiex_cmd_chan_region_cfg(struct mwifiex_private *priv, 1704 struct host_cmd_ds_command *cmd, 1705 u16 cmd_action) 1706 { 1707 struct host_cmd_ds_chan_region_cfg *reg = &cmd->params.reg_cfg; 1708 1709 cmd->command = cpu_to_le16(HostCmd_CMD_CHAN_REGION_CFG); 1710 cmd->size = cpu_to_le16(sizeof(*reg) + S_DS_GEN); 1711 1712 if (cmd_action == HostCmd_ACT_GEN_GET) 1713 reg->action = cpu_to_le16(cmd_action); 1714 1715 return 0; 1716 } 1717 1718 static int 1719 mwifiex_cmd_coalesce_cfg(struct mwifiex_private *priv, 1720 struct host_cmd_ds_command *cmd, 1721 u16 cmd_action, void *data_buf) 1722 { 1723 struct host_cmd_ds_coalesce_cfg *coalesce_cfg = 1724 &cmd->params.coalesce_cfg; 1725 struct mwifiex_ds_coalesce_cfg *cfg = data_buf; 1726 struct coalesce_filt_field_param *param; 1727 u16 cnt, idx, length; 1728 struct coalesce_receive_filt_rule *rule; 1729 1730 cmd->command = cpu_to_le16(HostCmd_CMD_COALESCE_CFG); 1731 cmd->size = cpu_to_le16(S_DS_GEN); 1732 1733 coalesce_cfg->action = cpu_to_le16(cmd_action); 1734 coalesce_cfg->num_of_rules = cpu_to_le16(cfg->num_of_rules); 1735 rule = (void *)coalesce_cfg->rule_data; 1736 1737 for (cnt = 0; cnt < cfg->num_of_rules; cnt++) { 1738 rule->header.type = cpu_to_le16(TLV_TYPE_COALESCE_RULE); 1739 rule->max_coalescing_delay = 1740 cpu_to_le16(cfg->rule[cnt].max_coalescing_delay); 1741 rule->pkt_type = cfg->rule[cnt].pkt_type; 1742 rule->num_of_fields = cfg->rule[cnt].num_of_fields; 1743 1744 length = 0; 1745 1746 param = rule->params; 1747 for (idx = 0; idx < cfg->rule[cnt].num_of_fields; idx++) { 1748 param->operation = cfg->rule[cnt].params[idx].operation; 1749 param->operand_len = 1750 cfg->rule[cnt].params[idx].operand_len; 1751 param->offset = 1752 cpu_to_le16(cfg->rule[cnt].params[idx].offset); 1753 memcpy(param->operand_byte_stream, 1754 cfg->rule[cnt].params[idx].operand_byte_stream, 1755 param->operand_len); 1756 1757 length += sizeof(struct coalesce_filt_field_param); 1758 1759 param++; 1760 } 1761 1762 /* Total rule length is sizeof max_coalescing_delay(u16), 1763 * num_of_fields(u8), pkt_type(u8) and total length of the all 1764 * params 1765 */ 1766 rule->header.len = cpu_to_le16(length + sizeof(u16) + 1767 sizeof(u8) + sizeof(u8)); 1768 1769 /* Add the rule length to the command size*/ 1770 le16_unaligned_add_cpu(&cmd->size, 1771 le16_to_cpu(rule->header.len) + 1772 sizeof(struct mwifiex_ie_types_header)); 1773 1774 rule = (void *)((u8 *)rule->params + length); 1775 } 1776 1777 /* Add sizeof action, num_of_rules to total command length */ 1778 le16_unaligned_add_cpu(&cmd->size, sizeof(u16) + sizeof(u16)); 1779 1780 return 0; 1781 } 1782 1783 static int 1784 mwifiex_cmd_tdls_config(struct mwifiex_private *priv, 1785 struct host_cmd_ds_command *cmd, 1786 u16 cmd_action, void *data_buf) 1787 { 1788 struct host_cmd_ds_tdls_config *tdls_config = &cmd->params.tdls_config; 1789 struct mwifiex_tdls_init_cs_params *config; 1790 struct mwifiex_tdls_config *init_config; 1791 u16 len; 1792 1793 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_CONFIG); 1794 cmd->size = cpu_to_le16(S_DS_GEN); 1795 tdls_config->tdls_action = cpu_to_le16(cmd_action); 1796 le16_unaligned_add_cpu(&cmd->size, sizeof(tdls_config->tdls_action)); 1797 1798 switch (cmd_action) { 1799 case ACT_TDLS_CS_ENABLE_CONFIG: 1800 init_config = data_buf; 1801 len = sizeof(*init_config); 1802 memcpy(tdls_config->tdls_data, init_config, len); 1803 break; 1804 case ACT_TDLS_CS_INIT: 1805 config = data_buf; 1806 len = sizeof(*config); 1807 memcpy(tdls_config->tdls_data, config, len); 1808 break; 1809 case ACT_TDLS_CS_STOP: 1810 len = sizeof(struct mwifiex_tdls_stop_cs_params); 1811 memcpy(tdls_config->tdls_data, data_buf, len); 1812 break; 1813 case ACT_TDLS_CS_PARAMS: 1814 len = sizeof(struct mwifiex_tdls_config_cs_params); 1815 memcpy(tdls_config->tdls_data, data_buf, len); 1816 break; 1817 default: 1818 mwifiex_dbg(priv->adapter, ERROR, 1819 "Unknown TDLS configuration\n"); 1820 return -EOPNOTSUPP; 1821 } 1822 1823 le16_unaligned_add_cpu(&cmd->size, len); 1824 return 0; 1825 } 1826 1827 static int 1828 mwifiex_cmd_tdls_oper(struct mwifiex_private *priv, 1829 struct host_cmd_ds_command *cmd, 1830 void *data_buf) 1831 { 1832 struct host_cmd_ds_tdls_oper *tdls_oper = &cmd->params.tdls_oper; 1833 struct mwifiex_ds_tdls_oper *oper = data_buf; 1834 struct host_cmd_tlv_rates *tlv_rates; 1835 struct mwifiex_ie_types_htcap *ht_capab; 1836 struct mwifiex_ie_types_qos_info *wmm_qos_info; 1837 struct mwifiex_ie_types_extcap *extcap; 1838 struct mwifiex_ie_types_vhtcap *vht_capab; 1839 struct mwifiex_ie_types_aid *aid; 1840 struct mwifiex_ie_types_tdls_idle_timeout *timeout; 1841 u8 *pos; 1842 u16 config_len = 0; 1843 struct station_parameters *params = priv->sta_params; 1844 1845 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_OPER); 1846 cmd->size = cpu_to_le16(S_DS_GEN); 1847 le16_unaligned_add_cpu(&cmd->size, 1848 sizeof(struct host_cmd_ds_tdls_oper)); 1849 1850 tdls_oper->reason = 0; 1851 memcpy(tdls_oper->peer_mac, oper->peer_mac, ETH_ALEN); 1852 1853 pos = (u8 *)tdls_oper + sizeof(struct host_cmd_ds_tdls_oper); 1854 1855 switch (oper->tdls_action) { 1856 case MWIFIEX_TDLS_DISABLE_LINK: 1857 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_DELETE); 1858 break; 1859 case MWIFIEX_TDLS_CREATE_LINK: 1860 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CREATE); 1861 break; 1862 case MWIFIEX_TDLS_CONFIG_LINK: 1863 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CONFIG); 1864 1865 if (!params) { 1866 mwifiex_dbg(priv->adapter, ERROR, 1867 "TDLS config params not available for %pM\n", 1868 oper->peer_mac); 1869 return -ENODATA; 1870 } 1871 1872 put_unaligned_le16(params->capability, pos); 1873 config_len += sizeof(params->capability); 1874 1875 wmm_qos_info = (void *)(pos + config_len); 1876 wmm_qos_info->header.type = cpu_to_le16(WLAN_EID_QOS_CAPA); 1877 wmm_qos_info->header.len = 1878 cpu_to_le16(sizeof(wmm_qos_info->qos_info)); 1879 wmm_qos_info->qos_info = 0; 1880 config_len += sizeof(struct mwifiex_ie_types_qos_info); 1881 1882 if (params->link_sta_params.ht_capa) { 1883 ht_capab = (struct mwifiex_ie_types_htcap *)(pos + 1884 config_len); 1885 ht_capab->header.type = 1886 cpu_to_le16(WLAN_EID_HT_CAPABILITY); 1887 ht_capab->header.len = 1888 cpu_to_le16(sizeof(struct ieee80211_ht_cap)); 1889 memcpy(&ht_capab->ht_cap, params->link_sta_params.ht_capa, 1890 sizeof(struct ieee80211_ht_cap)); 1891 config_len += sizeof(struct mwifiex_ie_types_htcap); 1892 } 1893 1894 if (params->link_sta_params.supported_rates && 1895 params->link_sta_params.supported_rates_len) { 1896 tlv_rates = (struct host_cmd_tlv_rates *)(pos + 1897 config_len); 1898 tlv_rates->header.type = 1899 cpu_to_le16(WLAN_EID_SUPP_RATES); 1900 tlv_rates->header.len = 1901 cpu_to_le16(params->link_sta_params.supported_rates_len); 1902 memcpy(tlv_rates->rates, 1903 params->link_sta_params.supported_rates, 1904 params->link_sta_params.supported_rates_len); 1905 config_len += sizeof(struct host_cmd_tlv_rates) + 1906 params->link_sta_params.supported_rates_len; 1907 } 1908 1909 if (params->ext_capab && params->ext_capab_len) { 1910 extcap = (struct mwifiex_ie_types_extcap *)(pos + 1911 config_len); 1912 extcap->header.type = 1913 cpu_to_le16(WLAN_EID_EXT_CAPABILITY); 1914 extcap->header.len = cpu_to_le16(params->ext_capab_len); 1915 memcpy(extcap->ext_capab, params->ext_capab, 1916 params->ext_capab_len); 1917 config_len += sizeof(struct mwifiex_ie_types_extcap) + 1918 params->ext_capab_len; 1919 } 1920 if (params->link_sta_params.vht_capa) { 1921 vht_capab = (struct mwifiex_ie_types_vhtcap *)(pos + 1922 config_len); 1923 vht_capab->header.type = 1924 cpu_to_le16(WLAN_EID_VHT_CAPABILITY); 1925 vht_capab->header.len = 1926 cpu_to_le16(sizeof(struct ieee80211_vht_cap)); 1927 memcpy(&vht_capab->vht_cap, params->link_sta_params.vht_capa, 1928 sizeof(struct ieee80211_vht_cap)); 1929 config_len += sizeof(struct mwifiex_ie_types_vhtcap); 1930 } 1931 if (params->aid) { 1932 aid = (struct mwifiex_ie_types_aid *)(pos + config_len); 1933 aid->header.type = cpu_to_le16(WLAN_EID_AID); 1934 aid->header.len = cpu_to_le16(sizeof(params->aid)); 1935 aid->aid = cpu_to_le16(params->aid); 1936 config_len += sizeof(struct mwifiex_ie_types_aid); 1937 } 1938 1939 timeout = (void *)(pos + config_len); 1940 timeout->header.type = cpu_to_le16(TLV_TYPE_TDLS_IDLE_TIMEOUT); 1941 timeout->header.len = cpu_to_le16(sizeof(timeout->value)); 1942 timeout->value = cpu_to_le16(MWIFIEX_TDLS_IDLE_TIMEOUT_IN_SEC); 1943 config_len += sizeof(struct mwifiex_ie_types_tdls_idle_timeout); 1944 1945 break; 1946 default: 1947 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS operation\n"); 1948 return -EOPNOTSUPP; 1949 } 1950 1951 le16_unaligned_add_cpu(&cmd->size, config_len); 1952 1953 return 0; 1954 } 1955 1956 /* This function prepares command of sdio rx aggr info. */ 1957 static int mwifiex_cmd_sdio_rx_aggr_cfg(struct host_cmd_ds_command *cmd, 1958 u16 cmd_action, void *data_buf) 1959 { 1960 struct host_cmd_sdio_sp_rx_aggr_cfg *cfg = 1961 &cmd->params.sdio_rx_aggr_cfg; 1962 1963 cmd->command = cpu_to_le16(HostCmd_CMD_SDIO_SP_RX_AGGR_CFG); 1964 cmd->size = 1965 cpu_to_le16(sizeof(struct host_cmd_sdio_sp_rx_aggr_cfg) + 1966 S_DS_GEN); 1967 cfg->action = cmd_action; 1968 if (cmd_action == HostCmd_ACT_GEN_SET) 1969 cfg->enable = *(u8 *)data_buf; 1970 1971 return 0; 1972 } 1973 1974 /* This function prepares command to get HS wakeup reason. 1975 * 1976 * Preparation includes - 1977 * - Setting command ID, action and proper size 1978 * - Ensuring correct endian-ness 1979 */ 1980 static int mwifiex_cmd_get_wakeup_reason(struct mwifiex_private *priv, 1981 struct host_cmd_ds_command *cmd) 1982 { 1983 cmd->command = cpu_to_le16(HostCmd_CMD_HS_WAKEUP_REASON); 1984 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_wakeup_reason) + 1985 S_DS_GEN); 1986 1987 return 0; 1988 } 1989 1990 static int mwifiex_cmd_get_chan_info(struct host_cmd_ds_command *cmd, 1991 u16 cmd_action) 1992 { 1993 struct host_cmd_ds_sta_configure *sta_cfg_cmd = &cmd->params.sta_cfg; 1994 struct host_cmd_tlv_channel_band *tlv_band_channel = 1995 (struct host_cmd_tlv_channel_band *)sta_cfg_cmd->tlv_buffer; 1996 1997 cmd->command = cpu_to_le16(HostCmd_CMD_STA_CONFIGURE); 1998 cmd->size = cpu_to_le16(sizeof(*sta_cfg_cmd) + 1999 sizeof(*tlv_band_channel) + S_DS_GEN); 2000 sta_cfg_cmd->action = cpu_to_le16(cmd_action); 2001 memset(tlv_band_channel, 0, sizeof(*tlv_band_channel)); 2002 tlv_band_channel->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST); 2003 tlv_band_channel->header.len = cpu_to_le16(sizeof(*tlv_band_channel) - 2004 sizeof(struct mwifiex_ie_types_header)); 2005 2006 return 0; 2007 } 2008 2009 /* This function check if the command is supported by firmware */ 2010 static int mwifiex_is_cmd_supported(struct mwifiex_private *priv, u16 cmd_no) 2011 { 2012 if (!ISSUPP_ADHOC_ENABLED(priv->adapter->fw_cap_info)) { 2013 switch (cmd_no) { 2014 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS: 2015 case HostCmd_CMD_802_11_AD_HOC_START: 2016 case HostCmd_CMD_802_11_AD_HOC_JOIN: 2017 case HostCmd_CMD_802_11_AD_HOC_STOP: 2018 return -EOPNOTSUPP; 2019 default: 2020 break; 2021 } 2022 } 2023 2024 return 0; 2025 } 2026 2027 /* 2028 * This function prepares the commands before sending them to the firmware. 2029 * 2030 * This is a generic function which calls specific command preparation 2031 * routines based upon the command number. 2032 */ 2033 int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no, 2034 u16 cmd_action, u32 cmd_oid, 2035 void *data_buf, void *cmd_buf) 2036 { 2037 struct host_cmd_ds_command *cmd_ptr = cmd_buf; 2038 int ret = 0; 2039 2040 if (mwifiex_is_cmd_supported(priv, cmd_no)) { 2041 mwifiex_dbg(priv->adapter, ERROR, 2042 "0x%x command not supported by firmware\n", 2043 cmd_no); 2044 return -EOPNOTSUPP; 2045 } 2046 2047 /* Prepare command */ 2048 switch (cmd_no) { 2049 case HostCmd_CMD_GET_HW_SPEC: 2050 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr); 2051 break; 2052 case HostCmd_CMD_CFG_DATA: 2053 ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, data_buf); 2054 break; 2055 case HostCmd_CMD_MAC_CONTROL: 2056 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action, 2057 data_buf); 2058 break; 2059 case HostCmd_CMD_802_11_MAC_ADDRESS: 2060 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr, 2061 cmd_action); 2062 break; 2063 case HostCmd_CMD_MAC_MULTICAST_ADR: 2064 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action, 2065 data_buf); 2066 break; 2067 case HostCmd_CMD_TX_RATE_CFG: 2068 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action, 2069 data_buf); 2070 break; 2071 case HostCmd_CMD_TXPWR_CFG: 2072 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action, 2073 data_buf); 2074 break; 2075 case HostCmd_CMD_RF_TX_PWR: 2076 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action, 2077 data_buf); 2078 break; 2079 case HostCmd_CMD_RF_ANTENNA: 2080 ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action, 2081 data_buf); 2082 break; 2083 case HostCmd_CMD_802_11_PS_MODE_ENH: 2084 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action, 2085 (uint16_t)cmd_oid, data_buf); 2086 break; 2087 case HostCmd_CMD_802_11_HS_CFG_ENH: 2088 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action, 2089 (struct mwifiex_hs_config_param *) data_buf); 2090 break; 2091 case HostCmd_CMD_802_11_SCAN: 2092 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf); 2093 break; 2094 case HostCmd_CMD_802_11_BG_SCAN_CONFIG: 2095 ret = mwifiex_cmd_802_11_bg_scan_config(priv, cmd_ptr, 2096 data_buf); 2097 break; 2098 case HostCmd_CMD_802_11_BG_SCAN_QUERY: 2099 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr); 2100 break; 2101 case HostCmd_CMD_802_11_ASSOCIATE: 2102 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf); 2103 break; 2104 case HostCmd_CMD_802_11_DEAUTHENTICATE: 2105 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr, 2106 data_buf); 2107 break; 2108 case HostCmd_CMD_802_11_AD_HOC_START: 2109 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr, 2110 data_buf); 2111 break; 2112 case HostCmd_CMD_802_11_GET_LOG: 2113 ret = mwifiex_cmd_802_11_get_log(cmd_ptr); 2114 break; 2115 case HostCmd_CMD_802_11_AD_HOC_JOIN: 2116 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr, 2117 data_buf); 2118 break; 2119 case HostCmd_CMD_802_11_AD_HOC_STOP: 2120 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr); 2121 break; 2122 case HostCmd_CMD_RSSI_INFO: 2123 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action); 2124 break; 2125 case HostCmd_CMD_802_11_SNMP_MIB: 2126 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action, 2127 cmd_oid, data_buf); 2128 break; 2129 case HostCmd_CMD_802_11_TX_RATE_QUERY: 2130 cmd_ptr->command = 2131 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY); 2132 cmd_ptr->size = 2133 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) + 2134 S_DS_GEN); 2135 priv->tx_rate = 0; 2136 ret = 0; 2137 break; 2138 case HostCmd_CMD_VERSION_EXT: 2139 cmd_ptr->command = cpu_to_le16(cmd_no); 2140 cmd_ptr->params.verext.version_str_sel = 2141 (u8)(get_unaligned((u32 *)data_buf)); 2142 memcpy(&cmd_ptr->params, data_buf, 2143 sizeof(struct host_cmd_ds_version_ext)); 2144 cmd_ptr->size = 2145 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) + 2146 S_DS_GEN); 2147 ret = 0; 2148 break; 2149 case HostCmd_CMD_MGMT_FRAME_REG: 2150 cmd_ptr->command = cpu_to_le16(cmd_no); 2151 cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action); 2152 cmd_ptr->params.reg_mask.mask = cpu_to_le32( 2153 get_unaligned((u32 *)data_buf)); 2154 cmd_ptr->size = 2155 cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) + 2156 S_DS_GEN); 2157 ret = 0; 2158 break; 2159 case HostCmd_CMD_REMAIN_ON_CHAN: 2160 cmd_ptr->command = cpu_to_le16(cmd_no); 2161 memcpy(&cmd_ptr->params, data_buf, 2162 sizeof(struct host_cmd_ds_remain_on_chan)); 2163 cmd_ptr->size = 2164 cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) + 2165 S_DS_GEN); 2166 break; 2167 case HostCmd_CMD_11AC_CFG: 2168 ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf); 2169 break; 2170 case HostCmd_CMD_PACKET_AGGR_CTRL: 2171 cmd_ptr->command = cpu_to_le16(cmd_no); 2172 cmd_ptr->params.pkt_aggr_ctrl.action = cpu_to_le16(cmd_action); 2173 cmd_ptr->params.pkt_aggr_ctrl.enable = 2174 cpu_to_le16(*(u16 *)data_buf); 2175 cmd_ptr->size = 2176 cpu_to_le16(sizeof(struct host_cmd_ds_pkt_aggr_ctrl) + 2177 S_DS_GEN); 2178 break; 2179 case HostCmd_CMD_P2P_MODE_CFG: 2180 cmd_ptr->command = cpu_to_le16(cmd_no); 2181 cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action); 2182 cmd_ptr->params.mode_cfg.mode = cpu_to_le16( 2183 get_unaligned((u16 *)data_buf)); 2184 cmd_ptr->size = 2185 cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) + 2186 S_DS_GEN); 2187 break; 2188 case HostCmd_CMD_FUNC_INIT: 2189 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET) 2190 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY; 2191 cmd_ptr->command = cpu_to_le16(cmd_no); 2192 cmd_ptr->size = cpu_to_le16(S_DS_GEN); 2193 break; 2194 case HostCmd_CMD_FUNC_SHUTDOWN: 2195 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET; 2196 cmd_ptr->command = cpu_to_le16(cmd_no); 2197 cmd_ptr->size = cpu_to_le16(S_DS_GEN); 2198 break; 2199 case HostCmd_CMD_11N_ADDBA_REQ: 2200 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf); 2201 break; 2202 case HostCmd_CMD_11N_DELBA: 2203 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf); 2204 break; 2205 case HostCmd_CMD_11N_ADDBA_RSP: 2206 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf); 2207 break; 2208 case HostCmd_CMD_802_11_KEY_MATERIAL: 2209 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr, 2210 cmd_action, cmd_oid, 2211 data_buf); 2212 break; 2213 case HostCmd_CMD_802_11D_DOMAIN_INFO: 2214 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr, 2215 cmd_action); 2216 break; 2217 case HostCmd_CMD_RECONFIGURE_TX_BUFF: 2218 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action, 2219 data_buf); 2220 break; 2221 case HostCmd_CMD_AMSDU_AGGR_CTRL: 2222 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action, 2223 data_buf); 2224 break; 2225 case HostCmd_CMD_11N_CFG: 2226 ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf); 2227 break; 2228 case HostCmd_CMD_WMM_GET_STATUS: 2229 mwifiex_dbg(priv->adapter, CMD, 2230 "cmd: WMM: WMM_GET_STATUS cmd sent\n"); 2231 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS); 2232 cmd_ptr->size = 2233 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) + 2234 S_DS_GEN); 2235 ret = 0; 2236 break; 2237 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS: 2238 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action, 2239 data_buf); 2240 break; 2241 case HostCmd_CMD_802_11_SCAN_EXT: 2242 ret = mwifiex_cmd_802_11_scan_ext(priv, cmd_ptr, data_buf); 2243 break; 2244 case HostCmd_CMD_MEM_ACCESS: 2245 ret = mwifiex_cmd_mem_access(cmd_ptr, cmd_action, data_buf); 2246 break; 2247 case HostCmd_CMD_MAC_REG_ACCESS: 2248 case HostCmd_CMD_BBP_REG_ACCESS: 2249 case HostCmd_CMD_RF_REG_ACCESS: 2250 case HostCmd_CMD_PMIC_REG_ACCESS: 2251 case HostCmd_CMD_CAU_REG_ACCESS: 2252 case HostCmd_CMD_802_11_EEPROM_ACCESS: 2253 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf); 2254 break; 2255 case HostCmd_CMD_SET_BSS_MODE: 2256 cmd_ptr->command = cpu_to_le16(cmd_no); 2257 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) 2258 cmd_ptr->params.bss_mode.con_type = 2259 CONNECTION_TYPE_ADHOC; 2260 else if (priv->bss_mode == NL80211_IFTYPE_STATION || 2261 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) 2262 cmd_ptr->params.bss_mode.con_type = 2263 CONNECTION_TYPE_INFRA; 2264 else if (priv->bss_mode == NL80211_IFTYPE_AP || 2265 priv->bss_mode == NL80211_IFTYPE_P2P_GO) 2266 cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP; 2267 cmd_ptr->size = cpu_to_le16(sizeof(struct 2268 host_cmd_ds_set_bss_mode) + S_DS_GEN); 2269 ret = 0; 2270 break; 2271 case HostCmd_CMD_PCIE_DESC_DETAILS: 2272 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action); 2273 break; 2274 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT: 2275 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf); 2276 break; 2277 case HostCmd_CMD_MEF_CFG: 2278 ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf); 2279 break; 2280 case HostCmd_CMD_COALESCE_CFG: 2281 ret = mwifiex_cmd_coalesce_cfg(priv, cmd_ptr, cmd_action, 2282 data_buf); 2283 break; 2284 case HostCmd_CMD_TDLS_OPER: 2285 ret = mwifiex_cmd_tdls_oper(priv, cmd_ptr, data_buf); 2286 break; 2287 case HostCmd_CMD_TDLS_CONFIG: 2288 ret = mwifiex_cmd_tdls_config(priv, cmd_ptr, cmd_action, 2289 data_buf); 2290 break; 2291 case HostCmd_CMD_CHAN_REPORT_REQUEST: 2292 ret = mwifiex_cmd_issue_chan_report_request(priv, cmd_ptr, 2293 data_buf); 2294 break; 2295 case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG: 2296 ret = mwifiex_cmd_sdio_rx_aggr_cfg(cmd_ptr, cmd_action, 2297 data_buf); 2298 break; 2299 case HostCmd_CMD_HS_WAKEUP_REASON: 2300 ret = mwifiex_cmd_get_wakeup_reason(priv, cmd_ptr); 2301 break; 2302 case HostCmd_CMD_MC_POLICY: 2303 ret = mwifiex_cmd_set_mc_policy(priv, cmd_ptr, cmd_action, 2304 data_buf); 2305 break; 2306 case HostCmd_CMD_ROBUST_COEX: 2307 ret = mwifiex_cmd_robust_coex(priv, cmd_ptr, cmd_action, 2308 data_buf); 2309 break; 2310 case HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG: 2311 ret = mwifiex_cmd_gtk_rekey_offload(priv, cmd_ptr, cmd_action, 2312 data_buf); 2313 break; 2314 case HostCmd_CMD_CHAN_REGION_CFG: 2315 ret = mwifiex_cmd_chan_region_cfg(priv, cmd_ptr, cmd_action); 2316 break; 2317 case HostCmd_CMD_FW_DUMP_EVENT: 2318 cmd_ptr->command = cpu_to_le16(cmd_no); 2319 cmd_ptr->size = cpu_to_le16(S_DS_GEN); 2320 break; 2321 case HostCmd_CMD_STA_CONFIGURE: 2322 ret = mwifiex_cmd_get_chan_info(cmd_ptr, cmd_action); 2323 break; 2324 default: 2325 mwifiex_dbg(priv->adapter, ERROR, 2326 "PREP_CMD: unknown cmd- %#x\n", cmd_no); 2327 ret = -1; 2328 break; 2329 } 2330 return ret; 2331 } 2332 2333 /* 2334 * This function issues commands to initialize firmware. 2335 * 2336 * This is called after firmware download to bring the card to 2337 * working state. 2338 * Function is also called during reinitialization of virtual 2339 * interfaces. 2340 * 2341 * The following commands are issued sequentially - 2342 * - Set PCI-Express host buffer configuration (PCIE only) 2343 * - Function init (for first interface only) 2344 * - Read MAC address (for first interface only) 2345 * - Reconfigure Tx buffer size (for first interface only) 2346 * - Enable auto deep sleep (for first interface only) 2347 * - Get Tx rate 2348 * - Get Tx power 2349 * - Set IBSS coalescing status 2350 * - Set AMSDU aggregation control 2351 * - Set 11d control 2352 * - Set MAC control (this must be the last command to initialize firmware) 2353 */ 2354 int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta) 2355 { 2356 struct mwifiex_adapter *adapter = priv->adapter; 2357 int ret; 2358 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl; 2359 struct mwifiex_ds_auto_ds auto_ds; 2360 enum state_11d_t state_11d; 2361 struct mwifiex_ds_11n_tx_cfg tx_cfg; 2362 u8 sdio_sp_rx_aggr_enable; 2363 u16 packet_aggr_enable; 2364 int data; 2365 2366 if (first_sta) { 2367 if (priv->adapter->iface_type == MWIFIEX_PCIE) { 2368 ret = mwifiex_send_cmd(priv, 2369 HostCmd_CMD_PCIE_DESC_DETAILS, 2370 HostCmd_ACT_GEN_SET, 0, NULL, 2371 true); 2372 if (ret) 2373 return -1; 2374 } 2375 2376 ret = mwifiex_send_cmd(priv, HostCmd_CMD_FUNC_INIT, 2377 HostCmd_ACT_GEN_SET, 0, NULL, true); 2378 if (ret) 2379 return -1; 2380 2381 /* Download calibration data to firmware. 2382 * The cal-data can be read from device tree and/or 2383 * a configuration file and downloaded to firmware. 2384 */ 2385 if (adapter->dt_node) { 2386 if (of_property_read_u32(adapter->dt_node, 2387 "marvell,wakeup-pin", 2388 &data) == 0) { 2389 pr_debug("Wakeup pin = 0x%x\n", data); 2390 adapter->hs_cfg.gpio = data; 2391 } 2392 2393 mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node, 2394 "marvell,caldata"); 2395 } 2396 2397 if (adapter->cal_data) { 2398 mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA, 2399 HostCmd_ACT_GEN_SET, 0, NULL, true); 2400 release_firmware(adapter->cal_data); 2401 adapter->cal_data = NULL; 2402 } 2403 2404 2405 /* Read MAC address from HW */ 2406 ret = mwifiex_send_cmd(priv, HostCmd_CMD_GET_HW_SPEC, 2407 HostCmd_ACT_GEN_GET, 0, NULL, true); 2408 if (ret) 2409 return -1; 2410 2411 /** Set SDIO Single Port RX Aggr Info */ 2412 if (priv->adapter->iface_type == MWIFIEX_SDIO && 2413 ISSUPP_SDIO_SPA_ENABLED(priv->adapter->fw_cap_info) && 2414 !priv->adapter->host_disable_sdio_rx_aggr) { 2415 sdio_sp_rx_aggr_enable = true; 2416 ret = mwifiex_send_cmd(priv, 2417 HostCmd_CMD_SDIO_SP_RX_AGGR_CFG, 2418 HostCmd_ACT_GEN_SET, 0, 2419 &sdio_sp_rx_aggr_enable, 2420 true); 2421 if (ret) { 2422 mwifiex_dbg(priv->adapter, ERROR, 2423 "error while enabling SP aggregation..disable it"); 2424 adapter->sdio_rx_aggr_enable = false; 2425 } 2426 } 2427 2428 /* Reconfigure tx buf size */ 2429 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF, 2430 HostCmd_ACT_GEN_SET, 0, 2431 &priv->adapter->tx_buf_size, true); 2432 if (ret) 2433 return -1; 2434 2435 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) { 2436 /* Enable IEEE PS by default */ 2437 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP; 2438 ret = mwifiex_send_cmd(priv, 2439 HostCmd_CMD_802_11_PS_MODE_ENH, 2440 EN_AUTO_PS, BITMAP_STA_PS, NULL, 2441 true); 2442 if (ret) 2443 return -1; 2444 } 2445 2446 if (drcs) { 2447 adapter->drcs_enabled = true; 2448 if (ISSUPP_DRCS_ENABLED(adapter->fw_cap_info)) 2449 ret = mwifiex_send_cmd(priv, 2450 HostCmd_CMD_MC_POLICY, 2451 HostCmd_ACT_GEN_SET, 0, 2452 &adapter->drcs_enabled, 2453 true); 2454 if (ret) 2455 return -1; 2456 } 2457 2458 mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REGION_CFG, 2459 HostCmd_ACT_GEN_GET, 0, NULL, true); 2460 } 2461 2462 /* get tx rate */ 2463 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG, 2464 HostCmd_ACT_GEN_GET, 0, NULL, true); 2465 if (ret) 2466 return -1; 2467 priv->data_rate = 0; 2468 2469 /* get tx power */ 2470 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR, 2471 HostCmd_ACT_GEN_GET, 0, NULL, true); 2472 if (ret) 2473 return -1; 2474 2475 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl)); 2476 amsdu_aggr_ctrl.enable = true; 2477 /* Send request to firmware */ 2478 ret = mwifiex_send_cmd(priv, HostCmd_CMD_AMSDU_AGGR_CTRL, 2479 HostCmd_ACT_GEN_SET, 0, 2480 &amsdu_aggr_ctrl, true); 2481 if (ret) 2482 return -1; 2483 /* MAC Control must be the last command in init_fw */ 2484 /* set MAC Control */ 2485 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL, 2486 HostCmd_ACT_GEN_SET, 0, 2487 &priv->curr_pkt_filter, true); 2488 if (ret) 2489 return -1; 2490 2491 if (!disable_auto_ds && first_sta && 2492 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) { 2493 /* Enable auto deep sleep */ 2494 auto_ds.auto_ds = DEEP_SLEEP_ON; 2495 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME; 2496 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH, 2497 EN_AUTO_PS, BITMAP_AUTO_DS, 2498 &auto_ds, true); 2499 if (ret) 2500 return -1; 2501 } 2502 2503 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) { 2504 /* Send cmd to FW to enable/disable 11D function */ 2505 state_11d = ENABLE_11D; 2506 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 2507 HostCmd_ACT_GEN_SET, DOT11D_I, 2508 &state_11d, true); 2509 if (ret) 2510 mwifiex_dbg(priv->adapter, ERROR, 2511 "11D: failed to enable 11D\n"); 2512 } 2513 2514 /* Pacekt aggregation handshake with firmware */ 2515 if (aggr_ctrl) { 2516 packet_aggr_enable = true; 2517 mwifiex_send_cmd(priv, HostCmd_CMD_PACKET_AGGR_CTRL, 2518 HostCmd_ACT_GEN_SET, 0, 2519 &packet_aggr_enable, true); 2520 } 2521 2522 /* Send cmd to FW to configure 11n specific configuration 2523 * (Short GI, Channel BW, Green field support etc.) for transmit 2524 */ 2525 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG; 2526 ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_CFG, 2527 HostCmd_ACT_GEN_SET, 0, &tx_cfg, true); 2528 2529 return ret; 2530 } 2531