diff --git a/components/p2p/core/src/wlan_p2p_main.c b/components/p2p/core/src/wlan_p2p_main.c index 413033d2cb..af75439459 100644 --- a/components/p2p/core/src/wlan_p2p_main.c +++ b/components/p2p/core/src/wlan_p2p_main.c @@ -222,6 +222,8 @@ static QDF_STATUS p2p_vdev_obj_create_notification( p2p_vdev_obj->noa_status = true; p2p_vdev_obj->non_p2p_peer_count = 0; p2p_init_random_mac_vdev(p2p_vdev_obj); + qdf_mem_copy(p2p_vdev_obj->prev_action_frame_addr2, + wlan_vdev_mlme_get_macaddr(vdev), QDF_MAC_ADDR_SIZE); status = wlan_objmgr_vdev_component_obj_attach(vdev, WLAN_UMAC_COMP_P2P, p2p_vdev_obj, @@ -546,6 +548,8 @@ static QDF_STATUS p2p_object_init_params( cfg_get(psoc, CFG_GO_LINK_MONITOR_PERIOD); p2p_soc_obj->param.p2p_device_addr_admin = cfg_get(psoc, CFG_P2P_DEVICE_ADDRESS_ADMINISTRATED); + p2p_soc_obj->param.is_random_seq_num_enabled = + cfg_get(psoc, CFG_ACTION_FRAME_RANDOM_SEQ_NUM_ENABLED); return QDF_STATUS_SUCCESS; } diff --git a/components/p2p/core/src/wlan_p2p_main.h b/components/p2p/core/src/wlan_p2p_main.h index 019d0b10fa..bf85652c0a 100644 --- a/components/p2p/core/src/wlan_p2p_main.h +++ b/components/p2p/core/src/wlan_p2p_main.h @@ -199,11 +199,13 @@ enum p2p_connection_status { * @p2p_device_addr_admin: enable/disable to derive the P2P * MAC address from the primary MAC address * @skip_dfs_channel_p2p_search: skip DFS Channel in case of P2P Search + * @is_random_seq_num_enabled: Flag to generate random sequence numbers */ struct p2p_param { uint32_t go_keepalive_period; uint32_t go_link_monitor_period; bool p2p_device_addr_admin; + bool is_random_seq_num_enabled; }; /** @@ -319,6 +321,8 @@ struct p2p_set_mac_filter_req { * @random_mac_lock: lock for random_mac list * @random_mac: active random mac filter lists * @pending_req: pending set mac filter request. + * @prev_action_frame_addr2: Address2 field (TA) of the last transmitted + * action frame. */ struct p2p_vdev_priv_obj { struct wlan_objmgr_vdev *vdev; @@ -330,6 +334,7 @@ struct p2p_vdev_priv_obj { qdf_spinlock_t random_mac_lock; struct action_frame_random_mac random_mac[MAX_RANDOM_MAC_ADDRS]; struct p2p_set_mac_filter_req pending_req; + uint8_t prev_action_frame_addr2[QDF_MAC_ADDR_SIZE]; }; /** diff --git a/components/p2p/core/src/wlan_p2p_off_chan_tx.c b/components/p2p/core/src/wlan_p2p_off_chan_tx.c index bbd56c0669..bd0f17dbe0 100644 --- a/components/p2p/core/src/wlan_p2p_off_chan_tx.c +++ b/components/p2p/core/src/wlan_p2p_off_chan_tx.c @@ -574,6 +574,69 @@ static void p2p_set_ht_caps(struct tx_action_context *tx_ctx, { } +/** + * p2p_get_next_seq_num() - get next sequence number to fill mac header + * @peer: PEER object + * @tx_ctx: tx context + * @ta : transmitter address + * + * API to get next sequence number of action frame for the peer. + * + * Return: Next sequence number of the peer + */ +static uint16_t p2p_get_next_seq_num(struct wlan_objmgr_peer *peer, + struct tx_action_context *tx_ctx, + uint8_t *ta) +{ + uint16_t random_num, random_num_bitmask = 0x03FF; + uint16_t seq_num, seq_num_bitmask = 0x0FFF; + struct p2p_vdev_priv_obj *p2p_vdev_obj; + struct wlan_objmgr_vdev *vdev; + bool is_new_random_ta; + + vdev = wlan_objmgr_get_vdev_by_id_from_psoc(tx_ctx->p2p_soc_obj->soc, + tx_ctx->vdev_id, + WLAN_P2P_ID); + if (!vdev) { + p2p_debug("vdev is null"); + return false; + } + + p2p_vdev_obj = wlan_objmgr_vdev_get_comp_private_obj( + vdev, WLAN_UMAC_COMP_P2P); + if (!p2p_vdev_obj) { + wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID); + p2p_debug("p2p vdev object is NULL"); + return false; + } + + is_new_random_ta = qdf_mem_cmp(p2p_vdev_obj->prev_action_frame_addr2, + ta, QDF_MAC_ADDR_SIZE); + if (is_new_random_ta && + tx_ctx->p2p_soc_obj->param.is_random_seq_num_enabled) { + /** + * Increment the previous sequence number with 10-bits + * random number to get the next sequence number. + */ + + qdf_get_random_bytes(&random_num, sizeof(random_num)); + random_num &= random_num_bitmask; + seq_num = (peer->peer_mlme.seq_num + random_num) & + seq_num_bitmask; + peer->peer_mlme.seq_num = seq_num; + + qdf_mem_copy(p2p_vdev_obj->prev_action_frame_addr2, ta, + QDF_MAC_ADDR_SIZE); + + } else { + seq_num = wlan_peer_mlme_get_next_seq_num(peer); + } + + wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID); + + return seq_num; +} + /** * p2p_populate_mac_header() - update sequence number * @tx_ctx: tx context @@ -626,7 +689,7 @@ static QDF_STATUS p2p_populate_mac_header( p2p_err("no valid peer"); return QDF_STATUS_E_INVAL; } - seq_num = (uint16_t)wlan_peer_mlme_get_next_seq_num(peer); + seq_num = (uint16_t)p2p_get_next_seq_num(peer, tx_ctx, wh->i_addr2); seq_ctl = (struct wlan_seq_ctl *)(tx_ctx->buf + WLAN_SEQ_CTL_OFFSET); seq_ctl->seq_num_lo = (seq_num & WLAN_LOW_SEQ_NUM_MASK); diff --git a/components/p2p/dispatcher/inc/wlan_p2p_cfg.h b/components/p2p/dispatcher/inc/wlan_p2p_cfg.h index 3655bbc241..a0558abbdc 100644 --- a/components/p2p/dispatcher/inc/wlan_p2p_cfg.h +++ b/components/p2p/dispatcher/inc/wlan_p2p_cfg.h @@ -98,7 +98,32 @@ 1, \ "derive the P2P MAC address from the primary MAC address") +/* + * + * action_frame_random_seq_num_enabled - Enables random sequence number + * generation for action frames + * @Min: 0 + * @Max: 1 + * @Default: 1 + * + * This ini is used to enable/disable random sequence number generation for + * action frames. + * + * Related: None. + * + * Supported Feature: P2P + * + * Usage: external + * + * + */ +#define CFG_ACTION_FRAME_RANDOM_SEQ_NUM_ENABLED CFG_INI_BOOL( \ + "action_frame_random_seq_num_enabled", \ + 1, \ + "Enable random seq nums for action frames") + #define CFG_P2P_ALL \ + CFG(CFG_ACTION_FRAME_RANDOM_SEQ_NUM_ENABLED) \ CFG(CFG_GO_KEEP_ALIVE_PERIOD) \ CFG(CFG_GO_LINK_MONITOR_PERIOD) \ CFG(CFG_P2P_DEVICE_ADDRESS_ADMINISTRATED)