Morse Micro IoT SDK  2.11.2
scan.c
Go to the documentation of this file.
1/*
2 * Copyright 2022-2023 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
21#include <string.h>
22#include "mmosal.h"
23#include "mmutils.h"
24#include "mmwlan.h"
25#include "mm_app_loadconfig.h"
26#include "mm_app_common.h"
27
28/*
29 * ANSI escape characters will be used for rich text in the console. To disable ANSI escape
30 * characters, ANSI_ESCAPE_ENABLED must be defined as 0.
31 */
32#if !(defined(ANSI_ESCAPE_ENABLED) && ANSI_ESCAPE_ENABLED == 0)
34#define ANSI_BOLD "\x1b[1m"
36#define ANSI_RESET "\x1b[0m"
37#else
39#define ANSI_BOLD ""
41#define ANSI_RESET ""
42#endif
43
46#define MAC_ADDR_STR_LEN (18)
47
50
57static void scan_rx_callback(const struct mmwlan_scan_result *result, void *arg)
58{
59 (void)(arg);
60 char bssid_str[MAC_ADDR_STR_LEN];
61 char ssid_str[MMWLAN_SSID_MAXLEN];
62 int ret;
63 struct mm_rsn_information rsn_info;
64
66 snprintf(bssid_str,
68 "%02x:%02x:%02x:%02x:%02x:%02x",
69 result->bssid[0],
70 result->bssid[1],
71 result->bssid[2],
72 result->bssid[3],
73 result->bssid[4],
74 result->bssid[5]);
75 snprintf(ssid_str, (result->ssid_len + 1), "%s", result->ssid);
76
77 printf(ANSI_BOLD "%s" ANSI_RESET "\n", ssid_str);
78 printf(" Operating BW: %u MHz\n", result->op_bw_mhz);
79 printf(" BSSID: %s\n", bssid_str);
80 printf(" RSSI: %3d dBm\n", result->rssi);
81 printf(" Noise: %3d dBm\n", result->noise_dbm);
82 printf(" Beacon Interval(TUs): %u\n", result->beacon_interval);
83 printf(" Capability Info: 0x%04x\n", result->capability_info);
84
85 ret = mm_parse_rsn_information(result->ies, result->ies_len, &rsn_info);
86 if (ret == 0)
87 {
88 unsigned ii;
89 printf(" Security:");
90 for (ii = 0; ii < rsn_info.num_akm_suites; ii++)
91 {
92 printf(" %s", mm_akm_suite_to_string(rsn_info.akm_suites[ii]));
93 }
94 printf("\n");
95 }
96 else if (ret == -1)
97 {
98 printf(" Security: None\n");
99 }
100 else
101 {
102 printf(" Invalid RSN IE in probe response\n");
103 }
104
105 struct mm_s1g_operation s1g_operation;
106 ret = mm_parse_s1g_operation(result->ies, result->ies_len, &s1g_operation);
107 if (ret == 0)
108 {
109 printf(" S1G Operation:\n");
110 printf(" Operating class: %u\n", s1g_operation.operating_class);
111 printf(" Primary channel: %u\n", s1g_operation.primary_channel_number);
112 printf(" Primary channel width: %u MHz\n", s1g_operation.primary_channel_width_mhz);
113 printf(" Operating channel: %u\n", s1g_operation.operating_channel_number);
114 printf(" Operating channel width: %u MHz\n",
115 s1g_operation.operating_channel_width_mhz);
116 }
117}
118
125static void scan_complete_callback(enum mmwlan_scan_state state, void *arg)
126{
127 (void)(state);
128 (void)(arg);
129 printf("Scanning completed.\n");
130}
131
136void app_init(void)
137{
138 enum mmwlan_status status;
139
140 printf("\n\nMorse Scan Demo (Built "__DATE__
141 " " __TIME__ ")\n\n");
142
143 mmwlan_init();
144
145 const struct mmwlan_s1g_channel_list *channel_list = load_channel_list();
146 status = mmwlan_set_channel_list(channel_list);
147 if (status != MMWLAN_SUCCESS)
148 {
149 printf("Failed to set country code %s\n", channel_list->country_code);
150 MMOSAL_ASSERT(false);
151 }
152
153 struct mmwlan_boot_args boot_args = MMWLAN_BOOT_ARGS_INIT;
154 status = mmwlan_boot(&boot_args);
155 MMOSAL_ASSERT(status == MMWLAN_SUCCESS);
156
158
160 struct mmwlan_scan_req scan_req = MMWLAN_SCAN_REQ_INIT;
161 scan_req.scan_rx_cb = scan_rx_callback;
163 status = mmwlan_scan_request(&scan_req);
164 MMOSAL_ASSERT(status == MMWLAN_SUCCESS);
165 printf("Scan started on %s channels, Waiting for results...\n", channel_list->country_code);
166}
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
Definition: mmosal.h:1006
const char * mm_akm_suite_to_string(uint32_t akm_suite_oui)
Get the name of the given AKM Suite as a string.
int mm_parse_s1g_operation(const uint8_t *ies, uint32_t ies_len, struct mm_s1g_operation *output)
Find the S1G Operation information element from within a block of IEs and extract useful information ...
int mm_parse_rsn_information(const uint8_t *ies, uint32_t ies_len, struct mm_rsn_information *output)
Search through the given list of information elements to find the RSN IE then parse it to extract rel...
enum mmwlan_status mmwlan_boot(const struct mmwlan_boot_args *args)
Boot the Morse Micro transceiver and leave it in an idle state.
#define MMWLAN_BOOT_ARGS_INIT
Initializer for mmwlan_boot_args.
Definition: mmwlan.h:623
void mmwlan_init(void)
Initialize the MMWLAN subsystem.
enum mmwlan_status mmwlan_set_channel_list(const struct mmwlan_s1g_channel_list *channel_list)
Set the list of channels that are supported by the regulatory domain in which the device resides.
mmwlan_scan_state
Enumeration of states in Scan mode.
Definition: mmwlan.h:808
#define MMWLAN_SCAN_REQ_INIT
Initializer for mmwlan_scan_req.
Definition: mmwlan.h:899
enum mmwlan_status mmwlan_scan_request(const struct mmwlan_scan_req *scan_req)
Request a scan.
mmwlan_status
Enumeration of status return codes.
Definition: mmwlan.h:50
#define MMWLAN_SSID_MAXLEN
Maximum allowable length of an SSID.
Definition: mmwlan.h:90
@ MMWLAN_SUCCESS
The operation was successful.
Definition: mmwlan.h:52
Morse Micro application helper routines for initializing/de-initializing the Wireless LAN interface a...
void app_print_version_info(void)
Prints various version information.
const struct mmwlan_s1g_channel_list * load_channel_list(void)
Looks up country code and returns appropriate channel list.
static void scan_complete_callback(enum mmwlan_scan_state state, void *arg)
Scan complete callback.
Definition: scan.c:125
#define MAC_ADDR_STR_LEN
Length of string representation of a MAC address (i.e., "XX:XX:XX:XX:XX:XX") including null terminato...
Definition: scan.c:46
#define ANSI_BOLD
ANSI escape sequence for bold text.
Definition: scan.c:34
static void scan_rx_callback(const struct mmwlan_scan_result *result, void *arg)
Scan rx callback.
Definition: scan.c:57
void app_init(void)
Main entry point to the application.
Definition: scan.c:136
static int num_scan_results
Number of results found.
Definition: scan.c:49
#define ANSI_RESET
ANSI escape sequence to reset font.
Definition: scan.c:36
Data structure to represent information extracted from an RSN information element.
Definition: mmutils.h:219
uint16_t num_akm_suites
Number of AKM suites in akm_suites.
Definition: mmutils.h:229
uint32_t akm_suites[MM_RSN_INFORMATION_MAX_AKM_SUITES]
AKM suite OUIs.
Definition: mmutils.h:225
Data structure to represent information extracted from an S1G Operation information element.
Definition: mmutils.h:345
uint8_t operating_channel_width_mhz
Width of the operating channel in MHz.
Definition: mmutils.h:349
uint8_t operating_channel_number
Channel number of the operating channel.
Definition: mmutils.h:353
uint8_t primary_channel_width_mhz
Width of the primary channel in MHz.
Definition: mmutils.h:351
uint8_t primary_channel_number
Channel number of the primary channel.
Definition: mmutils.h:355
uint8_t operating_class
Operating class.
Definition: mmutils.h:347
Arguments data structure for mmwlan_boot().
Definition: mmwlan.h:610
A list of S1G channels supported by a given regulatory domain.
Definition: mmwlan.h:183
uint8_t country_code[MMWLAN_COUNTRY_CODE_LEN]
Two character country code (null-terminated) used to identify the regulatory domain.
Definition: mmwlan.h:185
Structure to hold arguments specific to a given instance of a scan.
Definition: mmwlan.h:879
mmwlan_scan_rx_cb_t scan_rx_cb
Scan response receive callback.
Definition: mmwlan.h:881
mmwlan_scan_complete_cb_t scan_complete_cb
Scan complete callback.
Definition: mmwlan.h:883
Result of the scan request.
Definition: mmwlan.h:705
uint8_t ssid_len
Length of the SSID (ssid).
Definition: mmwlan.h:721
const uint8_t * ies
Pointer to the start of the Information Elements within the Probe Response frame.
Definition: mmwlan.h:713
uint16_t capability_info
Value of the Capability Information field.
Definition: mmwlan.h:717
uint16_t ies_len
Length of the Information Elements (ies).
Definition: mmwlan.h:719
const uint8_t * bssid
Pointer to the BSSID field within the Probe Response frame.
Definition: mmwlan.h:709
uint16_t beacon_interval
Value of the Beacon Interval field.
Definition: mmwlan.h:715
uint8_t op_bw_mhz
Operating bandwidth, in MHz, of the access point.
Definition: mmwlan.h:727
int16_t rssi
RSSI of the received frame.
Definition: mmwlan.h:707
int8_t noise_dbm
Background noise measured by the chip on the channel at the time the probe response was received.
Definition: mmwlan.h:732
const uint8_t * ssid
Pointer to the SSID within the SSID IE of the Probe Response frame.
Definition: mmwlan.h:711