# CHAN
[LMAC]

LMAC MAC Management module. More...

Collaboration diagram for CHAN:

## Data Structures
struct | chan_window
| Internal structure to represent window. More...
struct | chan_tbtt_tag
| Structure containing TBTT switch information. More...
struct | chan_switch_tag
| Structure containing scheduled channel switch information. More...
struct | chan_ctxt_tag
| Structure describing a channel context. More...
struct | chan_env_tag
| LMAC MAC Management Context. More...
## Defines
#define | CHAN_SWITCH_CNT 4
| Maximum number of scheduled switch.
#define | CHAN_MIN_PRES_DUR_US (5000)
| Minimal presence duration on a channel (in us).
#define | CHAN_CONN_LESS_DELAY (30000)
| Delay before switching on a Scan or a ROC channel, indicate minimal duration between two successive scan/roc operations.
#define | CHAN_ROC_SCAN_PENDING_MASK (CO_BIT(CHAN_ENV_ROC_BIT) | CO_BIT(CHAN_ENV_SCAN_BIT))
| Flags indicating that a scan ROC is pending.
#define | CHAN_P2P_NOA_RESCHEDULE_THRESHOLD 2000
| Drift threshold of STA/P2P-CLI TBTT to re-schedule NOA, in us.
#define | CHAN_P2P_NOA_RESYNC_THRESHOLD 200
| Drift threshold of STA/P2P-CLI TBTT to re-sync P2P GO TBTT with NOA, in us.
#define | CHAN_TRAF_CTXT_CNT (NX_CHAN_CTXT_CNT)
| Number of channel contexts for traffic.
#define | CHAN_CHAN_CTXT_CNT (CHAN_TRAF_CTXT_CNT + 1 + 1)
| Number of channel context (+1 for Scan and +1 for the Remain on Channel).
#define | CHAN_SCAN_CTXT_IDX (CHAN_TRAF_CTXT_CNT)
| Index of the Scan Channel Context.
#define | CHAN_ROC_CTXT_IDX (CHAN_SCAN_CTXT_IDX + 1)
| Index of the Remain on Channel Context.
#define | CHAN_CTXT_UNUSED (0xFF)
| Index of a Channel Context that is not linked with a VIF.
#define | CHAN_SWITCH_DELAY (4000 + phy_get_channel_switch_dur())
| Delay between the start of a channel switch procedure and the time the new channel should be active (in us).
## Enumerations
enum | chan_ctxt_status { CHAN_NOT_SCHEDULED = 0, CHAN_NOT_PROG, CHAN_GOTO_IDLE, CHAN_WAIT_NOA_CFM, CHAN_WAITING_END, CHAN_PRESENT, CHAN_SENDING_NOA }
| Channel Context State Machine. More...
enum | chan_tbtt_status { CHAN_TBTT_PROG = CO_BIT(0), CHAN_TBTT_WAIT_TO = CO_BIT(1), CHAN_TBTT_SKIPPED = CO_BIT(2), CHAN_TBTT_ALREADY_ADDED = CO_BIT(3), CHAN_TBTT_SCHEDULE_P2P_NOA = CO_BIT(4), CHAN_TBTT_P2P_NOA_TSF_UPDATE = CO_BIT(5), CHAN_TBTT_P2P_NOA_RESYNC = CO_BIT(6) }
| TBTT Switch State Machine. More...
enum | chan_env_status_bit { CHAN_ENV_ROC_WAIT_BIT = 0, CHAN_ENV_SCAN_WAIT_BIT, CHAN_ENV_ROC_BIT, CHAN_ENV_SCAN_BIT, CHAN_ENV_DELAY_PROG_BIT, CHAN_ENV_BCN_DETECT_BIT, CHAN_ENV_FIX_CTXT_PENDING_BIT }
| Channel Environment status bits (see chan_env.status). More...
## Functions
static void | chan_switch_start (struct chan_ctxt_tag *ctxt)
| Initiate channel switch procedure in order to jump to indicated channel.
static void | chan_switch_channel (void)
| Switch from chan_env.current_ctxt to chan_env.switch_ctxt.
__INLINE void | chan_switch_set_timer (struct chan_switch_tag *ch_switch)
| Configure timer for next channel switch.
__INLINE void | chan_switch_reset_timer (void)
| Cancel timer for channel switch.
__INLINE struct chan_switch_tag * | chan_switch_pop (void)
| Extract first element of scheduled channel switch list.
__INLINE struct chan_switch_tag * | chan_switch_pick (void)
| Get first element of scheduled channel switch list.
__INLINE struct chan_switch_tag * | chan_switch_last (void)
| Get last element of scheduled channel switch list.
__INLINE void | chan_switch_push_back (struct chan_switch_tag *ch_switch)
| Insert on element at the end of the scheduled channel switch list.
__INLINE bool | chan_switch_no_schedule (void)
| Check is scheduled channel switch list is empty.
__INLINE struct chan_switch_tag * | chan_switch_alloc (void)
| Allocate a channel switch information element.
__INLINE void | chan_switch_free (struct chan_switch_tag *ch_switch)
| Free a channel switch information element.
__INLINE struct chan_tbtt_tag * | chan_tbtt_pick (void)
| Get first element of tbtt list.
__INLINE struct chan_tbtt_tag * | chan_tbtt_next (struct chan_tbtt_tag *tbtt)
| Get next element of tbtt list.
__INLINE void | chan_tbtt_remove (struct chan_tbtt_tag *tbtt)
| Remove TBTT form the list.
__INLINE void | chan_tbtt_insert_before (struct chan_tbtt_tag *tbtt, struct chan_tbtt_tag *tbtt_next)
| Insert TBTT before another TBTT.
static uint32_t | chan_vif_tbtt_intv (struct vif_info_tag *vif)
| Get TBTT interval for a vif.
static uint32_t | chan_vif_tbtt_dur (struct vif_info_tag *vif)
| Get TBTT duration for a vif.
static void | chan_upd_ctxt_status (struct chan_ctxt_tag *ctxt, uint8_t status)
| Update the status of a provided channel context.
static struct chan_ctxt_tag * | chan_get_first_traf_ctxt (void)
| Get pointer to first active traffic channel context.
static struct chan_ctxt_tag * | chan_get_next_traf_ctxt (struct chan_ctxt_tag *ctxt)
| Get pointer to another traffic channel context.
static void | chan_send_pre_switch_ind (struct chan_ctxt_tag *old_ctxt)
| Send CHANNEL_PRE_SWITCH_IND message to the upper layers.
static void | chan_send_switch_ind (struct chan_ctxt_tag *new_ctxt)
| Send CHANNEL_SWITCH_IND message to the upper layers.
static void | chan_send_survey_ind (void)
| Send a channel survey to the host by using the MM_CHANNEL_SURVEY_IND message.
static void | chan_send_roc_exp_ind (struct chan_ctxt_tag *ctxt)
| Send MM_REMAIN_ON_CHANNEL_EXP_IND message to the upper layers.
__INLINE bool | chan_is_p2p_go (struct vif_info_tag *vif)
| Test if a vif is a P2P GO.
static uint32_t | chan_window_merge_duration (struct chan_window *w1, struct chan_window *w2, struct chan_window *w_res, uint32_t interval)
| Return the minimal window that contains both window.
static void | chan_stop_p2pgo_noa (struct vif_info_tag *p2pgo_vif)
| Stop concurrent NOA for a P2P GO interface.
static void | chan_start_p2pgo_noa (struct vif_info_tag *p2pgo_vif)
| Start concurrent NOA for a P2P GO interface.
__INLINE bool | chan_get_p2pgo (struct vif_info_tag **p2pgo_vif)
| Return P2P GO interface.
static bool | chan_start_p2pgo_single_noa (struct vif_info_tag *vif, uint32_t start, struct chan_tbtt_tag *tbtt)
| Start a non-periodic NOA on a P2P GO interface.
static bool | chan_tbtt_overlap (struct chan_tbtt_tag *tbtt1, struct chan_tbtt_tag *tbtt2)
| Check if TBTT constraint for two vifs overlap.
__INLINE bool | chan_tbtt_skip_fix_ctxt (uint32_t tbtt_time, struct chan_ctxt_tag *ctxt)
| Check if TBTT must be skipped because of scheduled switch or fix channel.
static void | chan_add_next_tbtt (struct vif_info_tag *vif, uint32_t tbtt_time, uint32_t skip_cnt)
| Add next TBTT for a vif.
static uint32_t | chan_share_medium (int32_t dur_to_split, uint32_t dur_spent, uint32_t now)
| Share time between two channel context.
static void | chan_schedule_one_switch (uint32_t date, struct chan_ctxt_tag *ctxt, struct chan_tbtt_tag *tbtt)
| Schedule a channel switch.
static bool | chan_schedule_extra_switch_from_p2pgo_ctxt (int p2p_vif_index, uint32_t now, uint32_t *switch_date, uint32_t *return_date)
| Schedule a switch (and return) to other context when TBTT ends on a channel with a P2P GO interface.
static bool | chan_schedule_extra_switch_to_p2pgo_ctxt (int p2p_vif_index, uint32_t *switch_date, uint32_t *return_date)
| Schedule a switch (and return) to a context with P2P GO interface when TBTT ends on a channel without a P2P GO interface.
static void | chan_schedule_switch_from_p2pgo_ctxt (int p2p_vif_index, struct chan_ctxt_tag *next_ctxt, uint32_t now, uint32_t *switch_date)
| Schedule a switch when TBTT window ends, from a context with a P2P GO interface to another context.
static void | chan_schedule_switch_to_p2pgo_ctxt (int p2p_vif_index, struct chan_ctxt_tag *ctxt, uint32_t now, uint32_t *switch_date)
| Schedule a switch from a context without P2P GO interface when TBTT ends to a context with P2P GO interface .
static void | chan_schedule_next_switch (struct vif_info_tag *vif, uint32_t now, uint32_t tbtt_dur)
| Schedule all channel switches from end of current TBTT until next TBTT.
static void | chan_cancel_all_switch (void)
| Cancel all scheduled channel switches.
static void | chan_fix_ctxt_until (struct chan_ctxt_tag *ctxt)
| Fix a channel context for a specified period.
static void | chan_conn_less_delay_evt (void *env)
| Callback called upon Connection Less Delay timer expiration.
static void | chan_conn_less_delay_prog (void)
| Program the timer used for delaying Scan/RoC operations.
static void | chan_conn_less_ctxt_end (struct chan_ctxt_tag *ctxt)
| Handle ends of connection-less channel context.
static struct chan_ctxt_tag * | chan_fix_ctxt_end (void)
| Return the new channel context to switch to after a fixed channel context.
static void | chan_tmr_switch_cb (void *env)
| Timer callback for channel switch.
static void | chan_pre_switch_channel (void)
| Function called once SW and HW are ready for a channel switch.
static void | chan_tx_cfm (void *dummy, uint32_t status)
| Function called during the Channel Switch procedure each time a NULL packet used for Absence indication is confirmed.
static void | chan_notify_presence (void)
| For each VIF linked with the channel context we are switching on, we send a NULL frame with the PM bit set to 0 in order to indicate our presence.
static int | chan_notify_absence (void)
| For each VIF linked with the channel context we are leaving, we send a NULL frame with the PM bit set to 1 in order to indicate our absence.
static void | chan_goto_idle_cb (void)
| This callback is called once HW has gone to the IDLE state during a channel switch procedure.
static void | chan_send_force_idle (void)
| Send a MM_FORCE_IDLE_REQ message to TASK_MM in order to require the HW to enter in IDLE mode.
static bool | chan_check_chan (struct mac_chan_op const *chan_req, uint8_t *idx)
| Go through the list of channel contexts in order to check if a channel context, using compatible parameters than those provided by the host, is currently used.
static void | chan_p2p_noa_resync (struct vif_info_tag *vif)
| Move P2P GO TBTT and NOA to resyncrhonize with other AP's TBTT.
static void | chan_p2p_noa_tsf_updated (struct vif_info_tag *vif)
| Post process after a TBTT move on a P2P GO interface.
static void | chan_p2p_noa_resync_check (struct vif_info_tag *vif, uint32_t tbtt_time)
| Check if drift in TBTT implies a resync (or restart) of NOA.
static void | chan_reset_tbtt_list (void)
| Reset TBTT list in channel module.
static void | chan_ctxt_init (struct chan_ctxt_tag *ctxt)
| Initialize all parameters stored in a channel context entry.
void | chan_init (void)
| MM Channel Module initialization function.
void | chan_scan_req (uint8_t band, uint16_t freq, int8_t pwr, uint32_t duration_us, uint8_t flags, uint8_t vif_index)
| Request to go to a specific channel for scanning.
uint8_t | chan_roc_req (struct mm_remain_on_channel_req const *req, ke_task_id_t taskid)
| Request to go to a specific channel for a given duration.
uint8_t | chan_ctxt_add (struct mac_chan_op const *chan_req, uint8_t *idx)
| Request to allocate a new channel context.
void | chan_ctxt_del (uint8_t idx)
| Free a previously allocated channel context.
void | chan_ctxt_link (uint8_t vif_idx, uint8_t chan_idx)
| Link a channel context to a VIF.
void | chan_ctxt_unlink (uint8_t vif_idx)
| Unlink the channel context from a VIF.
void | chan_ctxt_update (struct mm_chan_ctxt_update_req const *update)
| Request to update the parameters of a channel context.
void | chan_ctxt_link_monitor (uint8_t chan_idx)
| Link a channel context to the monitor interface.
int | chan_tbtt_start (struct vif_info_tag *vif, uint32_t tbtt_time, uint32_t next_tbtt_time)
| Indicates that TBTT starts and provides date of the next TBTT.
void | chan_tbtt_updated (struct vif_info_tag *vif)
| Called when TBTT timer has been updated after beacon reception.
void | chan_bcn_to_evt (struct vif_info_tag *vif)
| Indicates end of the TBTT window.
void | chan_bcn_detect_start (struct vif_info_tag *vif)
| Start a Remain on Channel procedure (duration is the beacon interval) in order to catch the beacon sent by a peer AP device.
void | chan_p2p_absence_update (struct chan_ctxt_tag *ctxt, bool absence)
| Function used by the P2P module to notify the chan module about an update of presence status of a GO device.
bool | chan_is_on_channel (struct vif_info_tag *vif)
| Check if the VIF passed as parameter has currently access to the channel.
bool | chan_is_tx_allowed (struct vif_info_tag *vif)
| Check if transmission is allowed on a vif's channel.
bool | chan_is_on_operational_channel (struct vif_info_tag *vif)
| Check if the VIF passed as parameter is currently on its operational channel.
void | chan_update_tx_power (struct chan_ctxt_tag *ctxt)
| Update TX power for a channel context.
void | chan_ctxt_sched (struct mm_chan_ctxt_sched_req const *sched_req, ke_task_id_t taskid)
| Request to schedule the switch to a channel context.
## Variables
struct chan_env_tag | chan_env
| MM Channel module context variable.
struct chan_ctxt_tag | chan_ctxt_pool [CHAN_CHAN_CTXT_CNT]
| Pool of channel contexts.
struct chan_switch_tag | chan_switch_pool [CHAN_SWITCH_CNT]
| Pool of channel switch descriptor.
struct chan_env_tag | chan_env
| MM Channel module context variable.

## Detailed Description

LMAC MAC Management module.

The CHAN module is used to switch the current operating channel at runtime.

This is not related to the CSA (Channel switch Annoucement) procedure. This is needed during a SCAN, a Remain on Channel (ROC) or when multiple vifs are active on different operating channels.

## Enumeration Type Documentation

enum chan_ctxt_status

Channel Context State Machine.

Enumerator:

  CHAN_NOT_SCHEDULED | Context has not been scheduled.
  CHAN_NOT_PROG | Context has been scheduled but is not been programmed.
  CHAN_GOTO_IDLE | HW is going to IDLE state.
  CHAN_WAIT_NOA_CFM | Wait for Notification of Absence confirmation.
  CHAN_WAITING_END | Waiting for channel duration timer end.
  CHAN_PRESENT | Present on channel but End of Channel timer not running.
  CHAN_SENDING_NOA | Context is sending a notification of absence.

Definition at line 64 of file chan.h.

enum chan_env_status_bit

Channel Environment status bits (see chan_env.status).

Enumerator:

  CHAN_ENV_ROC_WAIT_BIT | Remain on Channel operation is waiting.
  CHAN_ENV_SCAN_WAIT_BIT | Scan Operation is waiting.
  CHAN_ENV_ROC_BIT | Remain on Channel operation is in progress.
  CHAN_ENV_SCAN_BIT | Scan Operation is in progress.
  CHAN_ENV_DELAY_PROG_BIT | Connection Less Delay Timer is programmed.
  CHAN_ENV_BCN_DETECT_BIT | Beacon Detection is in progress.
  CHAN_ENV_FIX_CTXT_PENDING_BIT | Fix channel delayed.

Definition at line 103 of file chan.h.

enum chan_tbtt_status

TBTT Switch State Machine.

Enumerator:

  CHAN_TBTT_PROG | TBTT Timer is programmed.
  CHAN_TBTT_WAIT_TO | TBTT was scheduled, and end of TBTT period is expected.
  CHAN_TBTT_SKIPPED | TBTT was skipped by CHAN module.
  CHAN_TBTT_ALREADY_ADDED | Next TBTT was added at the start of the TBTT, so no need to add it at the.
  CHAN_TBTT_SCHEDULE_P2P_NOA | Need to start P2P NOA once this TBTT has been programmed.
  CHAN_TBTT_P2P_NOA_TSF_UPDATE | Indicate that p2p_noa_tsf_update field is valid.
  CHAN_TBTT_P2P_NOA_RESYNC | Indicate that P2P NOA must be resynced.

Definition at line 83 of file chan.h.

## Function Documentation

static void chan_add_next_tbtt | ( | struct vif_info_tag * | vif,
|  | uint32_t | tbtt_time,
|  | uint32_t | skip_cnt |
| ) |  |  | `[static]`

Add next TBTT for a vif.

This will add the next TBTT element for a vif in chan_env.list_tbtt. This list is only used by the module to scheduled channel switch. If it's not possible to add this TBTT, because of scheduled switchs (chan_tbtt_skip_fix_ctxt) or TBTT overlap (chan_tbtt_overlap), the function is called recursively with parameter `tbtt_time` incremented by one beacon interval and parameter `skip_cnt` incremented by one.

Parameters:

  `[in]` | vif | VIF structure.
  `[in]` | tbtt_time | Date of the next TBTT (absolute timestamp in us)
  `[in]` | skip_cnt | Number of TBTT skipped (only for debug).

Definition at line 1087 of file chan.c.

References vif_info_tag::chan_ctxt, chan_is_p2p_go(), chan_start_p2pgo_single_noa(), CHAN_SWITCH_DELAY, chan_tbtt_insert_before(), chan_tbtt_next(), chan_tbtt_overlap(), chan_tbtt_pick(), CHAN_TBTT_PROG, chan_tbtt_remove(), chan_tbtt_skip_fix_ctxt(), chan_vif_tbtt_dur(), chan_vif_tbtt_intv(), hal_machw_time_cmp(), vif_info_tag::index, vif_info_tag::tbtt_switch, chan_tbtt_tag::time, TR_32, and TRACE_CHAN.

Referenced by chan_fix_ctxt_until(), and chan_p2p_noa_tsf_updated().

void chan_bcn_detect_start | ( | struct vif_info_tag * | vif | ) |

Start a Remain on Channel procedure (duration is the beacon interval) in order to catch the beacon sent by a peer AP device.

Parameters:

  `[in]` | vif | VIF Entry

Referenced by mm_set_vif_state_req_handler().

void chan_bcn_to_evt | ( | struct vif_info_tag * | vif | ) |

Indicates end of the TBTT window.

It is called by MM at the end of the TBTT window (i.e. when beacon has been received or timeout has been reached). If multiple channel contexts are active, it will add the next TBTT in the list and scheduled channel switches until next scheduled TBTT.

Parameters:

  `[in]` | vif | VIF Entry

Referenced by vif_mgmt_bcn_to_evt().

static void chan_cancel_all_switch | ( | void |  | ) | `[static]`

Cancel all scheduled channel switches.

Definition at line 1585 of file chan.c.

References chan_switch_free(), chan_switch_pop(), and chan_switch_reset_timer().

Referenced by chan_fix_ctxt_until(), and chan_p2p_noa_tsf_updated().

static bool chan_check_chan | ( | struct mac_chan_op const * | chan_req,
|  | uint8_t * | idx |
| ) |  |  | `[static]`

Go through the list of channel contexts in order to check if a channel context, using compatible parameters than those provided by the host, is currently used.

By "compatible", it means that they have the same primary channel and one configuration include the other one. If the requested configuration is wider than the current configuration, then the latter one is updated. Note: The check assume valid 802.11 channel configuration (e.g. given a primary channel there is only one valid 80MHz channel defined)

Parameters:

  `[in]` | chan_req | Parameters of the channel to be added
  `[in,out]` | idx | Pointer to the found channel context index

Returns:
  true if a compatible channel context has been found, else false

Definition at line 2312 of file chan.c.

References mac_chan_op::band, mac_chan_op::center1_freq, mac_chan_op::center2_freq, chan_ctxt_pool, CHAN_CTXT_UNUSED, chan_env, CHAN_TRAF_CTXT_CNT, chan_ctxt_tag::channel, chan_env_tag::current_ctxt, chan_ctxt_tag::idx, chan_env_tag::nb_sched_ctxt, PHY_CHNL_BW_160, PHY_PRIM, phy_set_channel(), mac_chan_op::prim20_freq, TRACE_CHAN, and mac_chan_op::type.

static void chan_conn_less_ctxt_end | ( | struct chan_ctxt_tag * | ctxt | ) | `[static]`

Handle ends of connection-less channel context.

When time allocated for a connection-less channel context is over some specific action need to be done:

- For SCAN: need to send scan survey
- For ROC : need to indication that ROC is over

Parameters:

  `[in]` | ctxt | Connection-less Channel context.

Definition at line 1748 of file chan.c.

References chan_conn_less_delay_prog(), CHAN_CTXT_UNUSED, chan_env, CHAN_ENV_BCN_DETECT_BIT, CHAN_ENV_DELAY_PROG_BIT, CHAN_ENV_ROC_BIT, CHAN_ENV_ROC_WAIT_BIT, CHAN_ENV_SCAN_BIT, CHAN_ENV_SCAN_WAIT_BIT, CHAN_ROC_CTXT_IDX, CHAN_SCAN_CTXT_IDX, chan_send_roc_exp_ind(), chan_send_survey_ind(), CO_BIT, chan_env_tag::current_ctxt, GLOBAL_INT_DISABLE, GLOBAL_INT_RESTORE, chan_ctxt_tag::idx, ke_msg_send_basic(), mm_back_to_host_idle(), mm_force_idle_req(), MM_SCAN_CHANNEL_END_IND, chan_env_tag::pm, ps_env_tag::prevent_sleep, ps_env, PS_SCAN_ONGOING, chan_env_tag::status, chan_env_tag::switch_ctxt, TASK_MM, TASK_SCAN, TASK_TDLS, chan_ctxt_tag::taskid, and tdls_send_chan_switch_base_ind().

Referenced by chan_tmr_switch_cb().

static void chan_conn_less_delay_evt | ( | void * | env | ) | `[static]`

Callback called upon Connection Less Delay timer expiration.

If both Scan and RoC are scheduled, start RoC.

Parameters:

  `[in]` | env | Should be a NULL pointer, do not use it

Definition at line 1675 of file chan.c.

References ASSERT_ERR, ASSERT_WARN, chan_ctxt_pool, chan_env, CHAN_ENV_ROC_BIT, CHAN_ENV_ROC_WAIT_BIT, CHAN_ENV_SCAN_BIT, CHAN_ENV_SCAN_WAIT_BIT, chan_fix_ctxt_until(), CHAN_ROC_CTXT_IDX, CHAN_SCAN_CTXT_IDX, CO_BIT, chan_env_tag::status, and TRACE_CHAN.

Referenced by chan_conn_less_delay_prog().

static void chan_conn_less_delay_prog | ( | void |  | ) | `[static]`

Program the timer used for delaying Scan/RoC operations.

chan_conn_less_delay_evt is called upon timer expiration

Definition at line 1717 of file chan.c.

References CHAN_CONN_LESS_DELAY, chan_conn_less_delay_evt(), chan_env, CHAN_ENV_DELAY_PROG_BIT, CO_BIT, ke_time(), mm_timer_set(), chan_env_tag::nb_sched_ctxt, chan_env_tag::status, chan_env_tag::tmr_conn_less, and TRACE_CHAN.

Referenced by chan_conn_less_ctxt_end().

uint8_t chan_ctxt_add | ( | struct mac_chan_op const * | chan_req,
|  | uint8_t * | idx |
| ) |  |  |

Request to allocate a new channel context.

Parameters:

  `[in]` | chan_req | Pointer to the channel parameter structure
  `[out]` | idx | Index of the allocated channel context

Returns:
  CO_OK if allocation was successful, CO_FAIL otherwise

Referenced by apm_start_cac_req_handler(), and apm_start_req_handler().

void chan_ctxt_del | ( | uint8_t | idx | ) |

Free a previously allocated channel context.

Parameters:

  `[in]` | idx | Index of the channel context to be freed

static void chan_ctxt_init | ( | struct chan_ctxt_tag * | ctxt | ) | `[static]`

Initialize all parameters stored in a channel context entry.

Parameters:

  `[in]` | ctxt | Channel context entry to be initialazed

Definition at line 2531 of file chan.c.

References CHAN_CTXT_UNUSED, chan_ctxt_tag::idx, INVALID_VIF_IDX, chan_ctxt_tag::p2pgo_vif_index, and chan_ctxt_tag::taskid.

void chan_ctxt_link | ( | uint8_t | vif_idx,
|  | uint8_t | chan_idx |
| ) |  |  |

Link a channel context to a VIF.

Parameters:

  `[in]` | vif_idx | Index of the VIF
  `[in]` | chan_idx | Index of the channel context to be linked

Referenced by apm_start_cac_req_handler(), apm_start_req_handler(), and scanu_join_cfm_handler().

void chan_ctxt_link_monitor | ( | uint8_t | chan_idx | ) |

Link a channel context to the monitor interface.

This function is called every time a channel context is linked to a data interface and links the monitor interface to the same channel context of the data interface. If there is no data interface, this function links the monitor interface to the provided channel context and sets the monitor interface as active.

Parameters:

  `[in]` | chan_idx | Index of the channel context to be linked

void chan_ctxt_sched | ( | struct mm_chan_ctxt_sched_req const * | sched_req,
|  | ke_task_id_t | taskid |
| ) |  |  |

Request to schedule the switch to a channel context.

Parameters:

  `[in]` | sched_req | Pointer to the channel scheduling structure
  `[in]` | taskid | Kernel task ID of the task the confirmation has to be sent to

void chan_ctxt_unlink | ( | uint8_t | vif_idx | ) |

Unlink the channel context from a VIF.

Parameters:

  `[in]` | vif_idx | Index of the VIF

Referenced by apm_stop_cac_req_handler(), and mm_chan_ctxt_unlink_req_handler().

void chan_ctxt_update | ( | struct mm_chan_ctxt_update_req const * | update | ) |

Request to update the parameters of a channel context.

Parameters:

  `[in]` | update | Pointer to the new parameters structure

Referenced by mm_chan_ctxt_update_req_handler().

static struct chan_ctxt_tag* chan_fix_ctxt_end | ( | void |  | ) | `[static, read]`

Return the new channel context to switch to after a fixed channel context.

When a fixed channel is configured all previously configured switches are removed (chan_fix_ctxt_until). This function returns the new channel to switch to when the fixed period ends. If there are more than one active channel context, it selects the channel of the next TBTT, otherwise it selects the active channel (if any).

Returns:
  Channel context to switch to. (can be NULL)

Definition at line 1817 of file chan.c.

References vif_info_tag::chan_ctxt, chan_env, chan_get_first_traf_ctxt(), chan_tbtt_pick(), chan_env_tag::fix_ctxt, chan_env_tag::nb_sched_ctxt, chan_tbtt_tag::vif_index, and vif_info_tab.

Referenced by chan_tmr_switch_cb().

static void chan_fix_ctxt_until | ( | struct chan_ctxt_tag * | ctxt | ) | `[static]`

Fix a channel context for a specified period.

This function is called when a channel switch must be forced for a given time, for a SCAN or a ROC procedure. All scheduled switches are removed (even if they are scheduled after the end of the fixed period) and all TBTT scheduled before the end of the fixed period are delayed. Once fixed period will be over, chan_fix_ctxt_end will select the next channel to switch to and scheduling of channel switch will re-start on the following TBTT.

If this function is called during TBTT window, the switch is delayed until all TBTT are closed. The delay is done by setting CHAN_ENV_FIX_CTXT_PENDING_BIT status and when TBTT ends (chan_bcn_to_evt) this function is called back. Note that in this case (switch delayed) fix_until is still updated, so that chan_tbtt_skip_fix_ctxt will prevent TBTT that would be delayed when this function is called back

Parameters:

  `[in]` | ctxt | Channel context to force.

Definition at line 1622 of file chan.c.

References ASSERT_ERR, chan_add_next_tbtt(), chan_cancel_all_switch(), chan_env, CHAN_ENV_FIX_CTXT_PENDING_BIT, CHAN_ROC_SCAN_PENDING_MASK, chan_schedule_one_switch(), CHAN_SWITCH_DELAY, chan_switch_start(), chan_tbtt_pick(), chan_vif_tbtt_intv(), CO_BIT, chan_env_tag::current_ctxt, chan_ctxt_tag::duration_us, chan_env_tag::fix_ctxt, chan_env_tag::fix_until, hal_machw_time(), hal_machw_time_cmp(), chan_ctxt_tag::idx, chan_env_tag::nb_active_tbtt, chan_env_tag::status, chan_env_tag::switch_ctxt, chan_tbtt_tag::time, TR_32, TRACE_CHAN, chan_tbtt_tag::vif_index, and vif_info_tab.

Referenced by chan_conn_less_delay_evt().

static struct chan_ctxt_tag* chan_get_first_traf_ctxt | ( | void |  | ) | `[static, read]`

Get pointer to first active traffic channel context.

Returns:
  pointer to first active traffic channel context (can be NULL).

Definition at line 351 of file chan.c.

References chan_ctxt_pool, CHAN_CTXT_UNUSED, CHAN_TRAF_CTXT_CNT, and chan_ctxt_tag::idx.

Referenced by chan_fix_ctxt_end().

static struct chan_ctxt_tag* chan_get_next_traf_ctxt | ( | struct chan_ctxt_tag * | ctxt | ) | `[static, read]`

Get pointer to another traffic channel context.

Return pointer to the next active channel context associated to a vif, starting for channel context passed in parameter.

Parameters:

  `[in]` | ctxt | Channel context

Returns:
  pointer to another traffic channel context (can be NULL).

Definition at line 375 of file chan.c.

References chan_ctxt_pool, CHAN_CTXT_UNUSED, CHAN_TRAF_CTXT_CNT, and chan_ctxt_tag::idx.

Referenced by chan_schedule_extra_switch_from_p2pgo_ctxt(), chan_schedule_next_switch(), and chan_start_p2pgo_noa().

__INLINE bool chan_get_p2pgo | ( | struct vif_info_tag ** | p2pgo_vif | ) |

Return P2P GO interface.

Parameters:

  `[out]` | p2pgo_vif | Updated with pointer to vif structure for P2P GO interface.

Returns:
  true if a P2P GO interface exist and false otherwise

Definition at line 904 of file chan.c.

References chan_ctxt_pool, CHAN_CTXT_UNUSED, CHAN_TRAF_CTXT_CNT, chan_ctxt_tag::idx, INVALID_VIF_IDX, chan_ctxt_tag::p2pgo_vif_index, and vif_info_tab.

Referenced by chan_start_p2pgo_single_noa().

void chan_init | ( | void |  | ) |

MM Channel Module initialization function.

This function is called after reset and initializes all MM Channel related env and data.

bool chan_is_on_channel | ( | struct vif_info_tag * | vif | ) |

Check if the VIF passed as parameter has currently access to the channel.

Parameters:

  `[in]` | vif | Pointer to the VIF structure

Returns:
  true if the device is on channel, false otherwise

Referenced by tdls_chsw_time_evt().

bool chan_is_on_operational_channel | ( | struct vif_info_tag * | vif | ) |

Check if the VIF passed as parameter is currently on its operational channel.

Parameters:

  `[in]` | vif | Pointer to the VIF structure

Returns:
  true if the VIF is on its operational channel, false otherwise

__INLINE bool chan_is_p2p_go | ( | struct vif_info_tag * | vif | ) |

Test if a vif is a P2P GO.

Parameters:

  `[in]` | vif | VIF Entry

Returns:
  true is vif is a P2P GO interface and false otherwise

Definition at line 525 of file chan.c.

References vif_info_tag::p2p, vif_info_tag::p2p_index, p2p_info_tab, P2P_ROLE_GO, and p2p_info_tag::role.

Referenced by chan_add_next_tbtt().

bool chan_is_tx_allowed | ( | struct vif_info_tag * | vif | ) |

Check if transmission is allowed on a vif's channel.

Transmission is allowed as long as the vif is on the current channel and no channel switch is in progress. Exception: Transmitting NULL frame for notification of absence (i.e. status==CHAN_SENDING_NOA) is allowed during a channel switch

Parameters:

  `[in]` | vif | Pointer to the VIF structure

Returns:
  true if a frame can be pushed, false otherwise

Referenced by ps_dpsm_update(), and ps_uapsd_timer_handle().

static int chan_notify_absence | ( | void |  | ) | `[static]`

For each VIF linked with the channel context we are leaving, we send a NULL frame with the PM bit set to 1 in order to indicate our absence.

Returns:
  Number of NULL frame pushed.

Definition at line 2014 of file chan.c.

References vif_info_tag::active, chan_env_tag::cfm_cnt, vif_info_tag::chan_ctxt, chan_env, CHAN_SENDING_NOA, chan_tx_cfm(), chan_upd_ctxt_status(), CHAN_WAIT_NOA_CFM, CO_OK, chan_env_tag::current_ctxt, vif_info_tag::index, INVALID_STA_IDX, p2p_info_tag::is_go_present, mm_active(), vif_info_tag::p2p, vif_info_tag::p2p_index, p2p_info_tab, ps_env_tag::prevent_sleep, ps_env, ps_env_tag::ps_on, PS_PSM_PAUSED, vif_info_tag::sta, chan_ctxt_tag::status, chan_env_tag::switch_ctxt, TRACE_CHAN, txl_frame_send_null_frame(), vif_info_tag::type, vif_info_tag::u, vif_mgmt_first_used(), vif_mgmt_next(), and VIF_STA.

Referenced by chan_goto_idle_cb().

void chan_p2p_absence_update | ( | struct chan_ctxt_tag * | ctxt,
|  | bool | absence |
| ) |  |  |

Function used by the P2P module to notify the chan module about an update of presence status of a GO device.

Parameters:

  `[in]` | ctxt | Context linked to the p2p vif
  `[in]` | absence | True if GO is absent, false else

Referenced by p2p_update_go_ps_state().

static void chan_p2p_noa_resync | ( | struct vif_info_tag * | vif | ) | `[static]`

Move P2P GO TBTT and NOA to resyncrhonize with other AP's TBTT.

When P2P GO interface is active with multiple channel context NOA are started to allow context switch to respect TBTT on other (STA or P2P CLI) interfaces chan_start_p2pgo_noa. When a drift is detected between the P2P GO TBTT and other AP's TBTT, this function is called to move P2P GO TBTT and next occurence of NOA. The goal is to keep other AP's TBTT inside the programmed NOA.

Parameters:

  `[in]` | vif | VIF structure of the P2P GO interface

Definition at line 2393 of file chan.c.

References CHAN_TBTT_P2P_NOA_RESYNC, CHAN_TBTT_P2P_NOA_TSF_UPDATE, mm_ap_tbtt_move(), p2p_go_noa_concurrent_move(), chan_tbtt_tag::p2p_noa_tsf_update, chan_tbtt_tag::status, and vif_info_tag::tbtt_switch.

static void chan_p2p_noa_resync_check | ( | struct vif_info_tag * | vif,
|  | uint32_t | tbtt_time |
| ) |  |  | `[static]`

Check if drift in TBTT implies a resync (or restart) of NOA.

This is called when TBTT window starts on a VIF that induce a NOA on a P2P GO vif. It compares the time between this TBTT and the end of the induced NOA, with the value when the NOA has been created (chan_start_p2pgo_noa).

- If the delta, in absolute, is greater than CHAN_P2P_NOA_RESCHEDULE_THRESHOLD then it's too late and NOA will be restarted (i.e. chan_start_p2pgo_noa will be called)
- If the delta, in absolute, is greater than CHAN_P2P_NOA_RESCHEDULE_THRESHOLD then P2P GO TBTT and NOA will be resynced (chan_p2p_noa_resync). If there are several NOA, then delta is averaged among all NOA.

Parameters:

  `[in]` | vif | VIF that induce a NOA of the P2P GO interface
  `[in]` | tbtt_time | Date, in us, of the latest TBTT

Definition at line 2457 of file chan.c.

References CHAN_P2P_NOA_RESCHEDULE_THRESHOLD, CHAN_P2P_NOA_RESYNC_THRESHOLD, CHAN_TBTT_P2P_NOA_RESYNC, CHAN_TBTT_P2P_NOA_TSF_UPDATE, CHAN_TBTT_SCHEDULE_P2P_NOA, co_abs(), vif_info_tag::index, p2p_go_get_next_noa_end_date(), chan_tbtt_tag::p2p_noa_drift, chan_tbtt_tag::p2p_noa_index, chan_tbtt_tag::p2p_noa_tbtt_to_end, chan_tbtt_tag::p2p_noa_tsf_update, chan_tbtt_tag::p2p_noa_vif_index, chan_tbtt_tag::status, vif_info_tag::tbtt_switch, vif_info_tab, vif_mgmt_first_used(), and vif_mgmt_next().

static void chan_p2p_noa_tsf_updated | ( | struct vif_info_tag * | vif | ) | `[static]`

Post process after a TBTT move on a P2P GO interface.

When TBTT of a P2P GO interface is moved this function is called to update the mm_ap_pre_tbtt timer and the TBTT date in vif->tbtt_switch structure. This is called when the TBTT window of the P2P GO ends.

In some very unlikely cases, it may also reschedule context switches:

- This TBTT has been skipped by the CHAN module
- The last scheduled switch is based on previous TBTT date.

Parameters:

  `[in]` | vif | VIF structure of the P2P GO interface

Definition at line 2416 of file chan.c.

References chan_add_next_tbtt(), chan_cancel_all_switch(), chan_schedule_next_switch(), chan_switch_last(), CHAN_TBTT_P2P_NOA_TSF_UPDATE, CHAN_TBTT_PROG, hal_machw_time(), mm_timer_set(), chan_tbtt_tag::p2p_noa_tsf_update, chan_tbtt_tag::status, chan_switch_tag::tbtt, vif_info_tag::tbtt_switch, vif_info_tag::tbtt_timer, and mm_timer_tag::time.

static void chan_pre_switch_channel | ( | void |  | ) | `[static]`

Function called once SW and HW are ready for a channel switch.

It checks if ROC or SCAN are pending and if so change the target ctxt to this.

Definition at line 1885 of file chan.c.

References chan_ctxt_pool, chan_env, CHAN_ENV_ROC_BIT, CHAN_ENV_SCAN_BIT, CHAN_NOT_PROG, CHAN_ROC_CTXT_IDX, CHAN_SCAN_CTXT_IDX, chan_switch_channel(), chan_upd_ctxt_status(), CO_BIT, chan_env_tag::status, chan_env_tag::switch_ctxt, and TRACE_CHAN.

Referenced by chan_goto_idle_cb(), and chan_tx_cfm().

static void chan_reset_tbtt_list | ( | void |  | ) | `[static]`

Reset TBTT list in channel module.

Definition at line 2513 of file chan.c.

References chan_env, CHAN_TBTT_PROG, co_list_init(), chan_env_tag::list_tbtt, NX_VIRT_DEV_MAX, chan_tbtt_tag::status, vif_info_tag::tbtt_switch, and vif_info_tab.

void chan_scan_req | ( | uint8_t | band,
|  | uint16_t | freq,
|  | int8_t | pwr,
|  | uint32_t | duration_us,
|  | uint8_t | flags,
|  | uint8_t | vif_index |
| ) |  |  |

Request to go to a specific channel for scanning.

This function takes care on scheduling the channel switch at an appropriate time. Upon switching time, the MM channel will inform the AP(s) on which we are connected that we are going to power-save so that they start buffering the traffic for us.

Parameters:

  `[in]` | band | Band to be scanned (0: 2.4G, 1: 5G)
  `[in]` | freq | Frequency to be scanned
  `[in]` | pwr | Max power allowed (in dBm)
  `[in]` | duration_us | Duration of the scan on the requested channel
  `[in]` | flags | Channel flags (see mac_chan_flags)
  `[in]` | vif_index | Index of VIF on which scan will be performed

static bool chan_schedule_extra_switch_from_p2pgo_ctxt | ( | int | p2p_vif_index,
|  | uint32_t | now,
|  | uint32_t * | switch_date,
|  | uint32_t * | return_date |
| ) |  |  | `[static]`

Schedule a switch (and return) to other context when TBTT ends on a channel with a P2P GO interface.

Depending of P2P GO presence and its next scheduled NOA, the function checks if it is possible to switch to the other active channel :

- If the P2P GO interface is currently present, a switch can only be scheduled if the next p2p absence happens before the next TBTT (and is long enough).
- If the P2P GO interface is currently absent, switch immediately if absence period will last enough, or schedule a switch if another absence period happens before the the next TBTT (Both conditions can be true leading to schedule 4 switches in total)

Note:
  Because p2p_go_get_next_NOA_date only provides date for next NOA, the function assumes that only one NOA can happen until next TBTT. This should be true for NOA generated internally to support multiple channels, but not for NOA generated by host.

Parameters:

  `[in]` | p2p_vif_index | Vif index of the P2P GO interface
  `[in]` | now | Current date
  `[out]` | switch_date | Updated with the switch date
  `[in,out]` | return_date | Contain the latest date to return to P2P GO channel (including CHAN_SWITCH_DELAY), and may be updated if return must happen earlier.

Returns:
  true if a switch is possible (and in this case `switch_date` and `return_date` indicates the date) and false otherwise.

Definition at line 1220 of file chan.c.

References vif_info_tag::chan_ctxt, chan_get_next_traf_ctxt(), CHAN_MIN_PRES_DUR_US, chan_schedule_one_switch(), CHAN_SWITCH_DELAY, hal_machw_time_cmp(), p2p_go_get_next_NOA_date(), and vif_info_tab.

Referenced by chan_schedule_next_switch().

static bool chan_schedule_extra_switch_to_p2pgo_ctxt | ( | int | p2p_vif_index,
|  | uint32_t * | switch_date,
|  | uint32_t * | return_date |
| ) |  |  | `[static]`

Schedule a switch (and return) to a context with P2P GO interface when TBTT ends on a channel without a P2P GO interface.

Checks if a presence period will happen before the next TBTT and if so schedule switch to respect it. The NOA started by chan_start_p2pgo_noa should ensure that the P2P GO interface would be absent for this TBTT and the next one.

Note:
  Just like chan_schedule_extra_switch_from_p2pgo_ctxt the function assumes that only one presence period can happen until next TBTT.

Parameters:

  `[in]` | p2p_vif_index | Vif index of the P2P GO interface
  `[out]` | switch_date | Updated with the switch date
  `[in,out]` | return_date | Contain the latest date to return to P2P GO channel (including CHAN_SWITCH_DELAY), and may be updated if return must happen earlier.

Returns:
  true if a switch is possible (and in this case `switch_date` and `return_date` indicates the date) and false otherwise.

Definition at line 1301 of file chan.c.

References CHAN_SWITCH_DELAY, hal_machw_time_cmp(), p2p_go_get_next_NOA_date(), TR_32, TRACE_CHAN, and vif_info_tab.

Referenced by chan_schedule_next_switch().

static void chan_schedule_next_switch | ( | struct vif_info_tag * | vif,
|  | uint32_t | now,
|  | uint32_t | tbtt_dur |
| ) |  |  | `[static]`

Schedule all channel switches from end of current TBTT until next TBTT.

This function is called at each end of TBTT and schedules switches until next TBTT. (When this function is called there are necessarily two active channels contexts)

There are two main cases: 1. The next TBTT is on the same channel In this case check if it's possible to stay at least CHAN_MIN_PRES_DUR_US on the other active channel and come back before next TBTT. If it's not possible no switch are scheduled.

2. The Next TBTT is on another channel. Tests done on chan_add_next_tbtt ensure that we can switch to the other channel before its TBTT starts. The function simply schedules the switch to share time between both channels.

Note: In normal case, when this function is called current channel is the channel of the TBTT. But it may not always be the case: The switch took more that expected (CHAN_SWITCH_DELAY). In this case act like we are on the TBTT channel.

Parameters:

  `[in]` | vif | Vif of the current TBTT.
  `[in]` | now | Date of end of current TBTT.
  `[in]` | tbtt_dur | Duration spent on channel for the TBTT, in us.

Definition at line 1499 of file chan.c.

References vif_info_tag::chan_ctxt, chan_env, chan_get_next_traf_ctxt(), CHAN_MIN_PRES_DUR_US, chan_schedule_extra_switch_from_p2pgo_ctxt(), chan_schedule_extra_switch_to_p2pgo_ctxt(), chan_schedule_one_switch(), chan_schedule_switch_from_p2pgo_ctxt(), chan_schedule_switch_to_p2pgo_ctxt(), chan_share_medium(), CHAN_SWITCH_DELAY, chan_tbtt_pick(), chan_env_tag::current_ctxt, chan_ctxt_tag::idx, INVALID_VIF_IDX, chan_tbtt_tag::p2p_noa_vif_index, chan_ctxt_tag::p2pgo_vif_index, chan_ctxt_tag::status, vif_info_tag::tbtt_switch, chan_tbtt_tag::time, TRACE_CHAN, chan_tbtt_tag::vif_index, and vif_info_tab.

Referenced by chan_p2p_noa_tsf_updated().

static void chan_schedule_one_switch | ( | uint32_t | date,
|  | struct chan_ctxt_tag * | ctxt,
|  | struct chan_tbtt_tag * | tbtt |
| ) |  |  | `[static]`

Schedule a channel switch.

Parameters:

  `[in]` | date | Date of the switch (absolute timestamp in us)
  `[in]` | ctxt | Channel context to switch to
  `[in]` | tbtt | TBTT information that cause this switch (may be NULL)

Definition at line 1175 of file chan.c.

References chan_switch_alloc(), chan_switch_no_schedule(), chan_switch_push_back(), chan_switch_set_timer(), chan_switch_tag::ctxt, chan_ctxt_tag::idx, chan_switch_tag::tbtt, chan_switch_tag::time, TR_32, and TRACE_CHAN.

Referenced by chan_fix_ctxt_until(), chan_schedule_extra_switch_from_p2pgo_ctxt(), chan_schedule_next_switch(), chan_schedule_switch_from_p2pgo_ctxt(), and chan_schedule_switch_to_p2pgo_ctxt().

static void chan_schedule_switch_from_p2pgo_ctxt | ( | int | p2p_vif_index,
|  | struct chan_ctxt_tag * | next_ctxt,
|  | uint32_t | now,
|  | uint32_t * | switch_date |
| ) |  |  | `[static]`

Schedule a switch when TBTT window ends, from a context with a P2P GO interface to another context.

The NOA started by chan_start_p2pgo_noa (should) ensure that the P2P GO interface will be in an absence period for the TBTT on the next context. Still a presence period can happen before next TBTT, and in this case 2 extra switches will be scheduled.

Parameters:

  `[in]` | p2p_vif_index | Vif index of the P2P GO interface
  `[in]` | next_ctxt | Pointer to the otehr context
  `[in]` | now | Current date
  `[in,out]` | switch_date | Contain the latest date to switch from P2P GO channel (including CHAN_SWITCH_DELAY), and may be updated if switch can happen earlier.

Definition at line 1355 of file chan.c.

References vif_info_tag::chan_ctxt, CHAN_MIN_PRES_DUR_US, chan_schedule_one_switch(), CHAN_SWITCH_DELAY, hal_machw_time_cmp(), p2p_go_get_next_NOA_date(), TR_32, TRACE_CHAN, and vif_info_tab.

Referenced by chan_schedule_next_switch().

static void chan_schedule_switch_to_p2pgo_ctxt | ( | int | p2p_vif_index,
|  | struct chan_ctxt_tag * | ctxt,
|  | uint32_t | now,
|  | uint32_t * | switch_date |
| ) |  |  | `[static]`

Schedule a switch from a context without P2P GO interface when TBTT ends to a context with P2P GO interface .

Schedule switch to match next presence period or the next TBTT (whichever happens first). Still a absence period can happen before TBTT and in this case 2 extra switches will be scheduled.

Parameters:

  `[in]` | p2p_vif_index | Vif index of the P2P GO interface
  `[in]` | ctxt | Context of the current ending TBTT window
  `[in]` | now | Current date
  `[in,out]` | switch_date | Contain the latest date to switch to P2P GO channel (including CHAN_SWITCH_DELAY), and may be updated if switch must happen earlier.

Definition at line 1431 of file chan.c.

References vif_info_tag::chan_ctxt, CHAN_MIN_PRES_DUR_US, chan_schedule_one_switch(), CHAN_SWITCH_DELAY, hal_machw_time_cmp(), p2p_go_get_next_NOA_date(), TR_32, TRACE_CHAN, and vif_info_tab.

Referenced by chan_schedule_next_switch().

static void chan_send_force_idle | ( | void |  | ) | `[static]`

Send a MM_FORCE_IDLE_REQ message to TASK_MM in order to require the HW to enter in IDLE mode.

Definition at line 2122 of file chan.c.

References mm_force_idle_req::cb, chan_goto_idle_cb(), KE_MSG_ALLOC, ke_msg_send(), MM_FORCE_IDLE_REQ, and TASK_MM.

Referenced by chan_switch_start().

static void chan_send_pre_switch_ind | ( | struct chan_ctxt_tag * | old_ctxt | ) | `[static]`

Send CHANNEL_PRE_SWITCH_IND message to the upper layers.

Host should stop pushing packets for transmission after reception of this message.

Parameters:

  `[in]` | old_ctxt | Channel context we are about to leave

Definition at line 404 of file chan.c.

References mm_channel_pre_switch_ind::chan_index, CHAN_SCAN_CTXT_IDX, chan_ctxt_tag::idx, KE_MSG_ALLOC, ke_msg_send(), MM_CHANNEL_PRE_SWITCH_IND, and TASK_MM.

Referenced by chan_switch_start().

static void chan_send_roc_exp_ind | ( | struct chan_ctxt_tag * | ctxt | ) | `[static]`

Send MM_REMAIN_ON_CHANNEL_EXP_IND message to the upper layers.

It informs the host that the remain on channel has expired.

Parameters:

  `[in]` | ctxt | Pointer to the RoC Channel Context

Definition at line 504 of file chan.c.

References mm_remain_on_channel_exp_ind::chan_ctxt_index, chan_ctxt_tag::idx, KE_MSG_ALLOC, ke_msg_send(), MM_REMAIN_ON_CHANNEL_EXP_IND, TASK_MM, chan_ctxt_tag::taskid, chan_ctxt_tag::vif_index, and mm_remain_on_channel_exp_ind::vif_index.

Referenced by chan_conn_less_ctxt_end().

static void chan_send_switch_ind | ( | struct chan_ctxt_tag * | new_ctxt | ) | `[static]`

Send CHANNEL_SWITCH_IND message to the upper layers.

Host can start pushing packets for transmission after reception of this message.

Parameters:

  `[in]` | new_ctxt | Channel context on which we have switched

Definition at line 428 of file chan.c.

References mm_channel_switch_ind::chan_index, CHAN_ROC_CTXT_IDX, CHAN_SCAN_CTXT_IDX, chan_ctxt_tag::idx, KE_MSG_ALLOC, ke_msg_send(), MM_CHANNEL_SWITCH_IND, mm_channel_switch_ind::roc, mm_channel_switch_ind::roc_tdls, TASK_MM, TASK_TDLS, chan_ctxt_tag::taskid, chan_ctxt_tag::vif_index, and mm_channel_switch_ind::vif_index.

Referenced by chan_switch_channel().

static uint32_t chan_share_medium | ( | int32_t | dur_to_split,
|  | uint32_t | dur_spent,
|  | uint32_t | now |
| ) |  |  | `[static]`

Share time between two channel context.

For now do a 50/50 share between channels. To be updated

Parameters:

  `[in]` | dur_to_split | Time, in us, to share between the channels (not including dur_spent).
  `[in]` | dur_spent | Time, in us, already spent on current channel.
  `[in]` | now | Current time (absolute timestamp in us)

Returns:
  date of the switch.

Definition at line 1156 of file chan.c.

Referenced by chan_schedule_next_switch().

static void chan_start_p2pgo_noa | ( | struct vif_info_tag * | p2pgo_vif | ) | `[static]`

Start concurrent NOA for a P2P GO interface.

When a P2P GO is created and there are several active channel, it is necessary to start NOA (Notice of Absence) on the P2P GO interface to spend time on the other active channel. Indeed the P2P GO interface only needs to be present when not inside an absence period.

This function will:

- Start a periodic NOA for each interface on the other channel. For now the duration on this NOA is selected so that the P2P GO interface is absent half the time (To be updated to adapt repartition based on traffic)
- If two interfaces share the same beacon interval and their beacon are close enough then only one NOA will be started for both interfaces

Parameters:

  `[in]` | p2pgo_vif | VIF entry for the P2P GO interface

Definition at line 659 of file chan.c.

References ASSERT_ERR, vif_info_tag::chan_ctxt, chan_env, chan_get_next_traf_ctxt(), chan_stop_p2pgo_noa(), CHAN_SWITCH_DELAY, CHAN_TBTT_P2P_NOA_TSF_UPDATE, chan_vif_tbtt_dur(), chan_vif_tbtt_intv(), chan_window_merge_duration(), CO_BIT, co_min(), chan_window::end, hal_machw_time(), hal_machw_time_cmp(), hal_machw_time_past(), chan_ctxt_tag::idx, vif_info_tag::index, INVALID_VIF_IDX, mm_ap_tbtt_move(), chan_ctxt_tag::nb_linked_vif, chan_env_tag::nb_sched_ctxt, NX_VIRT_DEV_MAX, p2p_go_noa_start(), P2P_NOA_CONTINUOUS_COUNTER, chan_tbtt_tag::p2p_noa_drift, chan_tbtt_tag::p2p_noa_index, P2P_NOA_NB_MAX, chan_tbtt_tag::p2p_noa_tbtt_to_end, chan_tbtt_tag::p2p_noa_tsf_update, chan_tbtt_tag::p2p_noa_vif_index, chan_ctxt_tag::p2pgo_vif_index, chan_window::start, chan_tbtt_tag::status, vif_info_tag::tbtt_switch, vif_info_tag::tbtt_timer, mm_timer_tag::time, TR_32, TRACE_CHAN, vif_info_tab, vif_mgmt_first_used(), and vif_mgmt_next().

static bool chan_start_p2pgo_single_noa | ( | struct vif_info_tag * | vif,
|  | uint32_t | start,
|  | struct chan_tbtt_tag * | tbtt |
| ) |  |  | `[static]`

Start a non-periodic NOA on a P2P GO interface.

When a TBTT must be skipped for a P2P GO interface, a non periodic NOA must be started to inform client. Indeed P2P GO must be present for TBTT even during periodic NOA.

Parameters:

  `[in]` | vif | Vif structure for P2P GO interface.
  `[in]` | start | Timestamp, in us, of the skipped TBTT.
  `[in]` | tbtt | TBTT (of another vif) that induces this NOA. (may be NULL)

Returns:
  true if NOA has been started and false otherwise.

Definition at line 933 of file chan.c.

References chan_get_p2pgo(), CHAN_SWITCH_DELAY, chan_vif_tbtt_dur(), chan_vif_tbtt_intv(), hal_machw_time_cmp(), INVALID_VIF_IDX, p2p_go_get_next_noa_end_date(), p2p_go_noa_start(), P2P_INVALID_IDX, chan_tbtt_tag::p2p_noa_index, chan_tbtt_tag::p2p_noa_vif_index, chan_tbtt_tag::time, chan_tbtt_tag::vif_index, and vif_info_tab.

Referenced by chan_add_next_tbtt().

static void chan_stop_p2pgo_noa | ( | struct vif_info_tag * | p2pgo_vif | ) | `[static]`

Stop concurrent NOA for a P2P GO interface.

Parameters:

  `[in]` | p2pgo_vif | VIF entry for the P2P GO interface

Definition at line 616 of file chan.c.

References vif_info_tag::index, INVALID_VIF_IDX, p2p_info_tag::noa, p2p_noa_info_tag::noa_status, p2p_noa_info_tag::noa_type, p2p_go_noa_stop(), vif_info_tag::p2p_index, p2p_info_tab, P2P_NOA_NB_MAX, P2P_NOA_TIMER_NOT_STARTED, P2P_NOA_TYPE_CONCURRENT, chan_tbtt_tag::p2p_noa_vif_index, vif_info_tag::tbtt_switch, vif_mgmt_first_used(), and vif_mgmt_next().

Referenced by chan_start_p2pgo_noa().

__INLINE struct chan_switch_tag* chan_switch_alloc | ( | void |  | ) | `[read]`

Allocate a channel switch information element.

Returns:
  Pointer to allocated channel switch information element

Definition at line 217 of file chan.c.

References ASSERT_ERR, chan_env, co_list_pop_front(), and chan_env_tag::list_free_switch.

Referenced by chan_schedule_one_switch().

static void chan_switch_channel | ( | void |  | ) | `[static]`

Switch from chan_env.current_ctxt to chan_env.switch_ctxt.

HW is supposed to be in IDLE mode when entering in this function. current_ctxt value is replaced by chan_switch value and chan_switch is set to NULL.

Definition at line 2141 of file chan.c.

References mac_chan_op::band, mm_env_tag::basic_rates, vif_info_tag::chan_ctxt, chan_env, CHAN_NOT_PROG, chan_notify_presence(), CHAN_ROC_CTXT_IDX, CHAN_SCAN_CTXT_IDX, chan_send_switch_ind(), CHAN_TRAF_CTXT_CNT, chan_upd_ctxt_status(), CHAN_WAITING_END, chan_ctxt_tag::channel, co_list_next(), chan_env_tag::current_ctxt, GLOBAL_INT_DISABLE, GLOBAL_INT_RESTORE, chan_ctxt_tag::idx, vif_info_tag::index, ke_msg_send_basic(), vif_info_tag::list_hdr, mm_active(), MM_CHAN_CTXT_SCHED_CFM, mm_env, MM_SCAN_CHANNEL_START_IND, PHY_PRIM, phy_set_channel(), chan_env_tag::pm, ps_env_tag::prevent_sleep, mac_chan_op::prim20_freq, PROF_CHAN_CTXT_IDX_SET, PROF_CHAN_CTXT_SWITCH_CLR, PROF_MM_SET_CHANNEL_CLR, PROF_MM_SET_CHANNEL_SET, ps_env, PS_SCAN_ONGOING, chan_env_tag::switch_ctxt, TASK_MM, TASK_SCAN, chan_ctxt_tag::taskid, td_env_tab, tpc_update_tx_power(), TRACE_CHAN, mac_chan_op::tx_power, mac_chan_op::type, vif_mgmt_first_used(), and vif_mgmt_send_postponed_frame().

Referenced by chan_pre_switch_channel().

__INLINE void chan_switch_free | ( | struct chan_switch_tag * | ch_switch | ) |

Free a channel switch information element.

Parameters:

  `[in]` | ch_switch | Channel switch information to free

Definition at line 232 of file chan.c.

References chan_env, co_list_push_back(), chan_env_tag::list_free_switch, and chan_switch_tag::list_hdr.

Referenced by chan_cancel_all_switch(), and chan_tmr_switch_cb().

__INLINE struct chan_switch_tag* chan_switch_last | ( | void |  | ) | `[read]`

Get last element of scheduled channel switch list.

Returns:
  Pointer to last scheduled channel switch information (can be NULL)

Definition at line 181 of file chan.c.

References chan_env, co_list_pick_last(), and chan_env_tag::list_switch.

Referenced by chan_p2p_noa_tsf_updated(), and chan_tbtt_skip_fix_ctxt().

__INLINE bool chan_switch_no_schedule | ( | void |  | ) |

Check is scheduled channel switch list is empty.

Returns:
  true is no channel switch is scheduled and false otherwise.

Definition at line 205 of file chan.c.

References chan_env, co_list_is_empty(), and chan_env_tag::list_switch.

Referenced by chan_schedule_one_switch(), and chan_tbtt_skip_fix_ctxt().

__INLINE struct chan_switch_tag* chan_switch_pick | ( | void |  | ) | `[read]`

Get first element of scheduled channel switch list.

Returns:
  Pointer to next scheduled channel switch information (can be NULL)

Definition at line 169 of file chan.c.

References chan_env, co_list_pick(), and chan_env_tag::list_switch.

Referenced by chan_tmr_switch_cb().

__INLINE struct chan_switch_tag* chan_switch_pop | ( | void |  | ) | `[read]`

Extract first element of scheduled channel switch list.

Returns:
  Pointer to next scheduled channel switch information (can be NULL)

Definition at line 157 of file chan.c.

References chan_env, co_list_pop_front(), and chan_env_tag::list_switch.

Referenced by chan_cancel_all_switch(), and chan_tmr_switch_cb().

__INLINE void chan_switch_push_back | ( | struct chan_switch_tag * | ch_switch | ) |

Insert on element at the end of the scheduled channel switch list.

Parameters:

  `[in]` | ch_switch | Channel switch information

Definition at line 193 of file chan.c.

References chan_env, co_list_push_back(), chan_switch_tag::list_hdr, and chan_env_tag::list_switch.

Referenced by chan_schedule_one_switch().

__INLINE void chan_switch_set_timer | ( | struct chan_switch_tag * | ch_switch | ) |

Configure timer for next channel switch.

Parameters:

  `[in]` | ch_switch | Channel switch information

Definition at line 127 of file chan.c.

References mm_timer_tag::cb, chan_env, mm_timer_tag::env, hal_machw_time_past(), mm_timer_set(), chan_switch_tag::time, and chan_env_tag::tmr_switch.

Referenced by chan_schedule_one_switch(), and chan_tmr_switch_cb().

static void chan_switch_start | ( | struct chan_ctxt_tag * | ctxt | ) | `[static]`

Initiate channel switch procedure in order to jump to indicated channel.

If we already are present on provided channel or if a switch procedure is already in progress, nothing is done. Else requests the HW to go in IDLE state.

Parameters:

  `[in]` | ctxt | Channel context on which switch is required

Definition at line 2250 of file chan.c.

References AC_BCN, chan_env, CHAN_GOTO_IDLE, chan_send_force_idle(), chan_send_pre_switch_ind(), chan_upd_ctxt_status(), CHAN_WAITING_END, chan_env_tag::current_ctxt, DESC_DONE_SW_TX_BIT, GLOBAL_INT_DISABLE, GLOBAL_INT_RESTORE, chan_ctxt_tag::idx, mm_bcn_transmitting(), PROF_CHAN_CTXT_WAIT_END_CLR, chan_env_tag::switch_ctxt, TRACE_CHAN, txl_cntrl_flush_ac(), and txl_cntrl_halt_ac().

Referenced by chan_fix_ctxt_until(), and chan_tmr_switch_cb().

__INLINE void chan_tbtt_insert_before | ( | struct chan_tbtt_tag * | tbtt,
|  | struct chan_tbtt_tag * | tbtt_next |
| ) |  |  |

Insert TBTT before another TBTT.

Parameters:

  `[in]` | tbtt | TBTT to add in the list.
  `[in]` | tbtt_next | TBTT before which new element must be added.

Definition at line 283 of file chan.c.

References chan_env, CHAN_TBTT_PROG, co_list_insert_before(), chan_tbtt_tag::list_hdr, chan_env_tag::list_tbtt, and chan_tbtt_tag::status.

Referenced by chan_add_next_tbtt().

__INLINE struct chan_tbtt_tag* chan_tbtt_next | ( | struct chan_tbtt_tag * | tbtt | ) | `[read]`

Get next element of tbtt list.

Parameters:

  `[in]` | tbtt | TBTT.

Returns:
  Pointer to next TBTT (can be NULL).

Definition at line 257 of file chan.c.

References chan_tbtt_tag::list_hdr, and co_list_hdr::next.

Referenced by chan_add_next_tbtt().

static bool chan_tbtt_overlap | ( | struct chan_tbtt_tag * | tbtt1,
|  | struct chan_tbtt_tag * | tbtt2 |
| ) |  |  | `[static]`

Check if TBTT constraint for two vifs overlap.

Parameters:

  `[in]` | tbtt1 | TBTT information of first vif
  `[in]` | tbtt2 | TBTT information of second vif

Returns:
  true if TBTTs overlap and false otherwise.

Definition at line 989 of file chan.c.

References vif_info_tag::chan_ctxt, CHAN_SWITCH_DELAY, chan_vif_tbtt_dur(), hal_machw_time_cmp(), chan_tbtt_tag::time, chan_tbtt_tag::vif_index, and vif_info_tab.

Referenced by chan_add_next_tbtt().

__INLINE struct chan_tbtt_tag* chan_tbtt_pick | ( | void |  | ) | `[read]`

Get first element of tbtt list.

Returns:
  Pointer to next TBTT (can be NULL).

Definition at line 244 of file chan.c.

References chan_env, co_list_pick(), and chan_env_tag::list_tbtt.

Referenced by chan_add_next_tbtt(), chan_fix_ctxt_end(), chan_fix_ctxt_until(), and chan_schedule_next_switch().

__INLINE void chan_tbtt_remove | ( | struct chan_tbtt_tag * | tbtt | ) |

Remove TBTT form the list.

Parameters:

  `[in]` | tbtt | TBTT element to remove from the list.

Definition at line 269 of file chan.c.

References chan_env, CHAN_TBTT_PROG, co_list_extract(), chan_tbtt_tag::list_hdr, chan_env_tag::list_tbtt, and chan_tbtt_tag::status.

Referenced by chan_add_next_tbtt().

__INLINE bool chan_tbtt_skip_fix_ctxt | ( | uint32_t | tbtt_time,
|  | struct chan_ctxt_tag * | ctxt |
| ) |  |  |

Check if TBTT must be skipped because of scheduled switch or fix channel.

Check if the TBTT scheduled at `tbtt_time` on channel context `ctxt` have to be skipped. There are two conditions that may force to skip the TBTT: 1. If there are already scheduled channel switchs: (to avoid useless complexity, only the last scheduled switch is taken into account)

- If the target channel of this switch is the same as the channel passed in parameter the function checks that the channel will be active at `tbbt_time` (i.e. switch starts at least CHAN_SWITCH_DELAY us before `tbtt_time`). This assumes that the switch cannot be scheduled early because of other constraint.

- If the target channel is not the same, then the function checks if it's possible to switch to the new channel after the scheduled switch and be present at `tbtt_time` (i.e. if `tbtt_time` happens CHAN_SWITCH_DELAY us after the end of the switch)

Note: This case can only happen when a new vif is started. Indeed, channel switches are scheduled at each TBTT until next TBTT, so when this function is called (at TBTT) the list will always be empty unless this is the first TBTT of a vif.

2. Because of fix channel context: If a fix channel context is currently set, the function checks if the fix channel is the same as the target or if "fix period" ends at least CHAN_SWITCH_DELAY before `tbtt_time`.

Parameters:

  `[in]` | tbtt_time | Date of the TBTT (absolute timestamp in us)
  `[in]` | ctxt | Channel context of the TBTT

Returns:
  true if it won't be possible to have channel `ctxt` active at `tbtt_time`, false otherwise.

Definition at line 1045 of file chan.c.

References chan_env, CHAN_SWITCH_DELAY, chan_switch_last(), chan_switch_no_schedule(), chan_vif_tbtt_dur(), chan_switch_tag::ctxt, chan_env_tag::fix_ctxt, chan_env_tag::fix_until, hal_machw_time_cmp(), chan_switch_tag::tbtt, chan_switch_tag::time, chan_tbtt_tag::vif_index, and vif_info_tab.

Referenced by chan_add_next_tbtt().

int chan_tbtt_start | ( | struct vif_info_tag * | vif,
|  | uint32_t | tbtt_time,
|  | uint32_t | next_tbtt_time |
| ) |  |  |

Indicates that TBTT starts and provides date of the next TBTT.

It is called by MM module to indicate that TBTT starts. It also indicates expected date of the next TBTT. As the next TBTT date may be updated after beacon reception (chan_tbtt_updated) this function simply checks if this TBTT is expected (from CHAN module point of view). and waits for chan_bcn_to_evt to process it.

Parameters:

  `[in]` | vif | VIF Entry
  `[in]` | tbtt_time | Time of current TBTT
  `[in]` | next_tbtt_time | Time of next TBTT

Returns:
  0 If vif can send frame (i.e. vif's channel is the current active channel) and !=0 otherwise

Referenced by mm_ap_tbtt().

void chan_tbtt_updated | ( | struct vif_info_tag * | vif | ) |

Called when TBTT timer has been updated after beacon reception.

If this function is called in a "TBTT window", the fucntion will retrun immediately as update will be handled in chan_bcn_to_evt.

If this function is called outside of "TBTT window" it will update TBTT info for this vif.

Parameters:

  `[in]` | vif | VIF Entry

static void chan_tmr_switch_cb | ( | void * | env | ) | `[static]`

Timer callback for channel switch.

When this callback is called it's time to:

- Select the next channel if it's the end on a fixed period.
- Start switch to the next channel (if any).
- Process end of current channel (for connection-lestt contexts only)
- Program timer for next switch (if any).

Parameters:

  `[in]` | env | Channel context to switch to

Definition at line 1856 of file chan.c.

References ASSERT_ERR, chan_conn_less_ctxt_end(), chan_env, chan_fix_ctxt_end(), CHAN_NOT_PROG, chan_switch_free(), chan_switch_pick(), chan_switch_pop(), chan_switch_set_timer(), chan_switch_start(), CHAN_TRAF_CTXT_CNT, chan_upd_ctxt_status(), chan_switch_tag::ctxt, chan_env_tag::current_ctxt, chan_env_tag::fix_ctxt, and chan_ctxt_tag::idx.

static void chan_tx_cfm | ( | void * | dummy,
|  | uint32_t | status |
| ) |  |  | `[static]`

Function called during the Channel Switch procedure each time a NULL packet used for Absence indication is confirmed.

The cfm_cnt counter value in the chan environment is decremented. When its value comes to 0, we can switch on a new channel.

Parameters:

  `[in]` | dummy | Pointer to env passed when pushing the frame. (NULL in this case)
  `[in]` | status | Status of the transmission of NULL packet.

Definition at line 1931 of file chan.c.

References ASSERT_ERR, chan_env_tag::cfm_cnt, chan_env, chan_pre_switch_channel(), mm_force_idle_req(), TR_32, and TRACE_CHAN.

Referenced by chan_notify_absence().

static void chan_upd_ctxt_status | ( | struct chan_ctxt_tag * | ctxt,
|  | uint8_t | status |
| ) |  |  | `[static]`

Update the status of a provided channel context.

Parameters:

  `[in]` | ctxt | Channel Context entry
  `[in]` | status | New status of the provided channel context

Definition at line 338 of file chan.c.

References chan_ctxt_tag::idx, chan_ctxt_tag::status, and TRACE_CHAN.

Referenced by chan_notify_absence(), chan_pre_switch_channel(), chan_switch_channel(), chan_switch_start(), and chan_tmr_switch_cb().

void chan_update_tx_power | ( | struct chan_ctxt_tag * | ctxt | ) |

Update TX power for a channel context.

Set tx_power to the minimum value allowed among all vifs linked to this channel context. This power value is used to configure tx power used in frame generated by HW (Ack,...). Data frame will use the tx power configured at vif level.

Parameters:

  `[in]` | ctxt | Channel context to update.

Referenced by tpc_set_vif_tx_power().

static uint32_t chan_vif_tbtt_dur | ( | struct vif_info_tag * | vif | ) | `[static]`

Get TBTT duration for a vif.

For now fixed to VIF_MGMT_BCN_TO_DUR.

Parameters:

  `[in]` | vif | Vif structure

Returns:
  TBTT duration in us.

Definition at line 325 of file chan.c.

References VIF_MGMT_BCN_TO_DUR.

Referenced by chan_add_next_tbtt(), chan_start_p2pgo_noa(), chan_start_p2pgo_single_noa(), chan_tbtt_overlap(), and chan_tbtt_skip_fix_ctxt().

static uint32_t chan_vif_tbtt_intv | ( | struct vif_info_tag * | vif | ) | `[static]`

Get TBTT interval for a vif.

Parameters:

  `[in]` | vif | Vif structure

Returns:
  TBTT interval in us.

Definition at line 298 of file chan.c.

References vif_info_tag::ap, sta_info_tag::bcn_int, vif_info_tag::sta, sta_info_tab, TRACE_CHAN, vif_info_tag::type, vif_info_tag::u, VIF_AP, and VIF_STA.

Referenced by chan_add_next_tbtt(), chan_fix_ctxt_until(), chan_start_p2pgo_noa(), and chan_start_p2pgo_single_noa().

static uint32_t chan_window_merge_duration | ( | struct chan_window * | w1,
|  | struct chan_window * | w2,
|  | struct chan_window * | w_res,
|  | uint32_t | interval |
| ) |  |  | `[static]`

Return the minimal window that contains both window.

Given two recursive window (same interval), this functions return the width on the minimal window that would contains both windows.

Parameters:

  `[in]` | w1 | First window
  `[in]` | w2 | Second window
  `[out]` | w_res | Updated with the result window (can be NULL)
  `[in]` | interval | Window interval in us

Returns:
  Width, in us, of the result window.

Definition at line 546 of file chan.c.

References chan_window::end, hal_machw_time_cmp(), and chan_window::start.

Referenced by chan_start_p2pgo_noa().