Wi-Fi Development Guide

Introduction

Quectel FC41D module, FCM100D module, FCM740D module and FLMx40D module support QuecOpen® solution. QuecOpen® is an embedded development platform based on RTOS system. It is intended to simplify the design and development of IoT applications. For more information on QuecOpen®, see Quick_Start_Guide.

This document is applicable to QuecOpen® solution based on SDK builds environment. It introduces Wi-Fi API and related examples provided in the SDK of FC41D module, FCM100D module, FCM740D module and FLMx40D module in QuecOpen® solution.

Applicable Modules

Module Family Module
- FC41D
- FCM100D
- FCM740D
FLMx40D FLM040D
FLM140D
FLM240D
FLM340D

Wi-Fi API

Header File

ql_wlan.h, the header file of Wi-Fi API, is in the ql_components/qadpt/include/ directory. Unless otherwise specified, all header files mentioned in this document are in this directory.

API Overview

Function Description
ql_wlan_start() Starts the network connection in both STA and AP modes.
ql_wlan_start_sta_adv() Enables quick connection of STA to network.
ql_wlan_stop() Disables network connection in both STA and AP modes.
ql_wlan_start_scan() Enables network scan.
ql_wlan_scan_ap_reg_cb() Registers the callback function called after the scan is finished.
ql_wlan_sta_scan_result Gets scan results.
ql_wlan_start_assign_scan() Scans the specified network.
ql_wlan_start_monitor() Enables listening mode.
ql_wlan_stop_monitor() Disables listening mode.
ql_wlan_register_monitor_cb() Registers the callback function for listening.
ql_wlan_get_ip_status() Gets the current network status.
ql_wlan_get_link_status() Gets the current connection status.
ql_wlan_ap_para_info_get() Gets the current AP information.
ql_wlan_get_channel() Gets the current channel.
ql_sta_chiper_type Gets the encryption method of the current STA.
ql_wlan_set_channel() Sets the channel.
ql_wlan_ota_download() Upgrades the module firmware.

API Description

ql_wlan_start

This function starts the network connection in both STA and AP modes. The upper application starts network connection after obtaining the SSID and password.

  • Prototype
int ql_wlan_start(ql_network_InitTypeDef_s *inNetworkInitPara)
  • Parameter

inNetworkInitPara:

[In] Network connection configuration information. See ql_network_InitTypedef_s for details.

  • Return Value

0 Successful execution

Other Values Failed execution

ql_network_InitTypedef_s

The structure of the network connection configuration information:

typedef struct               
{
  char wifi_mode;
  char wifi_ssid[33];
  char wifi_key[64];
  char local_ip_addr[16];
  char net_mask[16];
  char gateway_ip_addr[16];
  char dns_server_ip_addr[16];
  char dhcp_mode;             
  char wifi_bssid[6];
  char reserved[26];
  int wifi_retry_interval;
} ql_network_InitTypeDef_s
  • Parameter
Type Parameter Description
char wifi_mode Wi-Fi mode.
char wifi_ssid SSID that needs to be connected or created.
char wifi_key Password that needs to be connected or created.
char local_ip_addr Static IP address, which is valid when DHCP is disabled.
char net_mask Static subnet mask, which is valid when DHCP is disabled.
char gateway_ip_addr Static gateway address, which is valid when DHCP is disabled.
char dns_server_ip_addr Static DNS address, which is valid when DHCP is disabled.
char dhcp_mode DHCP mode.
char wifi_bssid MAC address of AP.
char reserved Reserved.
int wifi_retry_interval Reconnection interval. Unit: millisecond.

ql_wlan_start_sta_adv

This function enables STA for quick network connection.

  • Prototype
int ql_wlan_start_sta_adv(ql_network_InitTypeDef_s *inNetworkInitParaAdv)
  • Parameter

inNetworkInitParaAdv:

[In] Network parameter. See ql_network_InitTypeDef_adv_s for details.

  • Return Value

0 Successful execution

Other Values Failed execution

ql_network_InitTypeDef_adv_s

The structure of the network parameter:

typedef struct ql_network_InitTypeDef_adv_st
{
  apinfo_adv_t ap_info;
  char key[64];
  int key_len;
  char local_ip_addr[16];
  char net_mask[16];
  char gateway_ip_addr[16];
  char dns_server_ip_addr[16];
  char dhcp_mode;
  char reserved[32];
  int wifi_retry_interval;
} ql_network_InitTypeDef_adv_s
  • Parameter
Type Parameter Description
ql_apinfo_adv_s ap_info Information of network to be quickly connected. See ql_apinfo_adv_s for details.
char key Password of the network to be quickly connected.
int key_len Length of network password. Unit: Byte.
char local_ip_addr Static IP address, which is valid when DHCP is disabled.
char net_mask Static subnet mask, which is valid when DHCP is disabled.
char gateway_ip_addr Static gateway address, which is valid when DHCP is disabled.
char dns_server_ip_addr Static DNS address, which is valid when DHCP is disabled.
char dhcp_mode DHCP mode.
char reserved Reserved.
int wifi_retry_interval Reconnection time. Unit: millisecond.
ql_apinfo_adv_s

The structure of information of network to be quickly connected:

typedef struct
{
  char ssid[32];
  char bssid[6];
  uint8_t channel;
  uint8_t security;
} ql_apinfo_adv_s
  • Parameter
Type Parameter Description
char ssid SSID of the network to be quickly connected.
char bssid BSSID of the network to be quickly connected .
uint8_t channel Channel of the network to be quickly connected.
uint8_t security AP encryption method. See ql_wlan_sec_type_e for details.
ql_wlan_sec_type_e

The enumeration of encryption methods:

typedef enum
{
  QL_SECURITY_TYPE_NONE,
  QL_SECURITY_TYPE_WEP,
  QL_SECURITY_TYPE_WPA_TKIP,
  QL_SECURITY_TYPE_WPA_AES,
  QL_SECURITY_TYPE_WPA2_TKIP,
  QL_SECURITY_TYPE_WPA2_AES,
  QL_SECURITY_TYPE_WPA2_MIXED,
  QL_SECURITY_TYPE_WPA3_SAE,
  QL_SECURITY_TYPE_WPA3_WPA2_MIXED,
  QL_SECURITY_TYPE_EAP,
  QL_SECURITY_TYPE_OWE,
  QL_SECURITY_TYPE_AUTO,
} ql_wlan_sec_type_e
  • Member
Member Description
QL_SECURITY_TYPE_NONE No encryption.
QL_SECURITY_TYPE_WEP WEP encryption.
QL_SECURITY_TYPE_WPA_TKIP WPA_TKIP encryption.
QL_SECURITY_TYPE_WPA_AES WPA_AES encryption.
QL_SECURITY_TYPE_WPA2_TKIP WPA2_TKIP encryption.
QL_SECURITY_TYPE_WPA2_AES WPA2_AES encryption.
QL_SECURITY_TYPE_WPA2_MIXED WPA2 mixed encryption.
QL_SECURITY_TYPE_WPA3_SAE WPA3_SAE encryption.
QL_SECURITY_TYPE_WPA3_WPA2_MIXED WPA3 and WPA2 hybrid encryption.
QL_SECURITY_TYPE_AUTO Automatic encryption.

ql_wlan_stop

This function disables the network connection in both STA and AP modes.

  • Prototype
int ql_wlan_stop(ql_wlanInterface_Typedef_e mode)
  • Parameter

mode:

[In] Network mode that needs to be disabled. See ql_wlanInterface_Typedef_e for details.

  • Return Value

0 Successful execution

Other Values Failed execution

ql_wlanInterface_Typedef_e

The enumeration of network modes that need to be disabled:

typedef enum
{
  QL_SOFT_AP = BK_SOFT_AP,
  QL_STATION = BK_STATION
} ql_wlanInterface_Typedef_e
  • Member
Member Description
QL_SOFT_AP AP mode
QL_STATION STA mode

ql_wlan_start_scan

This function enables network scan.

  • Prototype
int ql_wlan_start_scan(void)
  • Parameter

None

  • Return Value

0 Successful execution

Other Values Failed execution

ql_wlan_scan_ap_reg_cb

This function registers the callback function which will be called after the scan is finished.

  • Prototype
int ql_wlan_scan_ap_reg_cb(ql_func_scan_callback ind_cb)
  • Parameter

ind_cb:

[In] The callback function which will be called after the scan is finished. See ql_func_scan_callback for details.

  • Return Value

0 Successful execution

Other Values Failed execution

ql_func_scan_callback

This function is the callback function which will be called after the scan is finished.

  • Prototype
typedef void (*ql_func_scan_callback)(void *arg, uint8_t vif_idx)
  • Parameter

arg:

[Out] Output parameter.

vif_idx:

[Out] No significance currently.

ql_wlan_sta_scan_result

This function gets scan results. It can be used in the callback function which will be called after the scan is finished.

  • Prototype
int ql_wlan_sta_scan_result(ScanResult_adv *results)
  • Parameter

results:

[In] Scan result. See ScanResult_adv for details.

  • Return Value

0 Successful execution

Other Values Failed execution

ScanResult_adv

The structure of the scan result:

typedef struct _ScanResult_adv
{
  char ApNum;
  struct ApListStruct
  {
    char ssid[33];
    char ApPower;
    uint8_t bssid[6];
    char channel;
    wlan_sec_type_t security;
  } *ApList;
} ScanResult_adv;
  • Parameter
Type Parameter Description
char ApNum Number of scanned AP.
char ssid SSID of AP to be scanned.
char ApPower Signal strength of AP to be scanned. Minimum: 0; Maximum: 100.
char bssid BSSID of AP to be scanned.
char channel Channel of AP to be scanned.
wlan_sec_type_t security AP encryption method. See ql_wlan_sec_type_e for details.

ql_wlan_start_assign_scan

This function scans the specified network.

  • Prototype
int ql_wlan_start_assign_scan(UINT8 **ssid_ary, UINT8 ssid_num)
  • Parameter

ssid_ary:

[In] SSID of specified network.

ssid_num:

[In] Number of the specified network.

  • Return Value

0 Successful execution

Other Values Failed execution

ql_wlan_start_monitor

This function enables listening mode.

  • Prototype
int ql_wlan_start_monitor(void)
  • Parameter

None

  • Return Value

0 Successful execution

Other Values Failed execution

ql_wlan_stop_monitor

This function disables listening mode.

  • Prototype
int ql_wlan_stop_monitor(void)
  • Parameter

None

  • Return Value

0 Successful execution

Other Values Failed execution

ql_wlan_register_monitor_cb

This function registers the callback function for listening.

  • Prototype
int ql_wlan_register_monitor_cb(monitor_cb_t fn)
  • Parameter

fn:

[In] Callback function for listening. See monitor_cb_t for details.

  • Return Value

0 Successful execution

Other Values Failed execution

monitor_cb_t

This function is the callback function to be registered for listening.

  • Prototype
typedef void (*monitor_cb_t)(uint8_t *data, int len, wifi_link_info_t *info)
  • Parameter

data:

[Out] Data returned during listening.

len:

[Out] Length of data returned during listening. Unit: byte.

info:

[Out] Information returned during listening. See wifi_link_info_t for details.

The structure of the data package information for listening:

typedef struct
{
  int8_t rssi;
} wifi_link_info_t
  • Parameter
Type Parameter Description
Int8 rssi The signal strength of the data package received during listening.

ql_wlan_get_ip_status

This function gets the current network status.

  • Prototype
int ql_wlan_get_ip_status(IPStatusTypedef *outNetpara, WiFi_Interface inInterface)
  • Parameter

outNetpara:

[Out] Network status. See IPStatusTypedef for details.

inInterface:

[In] Network operation mode. See ql_wlanInterface_Typedef_e for details.

  • Return Value

0 Successful execution

Other Values Failed execution

IPStatusTypedef

The structure of the network status:

typedef struct
{
  uint8_t dhcp;
  char ip[16];
  char gate[16];
  char mask[16];
  char dns[16];
  char mac[16];
  char broadcastip[16];
} IPStatusTypedef
  • Parameter
Type Parameter Description
uint8_t dhcp Acquired DHCP mode.
char ip Acquired IP address.
char gate Acquired gateway IP address.
char mask Acquired subnet mask.
char dns DNS service IP address.
char mac Acquired MAC address.
char broadcastip Acquired broadcast IP address.

This function gets the current connection status.

  • Prototype
int ql_wlan_get_link_status(LinkStatusTypeDef *outStatus)
  • Parameter

outStatus:

[Out] Connection status. See LinkStatusTypeDef for details.

  • Return Value

0 Successful execution

Other Values Failed execution

LinkStatusTypeDef

The structure of the connection status:

typedef struct _linkStatus_t
{
  int conn_state;
  int wifi_strength;
  uint8_t ssid[32];
  uint8_t bssid[6];
  int channel;
  uint8_t security;
} LinkStatusTypeDef
  • Parameter
Type Parameter Description
int conn_state Current connection status of the module Wi-Fi. See ql_wlan_evt_type for details.
int wifi_strength Current signal strength.
uint8_t ssid SSID of currently connected network.
uint8_t bssid MAC address of AP.
int channel Current network channel.
uint8_t security Encryption method of AP. See ql_wlan_sec_type_e for details.
ql_wlan_evt_type

The enumeration of current connection statuses of the module Wi-Fi:

typedef enum {
  QL_WLAN_EVT_STA_IDLE = 0,
  QL_WLAN_EVT_STA_CONNECTING,
  QL_WLAN_EVT_STA_BEACON_LOSE,
  QL_WLAN_EVT_STA_PASSWORD_WRONG,
  QL_WLAN_EVT_STA_NO_AP_FOUND,
  QL_WLAN_EVT_STA_ASSOC_FULL,
  QL_WLAN_EVT_STA_DISCONNECTED,
  QL_WLAN_EVT_STA_CONNECT_FAILED,
  QL_WLAN_EVT_STA_CONNECTED,
  QL_WLAN_EVT_STA_GOT_IP, QL_WLAN_EVT_AP_CONNECTED,
  QL_WLAN_EVT_AP_DISCONNECTED,
  QL_WLAN_EVT_AP_CONNECT_FAILED,
  QL_WLAN_EVT_MAX
} ql_wlan_evt_type
  • Member
Member Description
QL_WLAN_EVT_STA_IDLE Idle.
QL_WLAN_EVT_STA_CONNECTING The module is connecting to AP as STA.
QL_WLAN_EVT_STA_BEACON_LOSE Beacon frame is lost.
QL_WLAN_EVT_STA_PASSWORD_WRONG Password is wrong.
QL_WLAN_EVT_STA_NO_AP_FOUND Target AP is not found.
QL_WLAN_EVT_STA_ASSOC_FULL The module is connecting to AP as STA, and the number of available connections to AP has reached the maximum value.
QL_WLAN_EVT_STA_DISCONNECTED The module is disconnected to AP as STA.
QL_WLAN_EVT_STA_CONNECT_FAILED The module is failed to connect to AP as STA.
QL_WLAN_EVT_STA_CONNECTED The module is connected to AP as STA and is obtaining the IP address.
QL_WLAN_EVT_STA_GOT_IP The module is connected to AP as STA, and the IP address is obtained successfully.
QL_WLAN_EVT_AP_CONNECTED The module is connected to STA as AP successfully.
QL_WLAN_EVT_AP_DISCONNECTED The module is disconnected to STA as AP.
QL_WLAN_EVT_AP_CONNECT_FAILED The module is failed to connect to STA as AP.

ql_wlan_ap_para_info_get

This function gets the current AP information.

  • Prototype
int ql_wlan_ap_para_info_get(network_InitTypeDef_ap_st *ap_info)
  • Parameter

ap_info:

[Out] AP information. See network_InitTypeDef_ap_st for details.

  • Return Value

0 Successful execution

Other Values Failed execution

network_InitTypeDef_ap_st

The structure of the AP information:

typedef struct _network_InitTypeDef_ap_st
{
  char wifi_ssid[32];
  char wifi_key[64];
  uint8_t channel;
  wlan_sec_type_t security;
  uint8_t ssid_hidden;
  uint8_t max_con;
  char local_ip_addr[16];
  char net_mask[16];
  char gateway_ip_addr[16];
  char dns_server_ip_addr[16];
  char dhcp_mode;
  char reserved[32];
  int wifi_retry_interval;
} network_InitTypeDef_ap_st
  • Parameter
Type Parameter Description
char wifi_ssid SSID that needs to be connected or created.
char wifi_key Password that needs to be connected or created.
uint8_t channel Current network channel.
wlan_sec_type_t security AP encryption method. See ql_wlan_sec_type_e for details.
uint8_t ssid_hidden Hide the enablement of SSID broadcasting.
uint8_t max_con Maximum number of concurrent STA connections.
char local_ip_addr Static IP address, which is valid when DHCP is disabled.
char net_mask Static subnet mask, which is valid when DHCP is disabled.
char gateway_ip_addr Static gateway address, which is valid when DHCP is disabled.
char dns_server_ip_addr Static DNS address, which is valid when DHCP is disabled.
char dhcp_mode DHCP mode.
char reserved Reserved.
char wifi_key Reconnection Time. Unit: millisecond.

ql_wlan_get_channel

This function gets the current channel.

  • Prototype
int ql_wlan_get_channel(void)
  • Parameter

None

  • Return Value

Current channel.

ql_sta_chiper_type

This function gets the encryption method of the current STA.

  • Prototype
int ql_sta_chiper_type(void)
  • Parameter

None

  • Return Value

STA encryption method. See ql_wlan_sec_type_e for details.

ql_wlan_set_channel

This function sets the channel.

  • Prototype
int ql_wlan_set_channel(int channel)
  • Parameter

channel:

[In] Channel.

  • Return Value

0 Successful execution

Other Values Failed execution

ql_wlan_ota_download

This function upgrades the module firmware.

  • Prototype
int ql_wlan_ota_download(const char *uri)
  • Parameter

uri:

[In] HTTP server domains stored in the firmware upgrade package.

  • Return Value

0 Successful execution

Other Values Failed execution

Example

Constant Definitions

  • LinkStatusTypeDef
#define DHCP_DISABLE  (0)  /*DHCP is disabled*/
#define DHCP_CLIENT   (1)  /*DHCP client mode*/
#define DHCP_SERVER   (2)  /*DHCP service mode*/

Example Codes

  • Enable STA to connect to the network
void demo_sta_app_init(char *oob_ssid, char *connect_key)
{
  /*Define a structure to input the parameters*/
  network_InitTypeDef_st wNetConfig;
  int len;
  /*Empty the structure*/
  os_memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));

  /*Check the length of SSID, which cannot be more than 32 bytes*/
  len = os_strlen(oob_ssid);
  if(SSID_MAX_LEN < len)
  {
    os_printf("ssid name more than 32 Bytes\r\n");
    return;
  }
  /*Input SSID and password to the structure*/
  os_strcpy((char *)wNetConfig.wifi_ssid, oob_ssid);
  os_strcpy((char *)wNetConfig.wifi_key, connect_key);

  /*Set the Wi-Fi mode to client mode*/
  wNetConfig.wifi_mode = QL_STATION;

  /*Set DHCP mode to DHCP CLIENT to get IP address from the router dynamics*/
  wNetConfig.dhcp_mode = DHCP_CLIENT;
  wNetConfig.wifi_retry_interval = 100;
  os_printf("ssid:%s key:%s\r\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key);

  /*Enable Wi-Fi connection*/
  ql_wlan_start(&wNetConfig);
}
  • Enable AP
void demo_softap_app_init(char *ap_ssid, char *ap_key)
{
  /*Define a structure to input the parameters*/
  network_InitTypeDef_st wNetConfig;
  int len;
  /*Empty the structure*/
  os_memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
  len = os_strlen(ap_ssid);
  if(SSID_MAX_LEN < len)
  {
    os_printf("ssid name is more than 32 Bytes\r\n");
    return;
  }
  /*Input AP SSID and ap key that needs to be connected*/
  os_strcpy((char *)wNetConfig.wifi_ssid, ap_ssid);
  os_strcpy((char *)wNetConfig.wifi_key, ap_key);

  /*Set Wi-Fi mode to AP mode */
  wNetConfig.wifi_mode = QL_SOFT_AP;

  /*You need to assign the static address as the local address when DHCP SERVER is used*/
  wNetConfig.dhcp_mode = DHCP_SERVER;
  wNetConfig.wifi_retry_interval = 100;
  os_strcpy((char *)wNetConfig.local_ip_addr, WLAN_DEFAULT_IP);
  os_strcpy((char *)wNetConfig.net_mask, WLAN_DEFAULT_MASK);
  os_strcpy((char *)wNetConfig.gateway_ip_addr, WLAN_DEFAULT_GW);
  os_strcpy((char *)wNetConfig.dns_server_ip_addr, WLAN_DEFAULT_GW);
  os_printf("ssid:%s key:%s\r\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key);

  /*Enable ap*/
  ql_wlan_start(&wNetConfig);
}
  • Enable STA to connect to the network quickly
void demo_sta_adv_app_init(char *oob_ssid,char *connect_key)
{
  /*Define a structure to input the parameters*/
  network_InitTypeDef_adv_st wNetConfigAdv;

  /*Empty the structure*/
  os_memset( &wNetConfigAdv, 0x0, sizeof(network_InitTypeDef_adv_st) );
  /*Input SSID that needs to be connected*/
  os_strcpy((char*)wNetConfigAdv.ap_info.ssid, oob_ssid);

  /*Input BSSID of the network that needs to be connected. The following bssid is for reference only*/
  hwaddr_aton("48:ee:0c:48:93:12", (u8*)(wNetConfigAdv.ap_info.bssid));

  /*The encryption method of the network that needs to be connected. Refer to the structure description for specific parameters*/
  wNetConfigAdv.ap_info.security = QL_SECURITY_TYPE_WPA2_MIXED;
  /*The channel of the network that needs to be connected*/
  wNetConfigAdv.ap_info.channel = 11;
  /*The password of the network that needs to be connected and the length of the password*/
  os_strcpy((char*)wNetConfigAdv.key, connect_key);
  wNetConfigAdv.key_len = os_strlen(connect_key);
  /*Get IP address through DHCP*/
  wNetConfigAdv.dhcp_mode = DHCP_CLIENT;
  wNetConfigAdv.wifi_retry_interval = 100;

  /*Enable quick connection*/
  ql_wlan_start_sta_adv(&wNetConfigAdv);
}
  • Enable scan and analyze scan results
/*Callback function to analyze scan results after the scan isfinished*/
static void scan_cb(void *ctxt, uint8_t param)
{
#if !CFG_WPA_CTRL_IFACE
  /*Pointer to the scan result*/
  struct scanu_rst_upload *scan_rst;
  /*Structure to save the scan result*/
  ScanResult apList;
  int i;

  GLOBAL_INT_DECLARATION();
  apList.ApList = NULL;
  GLOBAL_INT_DISABLE();
  /*Enable scan*/
  scan_rst = sr_get_scan_results();

  /*If nothing is scanned, return; otherwise, record the count of scanned networks*/
  if (scan_rst == NULL) {
    GLOBAL_INT_RESTORE();
    apList.ApNum = 0;
    return;
  } else {
    apList.ApNum = scan_rst->scanu_num;
  }

  if (apList.ApNum > 0) {
    /*Request the corresponding memory to save the scan result*/
    apList.ApList = (void *)os_zalloc(sizeof(*apList.ApList) * apList.ApNum);
    if(apList.ApList == NULL) {
      GLOBAL_INT_RESTORE();
      os_printf("Got ap count: %d,but malloc failed\r\n", apList.ApNum);
      return;
    }
    for (i = 0; i < scan_rst->scanu_num; i++) {
      /*Record SSID and RSSI of the scanned network*/
      os_memcpy(apList.ApList[i].ssid, scan_rst->res[i]->ssid, 32);
      apList.ApList[i].ApPower = scan_rst->res[i]->level;
    }
  }
  GLOBAL_INT_RESTORE();
  if (apList.ApList == NULL)
    apList.ApNum = 0;

  /*Print the scan result*/
  os_printf("Got ap count: %d\r\n", apList.ApNum);
  for (i = 0; i < apList.ApNum; i++) {
    if (os_strlen(apList.ApList[i].ssid) >= SSID_MAX_LEN) {
      char temp_ssid[33];
      os_memset(temp_ssid, 0, 33);
      os_memcpy(temp_ssid, apList.ApList[i].ssid, 32);
      os_printf(" %s, RSSI=%d\r\n", temp_ssid,
      apList.ApList[i].ApPower);
    } else {
      os_printf(" %s, RSSI=%d\r\n", apList.ApList[i].ssid,
      apList.ApList[i].ApPower);
    }
  }
  os_printf("Get ap end\...\....\r\n\r\n");

  /*Release the requested memory*/
  if (apList.ApList != NULL) {
    os_free(apList.ApList);
    apList.ApList = NULL;
  }
#if CFG_ROLE_LAUNCH
  rl_pre_sta_set_status(RL_STATUS_STA_LAUNCHED);
#endif
  sr_release_scan_results(scan_rst);

#else /* CFG_WPA_CTRL_IFACE */
  static const char *crypto_str[] = {
    "None",
    "WEP",
    "WPA_TKIP",
    "WPA_AES",
    "WPA2_TKIP",
    "WPA2_AES",
    "WPA2_MIXED", ////QL_SECURITY_TYPE_WPA3_SAE
    "WPA3_SAE", /**\< WPA3 SAE */
    "WPA3_WPA2_MIXED", /** WPA3 SAE or WPA2 AES */
    "AUTO",
  };

  ScanResult_adv apList;
  if (wlan_sta_scan_result(&apList) == 0) {
    int ap_num = apList.ApNum;
    int i;
    os_printf("Got ap count: %d\r\n", apList.ApNum);
    for (i = 0; i < ap_num; i++)
      os_printf(" \"%s\", " MACSTR "\b, %d, %s, %d\n", apList.ApList[i].ssid, MAC2STR(apList.ApList[i].bssid), apList.ApList[i].ApPower, crypto_str[apList.ApList[i].security], apList.ApList[i].channel);
    os_free(apList.ApList);
  }
#endif /* CFG_WPA_CTRL_IFACE */
}

void demo_scan_app_init(void)
{
  /*Register the scan callback function*/
  mhdr_scanu_reg_cb(scan_cb, 0);
  /* Start the scan*/
  ql_wlan_start_scan();
}
  • Get the current network status
void demo_ip_app_init(void)
{
  IPStatusTypedef ipStatus;

  os_memset(&ipStatus, 0x0, sizeof(IPStatusTypedef));
  ql_wlan_get_ip_status(&ipStatus, QL_STATION);
  os_printf("dhcp=%d ip=%s gate=%s mask=%s mac=" MACSTR "\r\n",

  ipStatus.dhcp, ipStatus.ip, ipStatus.gate,
  ipStatus.mask, MAC2STR((unsigned char*)ipStatus.mac));
}
  • Get the connection status when network is connected successfully
void demo_state_app_init(void)
{
  /*Define the structure to save the connection status*/
  LinkStatusTypeDef linkStatus;
  network_InitTypeDef_ap_st ap_info;
  char ssid[33] = {0};

#if CFG_IEEE80211N
  os_printf("sta: %d, softap: %d, b/g/n\r\n", sta_ip_is_start(),
  uap_ip_is_start());
#else
  os_printf("sta: %d, softap: %d, b/g\r\n", sta_ip_is_start(),
  uap_ip_is_start());
#endif
  /*Connection status in STA mode*/
  if (sta_ip_is_start()) {
    /*Empty the structure used to save the status*/
    os_memset(&linkStatus, 0x0, sizeof(LinkStatusTypeDef));
    /*Get the connection status*/
    ql_wlan_get_link_status(&linkStatus);
    os_memcpy(ssid, linkStatus.ssid, 32);
    /*Print the connection status*/
    os_printf("sta:rssi=%d,ssid=%s,bssid=" MACSTR ",channel=%d,cipher_type:", linkStatus.wifi_strength, ssid, MAC2STR(linkStatus.bssid), linkStatus.channel);

    switch (ql_sta_chiper_type()) {
      case QL_SECURITY_TYPE_NONE:
        os_printf("OPEN\r\n");
      break;
      case QL_SECURITY_TYPE_WEP :
        os_printf("WEP\r\n");
      break;
      case QL_SECURITY_TYPE_WPA_TKIP:
        os_printf("TKIP\r\n");
      break;
      case QL_SECURITY_TYPE_WPA_AES: 
        os_printf("WPA_AES\r\n");
      break;
      case QL_SECURITY_TYPE_WPA2_AES:
        os_printf("CCMP\r\n");
      break; case QL_SECURITY_TYPE_WPA2_TKIP:
        os_printf("WPA2_TKIP\r\n");
      break;
      case QL_SECURITY_TYPE_WPA2_MIXED:
        os_printf("WPA/WPA2 MIXED\r\n");
      break;
      case QL_SECURITY_TYPE_AUTO:
        os_printf("AUTO\r\n");
      break;
      case QL_SECURITY_TYPE_WPA3_SAE:
        os_printf("WPA3\n");
      break;
      case QL_SECURITY_TYPE_WPA3_WPA2_MIXED:
        os_printf("WPA2/WPA3 MIXED\n");
      break;
      default:
        os_printf("Error\r\n");
      break;
    }
  }
  /*Connection status in AP mode*/
  if (uap_ip_is_start()) {
    /*Empty the structure used to save the status*/
    os_memset(&ap_info, 0x0, sizeof(network_InitTypeDef_ap_st));
    /*Get the connection status*/
    ql_wlan_ap_para_info_get(&ap_info);
    os_memcpy(ssid, ap_info.wifi_ssid, 32);
    /*Print the acquired connection status value*/
    os_printf("softap:ssid=%s,channel=%d,dhcp=%d,cipher_type:", ssid, ap_info.channel, ap_info.dhcp_mode);

    switch (ap_info.security) {
      case QL_SECURITY_TYPE_NONE:
        os_printf("OPEN\r\n");
      break;
      case QL_SECURITY_TYPE_WEP :
        os_printf("WEP\r\n");
      break;
      case QL_SECURITY_TYPE_WPA_TKIP:
        os_printf("TKIP\r\n");
      break;
      case QL_SECURITY_TYPE_WPA2_AES:
        os_printf("CCMP\r\n");
      break;
      case QL_SECURITY_TYPE_WPA2_MIXED:
        os_printf("WPA/WPA2 MIXED\r\n");
      break;
      case QL_SECURITY_TYPE_AUTO:
        os_printf("AUTO\r\n");
      break;
      case QL_SECURITY_TYPE_WPA3_SAE:
        os_printf("WPA3\n");
      break;
      case QL_SECURITY_TYPE_WPA3_WPA2_MIXED:
        os_printf("WPA2/WPA3 MIXED\n");
      break;
      default:
        os_printf("Error\r\n");
      break;
    }
    os_printf("ip=%s,gate=%s,mask=%s,dns=%s\r\n",ap_info.local_ip_addr,
    ap_info.gateway_ip_addr,ap_info.net_mask,ap_info.dns_server_ip_addr);
  }
}
  • Scan the specified SSID
void demo_scan_adv_app_init(uint8_t *oob_ssid)
{
  uint8_t **ssid_array;
  ssid_array = &oob_ssid;

  /*Register the scan response function*/
  mhdr_scanu_reg_cb(scan_cb, 0);
  os_printf("scan for ssid:%s\r\n", oob_ssid);
  ql_wlan_start_assign_scan(ssid_array, 1);
}

Operation Description

ql_wlan_demo.c, the Wi-Fi API code example file, is in the ql_application/quectel_demo/ directory, where you can view the complete Wi-Fi API examples. WLAN feature is enabled by default. After the module is powered on, you can run different programs by inputting corresponding commands at the debugging port.

Enabling Scan

The module log is shown below:

scan

[sa_sta]MM_RESET_REQ
[sa_sta]ME_CONFIG_REQ
[sa_sta]ME_CHAN_CONFIG_REQ
[sa_sta]MM_START_REQ
no ht in scan
scan_start_req_handler

# Got ap count: 32
  cx_wifi3, RSSI=-24
  ASUS_2G, RSSI=-36
  billy1, RSSI=-45
  billy2, RSSI=-48
  GSWiFi-207F, RSSI=-52
  Quectel-SH, RSSI=-56
  Visitor-Quectel, RSSI=-57
  Visitor-Quectel, RSSI=-58
  Quectel-SH, RSSI=-59
  , RSSI=-59
  , RSSI=-62
  Quectel-SH, RSSI=-62
  Visitor-Quectel, RSSI=-64
  Visitor-Quectel, RSSI=-64
  Quectel-SH, RSSI=-65
  , RSSI=-67
  , RSSI=-68
  Visitor-Quectel, RSSI=-72
  SupermaniPhone, RSSI=-74
  , RSSI=-74
  Quectel-SH, RSSI=-74
  Visitor-Quectel, RSSI=-74
  Visitor-Quectel, RSSI=-74
  Quectel-SH, RSSI=-74
  123456, RSSI=-75
  YY-zhanting, RSSI=-82
  Quectel-SH, RSSI=-82
  , RSSI=-83
  , RSSI=-83
  , RSSI=-83
  DIRECT-AVSH-PD-DAVISN1ms2K, RSSI=-87
  , RSSI=-90
Get ap end.......

Scanning Specified Network

After the module is powered on, input advscan your_SSID at the debugging port of the module, and the module starts scanning the specific network. The module log is shown below:

advscan cx_wifi3
scan for ssid:cx_wifi3
[sa_sta]MM_RESET_REQ
[sa_sta]ME_CONFIG_REQ
[sa_sta]ME_CHAN_CONFIG_REQ
[sa_sta]MM_START_REQ
no ht in scan
scan_start_req_handler

# Got ap count: 1
  cx_wifi3, RSSI=-26
Get ap end.......

Enabling AP

To enable AP functionality, follow the following steps:

  1. Power on the module.

  2. Input softap your_SSID your_key at the debugging port of the module.

The module will create a network with your_SSID as the SSID and your_key as the password. The module log is shown below:

softap test 12345678

SOFTAP_COMMAND

ssid:test key:12345678
sending broadcast_deauth failed vif_entry == NULL
Soft_AP_start
[saap]MM_RESET_REQ
[saap]ME_CONFIG_REQ
[saap]ME_CHAN_CONFIG_REQ
[saap]MM_START_REQ
[csa]csa_in_progress[0:0]-clear
mm_add_if_req_handler:0
hapd_intf_add_vif,type:3, s:0, id:0
apm start with vif:0
----beacon_int_set:100 TU
set_active param 0
[msg]APM_STOP_CFM
update_ongoing_1_bcn_update
mm_set_vif_state_req_handler
vif_idx:0, ch_idx:0, bcmc_idx:2
cal dpll!
temperature_type=2
do td cur_t:343--last:idx:13,t:350 -- new:idx:14,t:340
--0xc:00, shift_b:0, shift_g:0, shift_ble:0 X:0
update_ongoing_1_bcn_update
hapd_intf_add_key CCMP
add is_broadcast_ether_addr
sta:255, vif:0, key:1
add hw key idx:1
enter low level!
mac c8:47:8c:42: 0:49
leave low level!
[net]addvif_idx:0
uap_ip_start

Configuring interface uap (with Static IP)[THD]dhcp-server:[tcb]414578 [stack]4140f0-414570:1152:2
def netif is no ap's netif, sending boardcast or no-subnet ip packets may failed
sending broadcast_deauth:5
#

Closing AP/STA

After enabling AP/STA, input stopintf 0/1 at the debugging port, and the module disables AP/STA. The module log is shown below:

stopintf 0

stop_wlan_intface_Command
stop wlan intface:0
sending broadcast_deauth:5
uap_ip_down
sta test 12345678
sta_Command
ssid:test key:12345678
[sa_sta]MM_RESET_REQ
[sa_sta]ME_CONFIG_REQ
[sa_sta]ME_CHAN_CONFIG_REQ
[sa_sta]MM_START_REQ
[THD]pskc:[tcb]410348 [stack]40ff40-410340:1024:4
PSKC: ssid test, passphrase 12345678
sizeof(wpa_supplicant)=768
mm_add_if_req_handler:0
hapd_intf_add_vif,type:2, s:0, id:0
wpa_dInit
enter low level!
mac c8:47:8c:42: 0:48
leave low level!
[net]addvif_idx:0

Connecting to AP

After powering on of the module, input sta your_ssid your_key to the debugging port, and the module will connect to the network whose SSID is your_SSID. The module log is shown below:

wpa_supplicant_req_scan
Setting scan request: 0.000000 sec
wpa_supplicant_scan
wpa_drv_scan
wpa_send_scan_req
no ht in scan
scan_start_req_handler
wpa_driver_scan_start_cb
scan_cancel_req_handler

# scan_send_cancel_cfm
wpa_driver_scan_cb
Scan completed in 0.100000 seconds
wpa_get_scan_rst:1
cipher2security 2 2 16 16
PSKC: end
cipher2security 2 2 16 16
wpa_supplicant_connect
Cancelling scan request
wpa_driver_associate: auth_alg 0x1
found scan rst rssi -27 > -50 0
sm_auth_send:1
sm_auth_handler
ht in assoc req
sm_assoc_rsp_handler
rc_init: station_id=0 format_mod=2 pre_type=0 short_gi=1 max_bw=0
rc_init: nss_max=0 mcs_max=7 r_idx_min=0 r_idx_max=3 no_samples=10
mm_set_vif_state_req_handler
chan_bcn_detect_start
----SM_CONNECT_IND_ok
Cancelling scan request
WPA: TK 0eb538f828d1e2a6d0a417736a3ff17c
new dtim period:2

new ie: 0 : 74 65 73 74
new ie: 1 : 82 84 8b c 12 96 18 24
new ie: 3 : 1
new ie: 30 : 1 0 0 f ac 4 1 0 0 f ac 4 1 0 0 f ac 2 c 0
new ie: 2d : ad 1 17 ff ff 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 

hapd_intf_add_key CCMP
add sta_mgmt_get_sta
sta:0, vif:0, key:0
sta_mgmt_add_key

Getting Wi-Fi Status

After powering on of the module, input wifistate to the debugging port, and the module will output the current status of Wi-Fi functionality. The module log is shown below:

add hw key idx:24
WPA: GTK bbd21fb387e9a66215df725673e64fbd
hapd_intf_add_key CCMP
add is_broadcast_ether_addr
sta:255, vif:0, key:1
add hw key idx:1
ctrl_port_hdl:1
me_set_ps_disable:869 0 0 0 0 1
dis set ps 1!!
WLAN_EVENT_CONNECTED
sta_ip_start

configuring interface mlan (with DHCP client)
dhcp_check_status_init_timer:20000
ip_addr: 372ba8c0
cal dpll!
cal_bias!
cal dpll!
do td cur_t:312--last:idx:16,t:320 -- new:idx:17,t:310
--0xc:00, shift_b:0, shift_g:0, shift_ble:0 X:-2
init_xtal:0, delta:-2, last_xtal:0
wifistate
wifistate_Command
sta: 1, softap: 0, b/g/n
sta:rssi=-32,ssid=test,bssid=82:54:40:e2:05:72
,channel=1,cipher_type:CCMP

Appendix References

Related Document:

Document Name
Quectel_FC41D&FCM100D&FCM740D&FLMx40D_QuecOpen(SDK)_Quick_Start_Guide

Terms and Abbreviations

Terms and Abbreviations:

Abbreviation Description
AP Access Point
API Application Programming Interface
DHCP Dynamic Host Configuration Protocol
DNS Domain Name Server
HTTP Hypertext Transfer Protocol
IoT Internet of Things
IP Internet Protocol
MAC Medium Access Control
RTOS Real-Time Operation
SDK Software Development Kit
SSID Service Set Identifier
STA Station
USB Universal Serial Bus
WLAN Wireless Local Area Network