# SCAN_TASK
[SCAN]

Task responsible for scanning process. More...

Collaboration diagram for SCAN_TASK:

## Data Structures
struct | scan_start_req
| Structure containing the parameters of the SCAN_START_REQ message. More...
struct | scan_start_cfm
| Structure containing the parameters of the SCAN_START_CFM message. More...
struct | scan_cancel_cfm
| Structure containing the parameters of the SCAN_START_CFM message. More...
## Defines
#define | SCAN_IDX_MAX 1
| SCAN TASK Instance Max.
## Enumerations
enum | scan_state_tag { SCAN_IDLE, SCAN_WAIT_IE_DWNLD, SCAN_WAIT_CHANNEL, SCAN_WAIT_BEACON_PROBE_RSP, SCAN_STATE_MAX }
| Possible States of the MM STA Task. More...
enum | scan_msg_tag { SCAN_START_REQ = KE_FIRST_MSG(TASK_SCAN), SCAN_START_CFM, SCAN_DONE_IND, SCAN_CANCEL_REQ, SCAN_CANCEL_CFM, SCAN_TIMER, SCAN_MAX }
| List of messages related to the task. More...
## Functions
static int | scan_start_req_handler (ke_msg_id_t const msgid, struct scan_start_req const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id)
| SCAN start request message handler.
static int | scan_cancel_req_handler (ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id)
| SCAN cancel request message handler.
static int | mm_scan_channel_start_ind_handler (ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id)
| MM set scan channel confirmation handler.
static int | mm_scan_channel_end_ind_handler (ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id)
| MM set scan channel confirmation handler.
## Variables
struct ke_msg_handler | scan_default_state []
| Message handlers in state DEFAULT.
struct ke_state_handler | scan_default_handler
| Specifies the message handlers that are common to all states.
ke_state_t | scan_state [SCAN_IDX_MAX]
| Defines the placeholder for the states of all the task instances.
struct ke_state_handler | scan_default_handler
| Specifies the message handlers that are common to all states.
ke_state_t | scan_state [SCAN_IDX_MAX]
| Defines the placeholder for the states of all the task instances.

## Detailed Description

Task responsible for scanning process.

## Enumeration Type Documentation

enum scan_msg_tag

List of messages related to the task.

Enumerator:

  SCAN_START_REQ | Scanning start Request.
  SCAN_START_CFM | Scanning start Confirmation.
  SCAN_DONE_IND | End of scanning indication.
  SCAN_CANCEL_REQ | Cancel scan request.
  SCAN_CANCEL_CFM | Cancel scan confirmation.
  SCAN_MAX | MAX number of messages.

Definition at line 63 of file scan_task.h.

enum scan_state_tag

Possible States of the MM STA Task.

Enumerator:

  SCAN_IDLE | SCAN IDLE State.
  SCAN_WAIT_IE_DWNLD | Wait ProbeReq IE download.
  SCAN_WAIT_CHANNEL | SCAN Wait for channel State.
  SCAN_WAIT_BEACON_PROBE_RSP | Wait for beacon and probe responses State.
  SCAN_STATE_MAX | SCAN Max Number of states.

Definition at line 48 of file scan_task.h.

## Function Documentation

static int mm_scan_channel_end_ind_handler | ( | ke_msg_id_t const | msgid,
|  | void const * | param,
|  | ke_task_id_t const | dest_id,
|  | ke_task_id_t const | src_id |
| ) |  |  | `[static]`

MM set scan channel confirmation handler.

This function handles the MM_SCAN_CHANNEL_END_IND message, which indicates that the scanning period on the channel is over. If there are other channels to scan, it starts scan on the next channel. If scan is over (or aborted), it frees scan parameter and sends indication to the task that request the scan.

Parameters:

  `[in]` | msgid | Id of the message received.
  `[in]` | param | Pointer to the parameters of the message.
  `[in]` | dest_id | TaskId of the receiving task.
  `[in]` | src_id | TaskId of the sending task.

Returns:
  Whether the message was consumed or not.

Definition at line 191 of file scan_task.c.

References scan_env_tag::abort, ASSERT_ERR, scan_start_req::chan_cnt, scan_env_tag::chan_idx, CO_OK, KE_MSG_CONSUMED, ke_msg_free(), ke_msg_send_basic(), ke_param2msg(), ke_state_get(), ke_state_set(), mm_rx_filter_lmac_enable_clear(), scan_env_tag::param, scan_env_tag::req_id, SCAN_DONE_IND, scan_env, SCAN_IDLE, scan_send_cancel_cfm(), scan_set_channel_request(), SCAN_WAIT_BEACON_PROBE_RSP, and TASK_SCAN.

static int mm_scan_channel_start_ind_handler | ( | ke_msg_id_t const | msgid,
|  | void const * | param,
|  | ke_task_id_t const | dest_id,
|  | ke_task_id_t const | src_id |
| ) |  |  | `[static]`

MM set scan channel confirmation handler.

This function handles the MM_SCAN_CHANNEL_START_IND message, which confirms the switch to the scanned channel.

Parameters:

  `[in]` | msgid | Id of the message received.
  `[in]` | param | Pointer to the parameters of the message.
  `[in]` | dest_id | TaskId of the receiving task.
  `[in]` | src_id | TaskId of the sending task.

Returns:
  Whether the message was consumed or not.

Definition at line 150 of file scan_task.c.

References ASSERT_ERR, scan_start_req::chan, scan_env_tag::chan_idx, CHAN_NO_IR, mac_chan_def::flags, KE_MSG_CONSUMED, ke_state_get(), ke_state_set(), mm_rx_filter_lmac_enable_set(), scan_env_tag::param, scan_env, scan_probe_req_tx(), SCAN_WAIT_BEACON_PROBE_RSP, SCAN_WAIT_CHANNEL, and TASK_SCAN.

static int scan_cancel_req_handler | ( | ke_msg_id_t const | msgid,
|  | void const * | param,
|  | ke_task_id_t const | dest_id,
|  | ke_task_id_t const | src_id |
| ) |  |  | `[static]`

SCAN cancel request message handler.

This function handles the SCAN_CANCEL_REQ message, which cancels the current scanning procedure if scanning is in progress.

Parameters:

  `[in]` | msgid | Id of the message received.
  `[in]` | param | Pointer to the parameters of the message.
  `[in]` | dest_id | TaskId of the receiving task.
  `[in]` | src_id | TaskId of the sending task.

Returns:
  Whether the message was consumed or not.

Definition at line 114 of file scan_task.c.

References scan_env_tag::abort, CO_FAIL, KE_MSG_CONSUMED, ke_state_get(), scan_env, SCAN_IDLE, scan_send_cancel_cfm(), scan_state, and TASK_SCAN.

static int scan_start_req_handler | ( | ke_msg_id_t const | msgid,
|  | struct scan_start_req const * | param,
|  | ke_task_id_t const | dest_id,
|  | ke_task_id_t const | src_id |
| ) |  |  | `[static]`

SCAN start request message handler.

This function handles the SCAN_START_REQ message, which starts the scanning procedure.

Parameters:

  `[in]` | msgid | Id of the message received.
  `[in]` | param | Pointer to the parameters of the message.
  `[in]` | dest_id | TaskId of the receiving task.
  `[in]` | src_id | TaskId of the sending task.

Returns:
  Whether the message was consumed or not.

Definition at line 56 of file scan_task.c.

References ASSERT_ERR, scan_start_req::chan_cnt, scan_env_tag::chan_idx, CO_BUSY, CO_OK, KE_MSG_ALLOC, KE_MSG_CONSUMED, KE_MSG_NO_FREE, ke_msg_send(), ke_state_get(), scan_env_tag::param, scan_env_tag::req_id, scan_env, SCAN_IDLE, scan_ie_download(), SCAN_START_CFM, scan_start_cfm::status, and TASK_SCAN.

## Variable Documentation

struct ke_state_handler scan_default_handler

Initial value:

        KE_STATE_HANDLER(scan_default_state)

Specifies the message handlers that are common to all states.

Definition at line 256 of file scan_task.c.

struct ke_msg_handler scan_default_state[]

Initial value:

    {

        {SCAN_START_REQ,            (ke_msg_func_t)scan_start_req_handler},

        {MM_SCAN_CHANNEL_START_IND, (ke_msg_func_t)mm_scan_channel_start_ind_handler},

        {MM_SCAN_CHANNEL_END_IND,   (ke_msg_func_t)mm_scan_channel_end_ind_handler},

        {SCAN_CANCEL_REQ,           (ke_msg_func_t)scan_cancel_req_handler},
    }

Message handlers in state DEFAULT.

Definition at line 243 of file scan_task.c.