From 688fb9a4cc81e2b16c9bfbea78e73d2ca64fa9f2 Mon Sep 17 00:00:00 2001 From: gitlab-runner Date: Mon, 18 Oct 2021 22:14:03 -0500 Subject: [PATCH] Upload wifi-connection-manager 2.0.4.1307 --- README.md | 14 +- RELEASE.md | 21 +- .../html/group__generic__wcm__defines.html | 24 +- .../html/group__generic__wcm__defines.js | 2 + .../html/group__group__wcm__enums.html | 4 + .../html/group__group__wcm__enums.js | 1 + .../html/group__group__wcm__functions.html | 81 +++- .../html/group__group__wcm__functions.js | 5 +- .../html/group__group__wcm__structures.html | 8 +- .../html/group__group__wcm__typedefs.html | 4 +- docs/api_reference_manual/html/index.html | 19 +- docs/api_reference_manual/html/navtreedata.js | 2 +- .../html/navtreeindex0.js | 26 +- .../html/navtreeindex1.js | 4 + .../api_reference_manual/html/search/all_2.js | 6 +- .../html/search/enumvalues_0.js | 1 + .../html/search/functions_0.js | 3 +- .../structcy__wcm__ap__credentials__t.html | 2 +- .../structcy__wcm__connect__params__t.html | 2 +- .../html/structcy__wcm__ip__address__t.html | 2 +- .../html/structcy__wcm__ip__setting__t.html | 2 +- .../html/structcy__wcm__scan__result__t.html | 1 + include/cy_wcm.h | 44 +- include/cy_wcm_error.h | 10 +- source/COMPONENT_43439/cy_chip_constants.h | 43 ++ source/COMPONENT_43907/cy_chip_constants.h | 43 ++ source/COMPONENT_LWIP/cy_wcm.c | 421 ++++++++++++++++-- source/COMPONENT_WPS/cy_wcm_wps.c | 7 + version.txt | 1 - version.xml | 1 + 30 files changed, 681 insertions(+), 123 deletions(-) create mode 100644 source/COMPONENT_43439/cy_chip_constants.h create mode 100644 source/COMPONENT_43907/cy_chip_constants.h delete mode 100644 version.txt create mode 100644 version.xml diff --git a/README.md b/README.md index 4317cfd..1773412 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,13 @@ The current implementation has the following features and functionality: ## Supported Platforms This library and its features are supported on the following Cypress platforms: -* [PSoC 6 Wi-Fi BT Prototyping Kit (CY8CPROTO-062-4343W)](https://www.cypress.com/documentation/development-kitsboards/psoc-6-wi-fi-bt-prototyping-kit-cy8cproto-062-4343w) +* [PSoC™ 6 Wi-Fi BT Prototyping Kit (CY8CPROTO-062-4343W)](https://www.cypress.com/documentation/development-kitsboards/psoc-6-wi-fi-bt-prototyping-kit-cy8cproto-062-4343w) -* [PSoC 62S2 Wi-Fi BT Pioneer Kit (CY8CKIT-062S2-43012)](https://www.cypress.com/documentation/development-kitsboards/psoc-62s2-wi-fi-bt-pioneer-kit-cy8ckit-062s2-43012) +* [PSoC™ 62S2 Wi-Fi BT Pioneer Kit (CY8CKIT-062S2-43012)](https://www.cypress.com/documentation/development-kitsboards/psoc-62s2-wi-fi-bt-pioneer-kit-cy8ckit-062s2-43012) -* [PSoC 6 WiFi-BT Pioneer Kit (CY8CKIT-062-WiFi-BT)](https://www.cypress.com/documentation/development-kitsboards/psoc-6-wifi-bt-pioneer-kit-cy8ckit-062-wifi-bt) +* [PSoC™ 6 WiFi-BT Pioneer Kit (CY8CKIT-062-WiFi-BT)](https://www.cypress.com/documentation/development-kitsboards/psoc-6-wifi-bt-pioneer-kit-cy8ckit-062-wifi-bt) + +* [PSoC™ 62S2 evaluation kit (CY8CEVAL-062S2-LAI-4373M2)](https://www.cypress.com/documentation/development-kitsboards/psoc-62s2-evaluation-kit-cy8ceval-062s2) ## Dependent Libraries This library depends on the following: @@ -54,8 +56,8 @@ This library depends on the following: * [Connectivity Utilities API documentation - for cy-log details](https://cypresssemiconductorco.github.io/connectivity-utilities/api_reference_manual/html/group__logging__utils.html) -* [ModusToolbox Software Environment, Quick Start Guide, Documentation, and Videos](https://www.cypress.com/products/modustoolbox-software-environment) +* [ModusToolbox™ Software Environment, Quick Start Guide, Documentation, and Videos](https://www.cypress.com/products/modustoolbox-software-environment) -* [Wi-Fi Connection Manager version](./version.txt) +* [Wi-Fi Connection Manager version](./version.xml) -* [ModusToolbox AnyCloud code examples](https://github.com/cypresssemiconductorco?q=mtb-example-anycloud%20NOT%20Deprecated) +* [ModusToolbox™ AnyCloud code examples](https://github.com/Infineon?q=mtb-example-anycloud%20NOT%20Deprecated) diff --git a/RELEASE.md b/RELEASE.md index 911c739..df0978d 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -10,6 +10,11 @@ See the [README.md](./README.md) for a complete description of the Wi-Fi Connect | cy_wcm_connect_ap API does not connect to AP, if MAC address is specified as connection parameter.| No workaround. This issue will be fixed in future release. | ## Changelog +### v2.0.4 +* Documentation updates. +* Minor updates and improvements added in connect to AP and WPS APIs. +* General bug fixes. + ### v2.0.3 * Added coverity fixes. @@ -51,11 +56,11 @@ See the [README.md](./README.md) for a complete description of the Wi-Fi Connect ### Supported Software and Tools This version of the library was validated for compatibility with the following Software and Tools: -| Software and Tools | Version | -| :--- | :----: | -| ModusToolbox Software Environment | 2.2 | -| - ModusToolbox Device Configurator | 2.20 | -| - ModusToolbox CapSense Configurator / Tuner tools | 3.10 | -| PSoC 6 Peripheral Driver Library (PDL) | 2.0.0 | -| GCC Compiler | 9.3.1 | -| IAR Compiler (only for AnyCloud) | 8.32 | +| Software and Tools | Version | +| :--- | :----: | +| ModusToolbox™ Software Environment | 2.4 | +| - ModusToolbox™ Device Configurator | 3.10 | +| - ModusToolbox™ CapSense Configurator / Tuner tools | 4.0 | +| PSoC 6 Peripheral Driver Library (PDL) | 2.3.0 | +| GCC Compiler | 10.3.1 | +| IAR Compiler (only for AnyCloud) | 8.32 | diff --git a/docs/api_reference_manual/html/group__generic__wcm__defines.html b/docs/api_reference_manual/html/group__generic__wcm__defines.html index 5571feb..f270514 100644 --- a/docs/api_reference_manual/html/group__generic__wcm__defines.html +++ b/docs/api_reference_manual/html/group__generic__wcm__defines.html @@ -221,16 +221,24 @@ #define CY_RSLT_WCM_SEMAPHORE_ERROR   (CY_RSLT_WCM_ERR_BASE + 36)  Semaphore error. More...
  -#define CY_RSLT_WCM_WPS_PBC_OVERLAP   (CY_RSLT_WCM_ERR_BASE + 37) + +#define CY_RSLT_WCM_SECURITY_NOT_FOUND   (CY_RSLT_WCM_ERR_BASE + 37) + Security type could not be determined.
+  + +#define CY_RSLT_WCM_CONNECT_IN_PROGRESS   (CY_RSLT_WCM_ERR_BASE + 38) + Connect to AP is in progress.
+  +#define CY_RSLT_WCM_WPS_PBC_OVERLAP   (CY_RSLT_WCM_ERR_BASE + 39)  WPS Error Codes. More...
  -#define CY_RSLT_WCM_WPS_ERROR_RECEIVED_WEP_CREDENTIALS   (CY_RSLT_WCM_ERR_BASE + 38) +#define CY_RSLT_WCM_WPS_ERROR_RECEIVED_WEP_CREDENTIALS   (CY_RSLT_WCM_ERR_BASE + 40)  WPS received incorrect credentials. More...
  -#define CY_RSLT_WCM_WPS_FAILED   (CY_RSLT_WCM_ERR_BASE + 39) +#define CY_RSLT_WCM_WPS_FAILED   (CY_RSLT_WCM_ERR_BASE + 41)  WPS PBC/PIN mode failed. More...
  -#define CY_RSLT_WCM_DHCP_TIMEOUT   (CY_RSLT_WCM_ERR_BASE + 40) +#define CY_RSLT_WCM_DHCP_TIMEOUT   (CY_RSLT_WCM_ERR_BASE + 42)  DHCP Error Code. More...
  @@ -819,7 +827,7 @@

- +
#define CY_RSLT_WCM_WPS_PBC_OVERLAP   (CY_RSLT_WCM_ERR_BASE + 37)#define CY_RSLT_WCM_WPS_PBC_OVERLAP   (CY_RSLT_WCM_ERR_BASE + 39)
diff --git a/docs/api_reference_manual/html/group__generic__wcm__defines.js b/docs/api_reference_manual/html/group__generic__wcm__defines.js index 4111705..3ded511 100644 --- a/docs/api_reference_manual/html/group__generic__wcm__defines.js +++ b/docs/api_reference_manual/html/group__generic__wcm__defines.js @@ -37,6 +37,8 @@ var group__generic__wcm__defines = [ "CY_RSLT_WCM_INTERFACE_NOT_UP", "group__generic__wcm__defines.html#ga3fbe3d03f2b124ee6b1f893170318b65", null ], [ "CY_RSLT_WCM_NOT_INITIALIZED", "group__generic__wcm__defines.html#ga17574dc98d92fa8947200e5550cbfeb4", null ], [ "CY_RSLT_WCM_SEMAPHORE_ERROR", "group__generic__wcm__defines.html#gaced51f450b0f6fd546796bf4528731ee", null ], + [ "CY_RSLT_WCM_SECURITY_NOT_FOUND", "group__generic__wcm__defines.html#ga2fac4f4f7090c94a3a3afe0da414bd56", null ], + [ "CY_RSLT_WCM_CONNECT_IN_PROGRESS", "group__generic__wcm__defines.html#ga7dffbb58af81a1b0e981d9082b371c3e", null ], [ "CY_RSLT_WCM_WPS_PBC_OVERLAP", "group__generic__wcm__defines.html#gab647206b775cba6ee4b7b7b19c583f7b", null ], [ "CY_RSLT_WCM_WPS_ERROR_RECEIVED_WEP_CREDENTIALS", "group__generic__wcm__defines.html#gac6347a8774ce04d4e63619b0f7bf64f1", null ], [ "CY_RSLT_WCM_WPS_FAILED", "group__generic__wcm__defines.html#ga46d6e7393784bb35e110d5fe42c004e9", null ], diff --git a/docs/api_reference_manual/html/group__group__wcm__enums.html b/docs/api_reference_manual/html/group__group__wcm__enums.html index 30d84fd..b3d83e6 100644 --- a/docs/api_reference_manual/html/group__group__wcm__enums.html +++ b/docs/api_reference_manual/html/group__group__wcm__enums.html @@ -313,6 +313,8 @@
  
CY_WCM_EVENT_IP_CHANGED,
+  CY_WCM_EVENT_INITIATED_RETRY, +
  CY_WCM_EVENT_STA_JOINED_SOFTAP,
  CY_WCM_EVENT_STA_LEFT_SOFTAP @@ -772,6 +774,8 @@

CY_WCM_EVENT_IP_CHANGED 

IP address change event.

This event is notified after connection, re-connection, and IP address change due to DHCP renewal.

+CY_WCM_EVENT_INITIATED_RETRY 

Indicates that WCM will initiate a retry logic to re-connect to the AP.

+ CY_WCM_EVENT_STA_JOINED_SOFTAP 

An STA device connected to SoftAP.

CY_WCM_EVENT_STA_LEFT_SOFTAP 

An STA device disconnected from SoftAP.

diff --git a/docs/api_reference_manual/html/group__group__wcm__enums.js b/docs/api_reference_manual/html/group__group__wcm__enums.js index 8571e8f..a305c43 100644 --- a/docs/api_reference_manual/html/group__group__wcm__enums.js +++ b/docs/api_reference_manual/html/group__group__wcm__enums.js @@ -112,6 +112,7 @@ var group__group__wcm__enums = [ "CY_WCM_EVENT_RECONNECTED", "group__group__wcm__enums.html#ggafada6a09a78bd0473f3daef54621567fab2e59655829c24bd5d0ea68622c8c56e", null ], [ "CY_WCM_EVENT_DISCONNECTED", "group__group__wcm__enums.html#ggafada6a09a78bd0473f3daef54621567fa206d74c35be5bf29e7903367287efc79", null ], [ "CY_WCM_EVENT_IP_CHANGED", "group__group__wcm__enums.html#ggafada6a09a78bd0473f3daef54621567fafe83442aa63aa747c3025d0874482c86", null ], + [ "CY_WCM_EVENT_INITIATED_RETRY", "group__group__wcm__enums.html#ggafada6a09a78bd0473f3daef54621567faf69cff70a802b9f8dae63efc10c70e1d", null ], [ "CY_WCM_EVENT_STA_JOINED_SOFTAP", "group__group__wcm__enums.html#ggafada6a09a78bd0473f3daef54621567fa89bf3f175e03aabb5951138e229392c9", null ], [ "CY_WCM_EVENT_STA_LEFT_SOFTAP", "group__group__wcm__enums.html#ggafada6a09a78bd0473f3daef54621567fa54168b9c07156a695d1de5db77f03bcb", null ] ] ], diff --git a/docs/api_reference_manual/html/group__group__wcm__functions.html b/docs/api_reference_manual/html/group__group__wcm__functions.html index b41c07a..b9451e5 100644 --- a/docs/api_reference_manual/html/group__group__wcm__functions.html +++ b/docs/api_reference_manual/html/group__group__wcm__functions.html @@ -110,9 +110,9 @@ cy_rslt_t cy_wcm_stop_scan (void)  Stops an ongoing Wi-Fi network scan. More...
  -cy_rslt_t cy_wcm_connect_ap (const cy_wcm_connect_params_t *connect_params, cy_wcm_ip_address_t *ip_addr) - Connects the STA interface to a AP using the Wi-Fi credentials and configuration parameters provided. More...
-  +cy_rslt_t cy_wcm_connect_ap (cy_wcm_connect_params_t *connect_params, cy_wcm_ip_address_t *ip_addr) + Connects the STA interface to a AP using the Wi-Fi credentials and configuration parameters provided. More...
+  cy_rslt_t cy_wcm_disconnect_ap (void)  Disconnects the STA interface from the currently connected AP. More...
  @@ -167,6 +167,9 @@ cy_rslt_t cy_wcm_get_associated_client_list (cy_wcm_mac_t *sta_list, uint8_t num_clients)  Gets the MAC address of the clients associated with the SoftAP. More...
  +cy_rslt_t cy_wcm_set_ap_ip_setting (cy_wcm_ip_setting_t *ap_ip, const char *ip_addr, const char *netmask, const char *gateway_addr, cy_wcm_ip_version_t ver) + Stores the AP settings provided by the user. More...

Function Documentation

@@ -256,7 +259,7 @@

Parameters
- +
[in]scan_callback: Callback function which receives the scan results; callback will be executed in the context of the WCM.
[in]scan_callback: Callback function which receives the scan results; callback will be executed in the context of the WCM. Scan results will be individually provided to this callback function. For more details on the scan results refer cy_wcm_scan_result_callback_t.
[in]user_data: User data to be returned as an argument in the callback function when the callback function is invoked.
[in]scan_filter: Scan filter parameter passed for scanning (optional).
@@ -287,8 +290,8 @@

-

◆ cy_wcm_connect_ap()

+ +

◆ cy_wcm_connect_ap()

@@ -296,7 +299,7 @@

cy_rslt_t cy_wcm_connect_ap ( - const cy_wcm_connect_params_t *  + cy_wcm_connect_params_tconnect_params, @@ -314,8 +317,8 @@

Connects the STA interface to a AP using the Wi-Fi credentials and configuration parameters provided.

-

On successful connection to the Wi-Fi network, the API returns the IP address.

-

This API is a blocking call; this function additionally performs the following checks: 1) Checks for and ignores duplicate connect requests to an already connected AP. 2) Checks the current connection state; if already connected, disconnects from the current Wi-Fi network and connects to the new Wi-Fi network.

+

On successful connection to the Wi-Fi network, the API returns the IP address. If the user does not know the security type of the AP then, connect_param.ap_credentials.security must be set to CY_WCM_SECURITY_UNKNOWN so that the library will internally find the security type before connecting to AP.

+

This API is a blocking call; this function additionally performs the following checks: 1) Checks for and ignores duplicate connect requests to an already connected AP. 2) Checks the current connection state; if already connected, disconnects from the current Wi-Fi network and connects to the new Wi-Fi network. 3) If the user does not know the security type of the AP, the library internally finds the security type.

Parameters
@@ -973,6 +976,66 @@

Note
If the number of connected client are less than the num_clients, then elements of sta_list beyond number of connected clients will be set to zero. Maximum number of supported client list varies for different Wi-Fi chips.
Returns
CY_RSLT_SUCCESS If getting the client list is successful; returns WCM-specific error codes otherwise.
+ + + +

◆ cy_wcm_set_ap_ip_setting()

+ +
+
+

[in]connect_params: Configuration to join the AP.
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
cy_rslt_t cy_wcm_set_ap_ip_setting (cy_wcm_ip_setting_tap_ip,
const char * ip_addr,
const char * netmask,
const char * gateway_addr,
cy_wcm_ip_version_t ver 
)
+

+ +

Stores the AP settings provided by the user.

+

NOTE: Dotted-decimal format example: 192.168.0.1

+
Parameters
+ + + + + + +
[in]ip_addr: Pointer to an array containing IP address of the AP in dotted-decimal format.
[in]netmask: Pointer to an array containing network mask in dotted-decimal format.
[in]gateway_addr: Pointer to an array containing gateway address in dotted-decimal format.
[in]ver: IP version. Possible values CY_WCM_IP_VER_V6 or CY_WCM_IP_VER_V4.
[in]ap_ip: Pointer to variable which stores AP settings.
+
+
+
Returns
CY_RSLT_SUCCESS if the AP settings are successfully stored in the user provided variable; returns WCM-specific error codes otherwise.
+

diff --git a/docs/api_reference_manual/html/group__group__wcm__functions.js b/docs/api_reference_manual/html/group__group__wcm__functions.js index 7dc929c..089d5de 100644 --- a/docs/api_reference_manual/html/group__group__wcm__functions.js +++ b/docs/api_reference_manual/html/group__group__wcm__functions.js @@ -4,7 +4,7 @@ var group__group__wcm__functions = [ "cy_wcm_deinit", "group__group__wcm__functions.html#ga5699a6a4d8f914d86022f3f973916316", null ], [ "cy_wcm_start_scan", "group__group__wcm__functions.html#gae0f0b5f3e6138bfdae943e9f7b16aa07", null ], [ "cy_wcm_stop_scan", "group__group__wcm__functions.html#ga6c18f6560c581912393e297b1560d3c7", null ], - [ "cy_wcm_connect_ap", "group__group__wcm__functions.html#ga9e8e04210ba0fc7429473d28d4643c7c", null ], + [ "cy_wcm_connect_ap", "group__group__wcm__functions.html#ga0aae35b5ae477a1a10caccf937beff0d", null ], [ "cy_wcm_disconnect_ap", "group__group__wcm__functions.html#gaabda4c932e13e0c8f29486d393a18c5b", null ], [ "cy_wcm_get_ip_addr", "group__group__wcm__functions.html#ga684ba6f1f1814d29775abaca9a029cd2", null ], [ "cy_wcm_get_ipv6_addr", "group__group__wcm__functions.html#ga6f90e612b2e00a03d13b575a3f759df9", null ], @@ -22,5 +22,6 @@ var group__group__wcm__functions = [ "cy_wcm_ping", "group__group__wcm__functions.html#gaa42251a4b728f775786d1781afbc32a2", null ], [ "cy_wcm_start_ap", "group__group__wcm__functions.html#ga4b6c66ca0e28ef817bdab02c56d180e6", null ], [ "cy_wcm_stop_ap", "group__group__wcm__functions.html#gaaf300adeaed2e9251dc85d6c85be9d72", null ], - [ "cy_wcm_get_associated_client_list", "group__group__wcm__functions.html#gac2570e24e41dc550252205489f56cc0f", null ] + [ "cy_wcm_get_associated_client_list", "group__group__wcm__functions.html#gac2570e24e41dc550252205489f56cc0f", null ], + [ "cy_wcm_set_ap_ip_setting", "group__group__wcm__functions.html#gadfcd3cdd92c62bcfd7b0ee53c7e4da7b", null ] ]; \ No newline at end of file diff --git a/docs/api_reference_manual/html/group__group__wcm__structures.html b/docs/api_reference_manual/html/group__group__wcm__structures.html index 8519931..ba85bfa 100644 --- a/docs/api_reference_manual/html/group__group__wcm__structures.html +++ b/docs/api_reference_manual/html/group__group__wcm__structures.html @@ -97,19 +97,19 @@  Structure used to pass WCM configuration to cy_wcm_init. More...
  struct  cy_wcm_ip_address_t - Structure used to receive the IP address information from cy_wcm_connect_ap. More...
+ Structure used to receive the IP address information from cy_wcm_connect_ap. More...
  union  cy_wcm_event_data_t  Structure used to receive the IP address of the STA or MAC address of the connected STA to SoftAP through the callback registered using cy_wcm_register_event_callback. More...
  struct  cy_wcm_ap_credentials_t - Structure used for providing the AP credential to connect to a AP using cy_wcm_connect_ap. More...
+ Structure used for providing the AP credential to connect to a AP using cy_wcm_connect_ap. More...
  struct  cy_wcm_ip_setting_t - Structure used to pass the static IP address information to cy_wcm_connect_ap. More...
+ Structure used to pass the static IP address information to cy_wcm_connect_ap. More...
  struct  cy_wcm_connect_params_t - Structure used to pass the Wi-Fi connection parameter information to cy_wcm_connect_ap. More...
+ Structure used to pass the Wi-Fi connection parameter information to cy_wcm_connect_ap. More...
  struct  cy_wcm_scan_filter_t  Structure used to pass scan filters to cy_wcm_start_scan. More...
diff --git a/docs/api_reference_manual/html/group__group__wcm__typedefs.html b/docs/api_reference_manual/html/group__group__wcm__typedefs.html index c89b0a9..c465b0e 100644 --- a/docs/api_reference_manual/html/group__group__wcm__typedefs.html +++ b/docs/api_reference_manual/html/group__group__wcm__typedefs.html @@ -170,9 +170,9 @@

Parameters
- + - +
[in]result_ptr: A pointer to the scan result; the scan result will be freed once the callback function returns from the application. There will not be any scan result when the scan status is CY_WCM_SCAN_COMPLETE.
[in]result_ptr: A pointer to the scan result; the scan result will be freed once the callback function returns from the application. There will not be any scan result when the scan status is CY_WCM_SCAN_COMPLETE. For more details on content of result_ptr, refer cy_wcm_scan_result_t.
[in]user_data: User-provided data.
[in]status: Status of the scan process.
[in]status: Status of the scan process. CY_WCM_SCAN_COMPLETE : Indicates the scan is completed. In this case the result_ptr will not contain any results. CY_WCM_SCAN_INCOMPLETE : Indicates the scan is in progress. In this case result_ptr contains one of the scan result.
diff --git a/docs/api_reference_manual/html/index.html b/docs/api_reference_manual/html/index.html index ec88ede..8105c31 100644 --- a/docs/api_reference_manual/html/index.html +++ b/docs/api_reference_manual/html/index.html @@ -93,15 +93,16 @@

  • Support for Wi-Fi Protected Setup (WPS) - Enrollee role.
  • Exposes Wi-Fi APIs to scan, join, and leave the Wi-Fi network.
  • Connection monitoring: Monitors active connections and link events. Automatically reconnects to the AP if the connection with the AP is lost intermittently. Notifies the connection state change through event the notification registration mechanism.
  • -
  • This library is part of the AnyCloud framework that supports connectivity applications based on FreeRTOS, lwIP, and mbed TLS.
  • +
  • This library is part of the ModusToolbox™ environment that supports connectivity applications based on FreeRTOS, lwIP, and mbed TLS.
  • The library is built on top of the abstraction-rtos library that provides RTOS abstraction API for FreeRTOS.
  • Supported Platforms

    This library and its features are supported on the following Cypress platforms:

    Dependent Libraries

    @@ -126,7 +127,7 @@

    void snippet_wcm_scan_with_ssid_filter()
    {
    cy_rslt_t result;
    cy_wcm_scan_filter_t scan_filter;
    /* SSID value which is used to filter the scan results.*/
    static const cy_wcm_ssid_t ssid = "SSID";
    /* Configure the scan filter specified by the variable ssid.*/
    memcpy(scan_filter.param.SSID, ssid, sizeof(cy_wcm_ssid_t));
    printf("\n---------------------------------------------------------------------------------\n"
    " SSID RSSI Channel \n"
    "---------------------------------------------------------------------------------\n");
    result = cy_wcm_start_scan(scan_callback, NULL, &scan_filter);
    if(result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_start_scan failed....!\n");
    }
    }

    Snippet 3: Connect to an AP

    The following snippet demonstrates scanning for WIFI_SSID to get the security type of the AP and then connect to it. After a successful connection, the device registers an event callback through which the middleware notifies the application on disconnection, reconnection, and IP change events. If the connection to AP fails, it is retried up to MAX_WIFI_RETRY_COUNT times before reporting failure.

    -
    /* Wi-Fi Credentials: Modify WIFI_SSID and WIFI_PASSWORD to match your Wi-Fi network
    * credentials.
    */
    #define WIFI_SSID "SSID"
    #define WIFI_PASSWORD "PASSWORD"
    #define MAX_WIFI_RETRY_COUNT (3u)
    #define WIFI_CONN_RETRY_INTERVAL_MSEC (100u)
    /* The size of the cy_wcm_ip_address_t array that is passed to
    * cy_wcm_get_ip_addr API. In the case of stand-alone AP or STA mode, the size of
    * the array is 1. In concurrent AP/STA mode, the size of the array is 2 where
    * the first index stores the IP address of the STA and the second index
    * stores the IP address of the AP.
    */
    #define SIZE_OF_IP_ARRAY_STA (1u)
    /* Scan callback function */
    void scan_to_get_security(cy_wcm_scan_result_t *result_ptr, void *user_data, cy_wcm_scan_status_t status)
    {
    cy_wcm_security_t* security = (cy_wcm_security_t *)user_data;
    /* Scan for SSID and pass the security type through user_data.*/
    if ((strlen((const char *)result_ptr->SSID) != 0) && (status == CY_WCM_SCAN_INCOMPLETE))
    {
    *security = result_ptr->security;
    }
    }
    void network_event_callback(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    {
    printf("Disconnected from Wi-Fi\n");
    }
    else if (CY_WCM_EVENT_RECONNECTED == event)
    {
    printf("Reconnected to Wi-Fi.\n");
    }
    /* This event corresponds to the event when the IP address of the device
    * changes.
    */
    else if (CY_WCM_EVENT_IP_CHANGED == event)
    {
    cy_wcm_get_ip_addr(CY_WCM_INTERFACE_TYPE_STA, &ip_addr, SIZE_OF_IP_ARRAY_STA);
    if (event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    printf("IP Address: %d.%d.%d.%d\n", (uint8_t)event_data->ip_addr.ip.v4,
    (uint8_t)(event_data->ip_addr.ip.v4 >> 8), (uint8_t)(event_data->ip_addr.ip.v4 >> 16),
    (uint8_t)(event_data->ip_addr.ip.v4 >> 24));
    }
    else if(event_data->ip_addr.version == CY_WCM_IP_VER_V6)
    {
    printf("IP Address: %X:%X:%X:%X\n", (uint8_t)event_data->ip_addr.ip.v6[0],
    (uint8_t)(event_data->ip_addr.ip.v6[1]), (uint8_t)(event_data->ip_addr.ip.v6[2]),
    (uint8_t)(event_data->ip_addr.ip.v6[3]));
    }
    }
    }
    void snippet_wcm_connect_ap()
    {
    cy_rslt_t result;
    cy_wcm_connect_params_t connect_param;
    cy_wcm_ip_address_t ip_address;
    cy_wcm_scan_filter_t scan_filter;
    /* Configure the scan filter specified by the macro WIFI_SSID.*/
    memcpy(scan_filter.param.SSID, WIFI_SSID, sizeof(WIFI_SSID));
    /* Scan with the filter to obtain the security type. The function waits
    * until the security type is obtained in scan_to_get_security.
    */
    cy_wcm_start_scan(scan_to_get_security, (void *)(&security), &scan_filter);
    xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
    memset(&connect_param, 0, sizeof(cy_wcm_connect_params_t));
    memset(&ip_address, 0, sizeof(cy_wcm_ip_address_t));
    memcpy(connect_param.ap_credentials.SSID, WIFI_SSID, sizeof(WIFI_SSID));
    memcpy(connect_param.ap_credentials.password, WIFI_PASSWORD, sizeof(WIFI_PASSWORD));
    connect_param.ap_credentials.security = security;
    /* Attempt to connect to Wi-Fi until a connection is made or
    * MAX_WIFI_RETRY_COUNT attempts have been made.
    */
    for (uint32_t conn_retries = 0; conn_retries < MAX_WIFI_RETRY_COUNT; conn_retries++)
    {
    result = cy_wcm_connect_ap(&connect_param, &ip_address);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("Successfully connected to Wi-Fi network '%s'.\n", connect_param.ap_credentials.SSID);
    /* Register event callbacks for changes in the Wi-Fi link status. These
    * events could be related to IP address changes, connection, and
    * disconnection events.
    */
    cy_wcm_register_event_callback(network_event_callback);
    break;
    }
    printf("Connection to Wi-Fi network failed with error code %d."
    "Retrying in %d ms...\n", (int)result, WIFI_CONN_RETRY_INTERVAL_MSEC);
    vTaskDelay(pdMS_TO_TICKS(WIFI_CONN_RETRY_INTERVAL_MSEC));
    }
    }

    +
    /* Wi-Fi Credentials: Modify WIFI_SSID and WIFI_PASSWORD to match your Wi-Fi network
    * credentials.
    */
    #define WIFI_SSID "SSID"
    #define WIFI_PASSWORD "PASSWORD"
    #define MAX_WIFI_RETRY_COUNT (3u)
    #define WIFI_CONN_RETRY_INTERVAL_MSEC (100u)
    /* The size of the cy_wcm_ip_address_t array that is passed to
    * cy_wcm_get_ip_addr API. In the case of stand-alone AP or STA mode, the size of
    * the array is 1. In concurrent AP/STA mode, the size of the array is 2 where
    * the first index stores the IP address of the STA and the second index
    * stores the IP address of the AP.
    */
    #define SIZE_OF_IP_ARRAY_STA (1u)
    /* Scan callback function */
    void scan_to_get_security(cy_wcm_scan_result_t *result_ptr, void *user_data, cy_wcm_scan_status_t status)
    {
    cy_wcm_security_t* security = (cy_wcm_security_t *)user_data;
    /* Scan for SSID and pass the security type through user_data.*/
    if ((strlen((const char *)result_ptr->SSID) != 0) && (status == CY_WCM_SCAN_INCOMPLETE))
    {
    *security = result_ptr->security;
    }
    }
    void network_event_callback(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    {
    printf("Disconnected from Wi-Fi\n");
    }
    else if (CY_WCM_EVENT_RECONNECTED == event)
    {
    printf("Reconnected to Wi-Fi.\n");
    }
    /* This event corresponds to the event when the IP address of the device
    * changes.
    */
    else if (CY_WCM_EVENT_IP_CHANGED == event)
    {
    cy_wcm_get_ip_addr(CY_WCM_INTERFACE_TYPE_STA, &ip_addr, SIZE_OF_IP_ARRAY_STA);
    if (event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    printf("IP Address: %d.%d.%d.%d\n", (uint8_t)event_data->ip_addr.ip.v4,
    (uint8_t)(event_data->ip_addr.ip.v4 >> 8), (uint8_t)(event_data->ip_addr.ip.v4 >> 16),
    (uint8_t)(event_data->ip_addr.ip.v4 >> 24));
    }
    else if(event_data->ip_addr.version == CY_WCM_IP_VER_V6)
    {
    printf("IP Address: %X:%X:%X:%X\n", (uint8_t)event_data->ip_addr.ip.v6[0],
    (uint8_t)(event_data->ip_addr.ip.v6[1]), (uint8_t)(event_data->ip_addr.ip.v6[2]),
    (uint8_t)(event_data->ip_addr.ip.v6[3]));
    }
    }
    }
    void snippet_wcm_connect_ap()
    {
    cy_rslt_t result;
    cy_wcm_connect_params_t connect_param;
    cy_wcm_ip_address_t ip_address;
    cy_wcm_scan_filter_t scan_filter;
    /* Configure the scan filter specified by the macro WIFI_SSID.*/
    memcpy(scan_filter.param.SSID, WIFI_SSID, sizeof(WIFI_SSID));
    /* Scan with the filter to obtain the security type. The function waits
    * until the security type is obtained in scan_to_get_security.
    */
    cy_wcm_start_scan(scan_to_get_security, (void *)(&security), &scan_filter);
    xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
    memset(&connect_param, 0, sizeof(cy_wcm_connect_params_t));
    memset(&ip_address, 0, sizeof(cy_wcm_ip_address_t));
    memcpy(connect_param.ap_credentials.SSID, WIFI_SSID, sizeof(WIFI_SSID));
    memcpy(connect_param.ap_credentials.password, WIFI_PASSWORD, sizeof(WIFI_PASSWORD));
    connect_param.ap_credentials.security = security;
    /* Attempt to connect to Wi-Fi until a connection is made or
    * MAX_WIFI_RETRY_COUNT attempts have been made.
    */
    for (uint32_t conn_retries = 0; conn_retries < MAX_WIFI_RETRY_COUNT; conn_retries++)
    {
    result = cy_wcm_connect_ap(&connect_param, &ip_address);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("Successfully connected to Wi-Fi network '%s'.\n", connect_param.ap_credentials.SSID);
    /* Register event callbacks for changes in the Wi-Fi link status. These
    * events could be related to IP address changes, connection, and
    * disconnection events.
    */
    cy_wcm_register_event_callback(network_event_callback);
    break;
    }
    printf("Connection to Wi-Fi network failed with error code %d."
    "Retrying in %d ms...\n", (int)result, WIFI_CONN_RETRY_INTERVAL_MSEC);
    vTaskDelay(pdMS_TO_TICKS(WIFI_CONN_RETRY_INTERVAL_MSEC));
    }
    }

    Snippet 4: Connect to an AP using WPS-Push Button

    The following snippet demonstrates joining an AP and obtaining its credentials through WPS using the push button mode. The credentials obtained are printed on the serial terminal.

    /* The value of this macro specifies the maximum number of Wi-Fi networks the
    * device can join through WPS in one call to cy_wcm_wps_enrollee. This value is
    * 2 for dual-band AP. Note that the device can obtain Wi-Fi credentials of only
    * one network and therefore can receive a maximum of 1 for single-band Wi-Fi AP or
    * 2 for dual-band AP.
    */
    #define MAX_WIFI_CREDENTIALS_COUNT (2)
    /* Device's enrollee details. Details of WPS mode, WPS authentication, and
    * encryption methods supported are provided in this structure.
    */
    const cy_wcm_wps_device_detail_t enrollee_details =
    {
    .device_name = "PSoC 6",
    .manufacturer = "Cypress",
    .model_name = "PSoC 6",
    .model_number = "1.0",
    .serial_number = "1234567",
    .device_category = CY_WCM_WPS_DEVICE_COMPUTER,
    .sub_category = 7,
    };
    void snippet_wcm_wps_pbc()
    {
    cy_rslt_t result;
    /* Store the credentials obtained through WPS.*/
    cy_wcm_wps_credential_t credentials[MAX_WIFI_CREDENTIALS_COUNT];
    cy_wcm_wps_config_t wps_config;
    /* Store the PIN used for WPS. It is unused when PBC mode is employed.*/
    char pin_string[CY_WCM_WPS_PIN_LENGTH];
    uint16_t credential_count = MAX_WIFI_CREDENTIALS_COUNT;
    /*Configure the mode of the WPS as CY_WCM_WPS_PBC_MODE.*/
    wps_config.mode = CY_WCM_WPS_PBC_MODE;
    wps_config.password = pin_string;
    memset(credentials, 0, sizeof(credentials));
    printf("Press the push button on your WPS AP.\n");
    result = cy_wcm_wps_enrollee(&wps_config, &enrollee_details, credentials, &credential_count);
    if (CY_RSLT_SUCCESS == result)
    {
    printf("WPS Success.\n");
    /* Print the WPS credentials obtained through WPS.*/
    for (uint32_t loop = 0; loop < credential_count; loop++)
    {
    printf("%d. SSID = %s, Password = %c%c******.\n", (uint8_t)loop + 1, credentials[loop].ssid, credentials[loop].passphrase[0], credentials[loop].passphrase[1]);
    }
    }
    }

    @@ -135,16 +136,16 @@

    void snippet_wcm_wps_pin()
    {
    cy_rslt_t result;
    cy_wcm_wps_credential_t credentials[MAX_WIFI_CREDENTIALS_COUNT];
    cy_wcm_wps_config_t wps_config;
    char pin_string[CY_WCM_WPS_PIN_LENGTH];
    uint16_t credential_count = MAX_WIFI_CREDENTIALS_COUNT;
    memset(credentials, 0, sizeof(credentials));
    /* Here, the WPS PIN is generated by the device. The user must
    * enter the PIN in the AP to join the network through WPS.
    */
    /*Configure the mode of WPS as CY_WCM_WPS_PIN_MODE.*/
    wps_config.mode = CY_WCM_WPS_PIN_MODE;
    wps_config.password = pin_string;
    printf("Enter this PIN: \'%s\' in your AP.\n", pin_string);
    result = cy_wcm_wps_enrollee(&wps_config, &enrollee_details, credentials, &credential_count);
    if (CY_RSLT_SUCCESS == result)
    {
    printf("WPS Success.\n");
    /* Print the WPS credentials obtained through WPS.*/
    for (uint32_t loop = 0; loop < credential_count; loop++)
    {
    printf("%d. SSID = %s, Password = %c%c******.\n", (uint8_t)loop + 1, credentials[loop].ssid, credentials[loop].passphrase[0], credentials[loop].passphrase[1]);
    }
    }
    }

    Snippet 6: Pinging Gateway IP address

    The following snippet demonstrates ping to the gateway IP address with a STA mode connection.

    -
    #define WIFI_SSID "SSID"
    #define WIFI_PASSWORD "PASSWORD"
    #define MAX_WIFI_RETRY_COUNT (3u)
    #define WIFI_CONN_RETRY_INTERVAL_MSEC (100u)
    static void print_ip4(uint32_t ip)
    {
    unsigned char bytes[4];
    bytes[0] = ip & 0xFF;
    bytes[1] = (ip >> 8) & 0xFF;
    bytes[2] = (ip >> 16) & 0xFF;
    bytes[3] = (ip >> 24) & 0xFF;
    printf("IPV4 addr = %d.%d.%d.%d\n", bytes[0], bytes[1], bytes[2], bytes[3]);
    }
    void snippet_wcm_sta_ping()
    {
    cy_rslt_t result;
    /* Initialize the Wi-Fi device as a STA.*/
    cy_wcm_connect_params_t connect_param;
    cy_wcm_ip_address_t ip_address;
    cy_wcm_ip_address_t ip_addr, gateway_addr;
    uint32_t elapsed_time_ms;
    memset(&connect_param, 0, sizeof(cy_wcm_connect_params_t));
    memset(&ip_address, 0, sizeof(cy_wcm_ip_address_t));
    memcpy(connect_param.ap_credentials.SSID, WIFI_SSID, sizeof(WIFI_SSID));
    memcpy(connect_param.ap_credentials.password, WIFI_PASSWORD, sizeof(WIFI_PASSWORD));
    /* Initialize the Wi-Fi device, Wi-Fi transport, and lwIP network stack.*/
    result = cy_wcm_init(&config);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_init failed...!\n");
    return;
    }
    printf("\n*** Starting STA Mode ***\n");
    /* Attempt to connect to Wi-Fi until a connection is made or
    * MAX_WIFI_RETRY_COUNT attempts have been made.
    */
    for (uint32_t conn_retries = 0; conn_retries < MAX_WIFI_RETRY_COUNT; conn_retries++)
    {
    result = cy_wcm_connect_ap(&connect_param, &ip_address);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("Successfully connected to Wi-Fi network '%s'.\n", connect_param.ap_credentials.SSID);
    break;
    }
    printf("Connection to Wi-Fi network failed with error code %d."
    "Retrying in %d ms...\n", (int)result, WIFI_CONN_RETRY_INTERVAL_MSEC);
    vTaskDelay(pdMS_TO_TICKS(WIFI_CONN_RETRY_INTERVAL_MSEC));
    }
    /* Get IPv4 address */
    print_ip4(ip_addr.ip.v4);
    /* Get gateway address */
    print_ip4(gateway_addr.ip.v4);
    vTaskDelay(2000);
    printf("Pinging to gateway IP address ... \n");
    /* Send PING request with 3000ms ping timeout */
    result = cy_wcm_ping(CY_WCM_INTERFACE_TYPE_STA, &gateway_addr, 3000, &elapsed_time_ms);
    if( result == CY_RSLT_SUCCESS)
    {
    printf("ping was successful time elapsed = %u\n", (uint8_t)elapsed_time_ms);
    }
    else
    {
    printf("Ping failed !!\n");
    }
    }

    +
    #define WIFI_SSID "SSID"
    #define WIFI_PASSWORD "PASSWORD"
    #define MAX_WIFI_RETRY_COUNT (3u)
    #define WIFI_CONN_RETRY_INTERVAL_MSEC (100u)
    void snippet_wcm_sta_ping()
    {
    cy_rslt_t result;
    char ip4_str[16];
    cy_nw_ip_address_t nw_ipv4;
    /* Initialize the Wi-Fi device as a STA.*/
    cy_wcm_connect_params_t connect_param;
    cy_wcm_ip_address_t ip_address;
    cy_wcm_ip_address_t ip_addr, gateway_addr;
    uint32_t elapsed_time_ms;
    memset(&connect_param, 0, sizeof(cy_wcm_connect_params_t));
    memset(&ip_address, 0, sizeof(cy_wcm_ip_address_t));
    memcpy(connect_param.ap_credentials.SSID, WIFI_SSID, sizeof(WIFI_SSID));
    memcpy(connect_param.ap_credentials.password, WIFI_PASSWORD, sizeof(WIFI_PASSWORD));
    /* Initialize the Wi-Fi device, Wi-Fi transport, and lwIP network stack.*/
    result = cy_wcm_init(&config);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_init failed...!\n");
    return;
    }
    printf("\n*** Starting STA Mode ***\n");
    /* Attempt to connect to Wi-Fi until a connection is made or
    * MAX_WIFI_RETRY_COUNT attempts have been made.
    */
    for (uint32_t conn_retries = 0; conn_retries < MAX_WIFI_RETRY_COUNT; conn_retries++)
    {
    result = cy_wcm_connect_ap(&connect_param, &ip_address);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("Successfully connected to Wi-Fi network '%s'.\n", connect_param.ap_credentials.SSID);
    break;
    }
    printf("Connection to Wi-Fi network failed with error code %d."
    "Retrying in %d ms...\n", (int)result, WIFI_CONN_RETRY_INTERVAL_MSEC);
    vTaskDelay(pdMS_TO_TICKS(WIFI_CONN_RETRY_INTERVAL_MSEC));
    }
    /* Get IPv4 address */
    nw_ipv4.ip.v4 = ip_addr.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    /* Get gateway address */
    nw_ipv4.ip.v4 = gateway_addr.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    vTaskDelay(2000);
    printf("Pinging to gateway IP address ... \n");
    /* Send PING request with 3000ms ping timeout */
    result = cy_wcm_ping(CY_WCM_INTERFACE_TYPE_STA, &gateway_addr, 3000, &elapsed_time_ms);
    if( result == CY_RSLT_SUCCESS)
    {
    printf("ping was successful time elapsed = %u\n", (uint8_t)elapsed_time_ms);
    }
    else
    {
    printf("Ping failed !!\n");
    }
    }

    Snippet 7: Soft AP start-stop

    The following snippet demonstrates Soft AP start and stop.

    -
    #define WIFI_SSID_AP "AnyCloud"
    #define WIFI_KEY_AP "abcd@9009"
    #define INITIALISER_IPV4_ADDRESS1( addr_var, addr_val ) addr_var = { CY_WCM_IP_VER_V4, { .v4 = (uint32_t)(addr_val) } }
    #define MAKE_IPV4_ADDRESS1(a, b, c, d) ((((uint32_t) d) << 24) | (((uint32_t) c) << 16) | (((uint32_t) b) << 8) |((uint32_t) a))
    static const cy_wcm_ip_setting_t ap_mode_ip_settings =
    {
    INITIALISER_IPV4_ADDRESS1( .ip_address, MAKE_IPV4_ADDRESS1( 192, 168, 0, 2 )),
    INITIALISER_IPV4_ADDRESS1( .netmask, MAKE_IPV4_ADDRESS1( 255, 255, 255, 0 )),
    INITIALISER_IPV4_ADDRESS1( .gateway, MAKE_IPV4_ADDRESS1( 192, 168, 0, 2 ) ),
    };
    #define HTONS(x) ( ( ( (x) & 0x0000FF00) >> 8 ) | ((x) & 0x000000FF) << 8 )
    static void print_ipv6(uint32_t* ipv6)
    {
    uint16_t* ipv6_ptr = (uint16_t*) ipv6;
    printf("IPV6 Address : %0x, %0x, %0x, %0x, %0x, %0x, %0x, %0x \n", HTONS(ipv6_ptr[0]), HTONS(ipv6_ptr[1]), HTONS(ipv6_ptr[2]), HTONS(ipv6_ptr[3]), HTONS(ipv6_ptr[4]), HTONS(ipv6_ptr[5]), HTONS(ipv6_ptr[6]), HTONS(ipv6_ptr[7]));
    }
    static void print_ipv4(uint32_t ip)
    {
    unsigned char bytes[4];
    bytes[0] = ip & 0xFF;
    bytes[1] = (ip >> 8) & 0xFF;
    bytes[2] = (ip >> 16) & 0xFF;
    bytes[3] = (ip >> 24) & 0xFF;
    printf("IPV4 addr = %d.%d.%d.%d\n", bytes[0], bytes[1], bytes[2], bytes[3]);
    }
    static void ap_event_cb(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    printf("######### Received event changed from wcm, event = %d #######\n", event);
    {
    printf("Network is down! \n");
    }
    {
    printf("Network is up again! \n");
    }
    {
    printf("Connecting to AP ... \n");
    }
    {
    printf("Connected to AP and network is up !! \n");
    }
    {
    printf("Connection to AP Failed ! \n");
    }
    {
    if(event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    print_ip4(event_data->ip_addr.ip.v4);
    }
    }
    {
    printf("mac address of the STA which joined = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    }
    {
    printf("mac address of the STA which left = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    }
    }
    void snippet_wcm_ap_start_stop()
    {
    cy_rslt_t result;
    /* Initialize the Wi-Fi device, Wi-Fi transport, and lwIP network stack.*/
    result = cy_wcm_init(&config);
    if(result != CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_init failed...!\n");
    return;
    }
    memset(&ap_conf, 0, sizeof(cy_wcm_ap_config_t));
    ap_conf.channel = 1;
    memcpy(ap_conf.ap_credentials.SSID, WIFI_SSID_AP, strlen(WIFI_SSID_AP) + 1);
    memcpy(ap_conf.ap_credentials.password, WIFI_KEY_AP, strlen(WIFI_KEY_AP) + 1);
    ap_conf.ip_settings.ip_address = ap_mode_ip_settings.ip_address;
    ap_conf.ip_settings.netmask = ap_mode_ip_settings.netmask;
    ap_conf.ip_settings.gateway = ap_mode_ip_settings.gateway;
    printf("configured ip address of the AP = %u \n", (uint8_t)ap_conf.ip_settings.ip_address.ip.v4);
    print_ipv4(ap_conf.ip_settings.ip_address.ip.v4);
    /* Start AP */
    result = cy_wcm_start_ap(&ap_conf);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_start_ap failed....! \n");
    return;
    }
    /* Register AP event callback */
    result = cy_wcm_register_event_callback(&ap_event_cb);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_register_event_callback failed....! \n");
    return;
    }
    /* Link Local IPV6 AP address for AP */
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_get_ipv6_addr failed....! \n");
    return;
    }
    print_ipv6(ipv6_addr.ip.v6);
    /* wait for 30 seconds to check whether AP is visible or not */
    vTaskDelay(30000);
    /* Stop AP */
    result = cy_wcm_stop_ap();
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_stop_ap failed....! \n");
    }
    return;
    }

    +
    #define WIFI_SSID_AP "AnyCloud"
    #define WIFI_KEY_AP "abcd@9009"
    static cy_wcm_ip_setting_t ap_mode_ip_settings;
    static void ap_event_cb(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    char ip4_str[16];
    cy_nw_ip_address_t nw_ipv4;
    printf("######### Received event changed from wcm, event = %d #######\n", event);
    switch(event)
    {
    {
    printf("Network is down! \n");
    break;
    }
    {
    printf("Network is up again! \n");
    break;
    }
    {
    printf("Connecting to AP ... \n");
    break;
    }
    {
    printf("Connected to AP and network is up !! \n");
    break;
    }
    {
    printf("Connection to AP Failed ! \n");
    break;
    }
    {
    if(event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    nw_ipv4.ip.v4 = event_data->ip_addr.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    }
    break;
    }
    {
    printf("mac address of the STA which joined = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    break;
    }
    {
    printf("mac address of the STA which left = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    break;
    }
    default:
    {
    printf("Invalid event \n");
    break;
    }
    }
    }
    void snippet_wcm_ap_start_stop()
    {
    cy_rslt_t result;
    char ip6_str[40];
    char ip4_str[16];
    char *ip = "192.168.0.2";
    char *netmask = "255.255.255.0";
    char *gateway = "192.168.0.2";
    cy_nw_ip_address_t nw_ipv4;
    cy_nw_ip_address_t nw_ipv6;
    /* Initialize the Wi-Fi device, Wi-Fi transport, and lwIP network stack.*/
    result = cy_wcm_init(&config);
    if(result != CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_init failed...!\n");
    return;
    }
    /* AP settings */
    cy_wcm_set_ap_ip_setting(&ap_mode_ip_settings, ip, netmask, gateway, CY_WCM_IP_VER_V4);
    memset(&ap_conf, 0, sizeof(cy_wcm_ap_config_t));
    ap_conf.channel = 1;
    memcpy(ap_conf.ap_credentials.SSID, WIFI_SSID_AP, strlen(WIFI_SSID_AP) + 1);
    memcpy(ap_conf.ap_credentials.password, WIFI_KEY_AP, strlen(WIFI_KEY_AP) + 1);
    ap_conf.ip_settings.ip_address = ap_mode_ip_settings.ip_address;
    ap_conf.ip_settings.netmask = ap_mode_ip_settings.netmask;
    ap_conf.ip_settings.gateway = ap_mode_ip_settings.gateway;
    printf("configured ip address of the AP = %u \n", (uint8_t)ap_conf.ip_settings.ip_address.ip.v4);
    nw_ipv4.ip.v4 = ap_conf.ip_settings.ip_address.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    /* Start AP */
    result = cy_wcm_start_ap(&ap_conf);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_start_ap failed....! \n");
    return;
    }
    /* Register AP event callback */
    result = cy_wcm_register_event_callback(&ap_event_cb);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_register_event_callback failed....! \n");
    return;
    }
    /* Link Local IPV6 AP address for AP */
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_get_ipv6_addr failed....! \n");
    return;
    }
    nw_ipv6.ip.v6[0] = ipv6_addr.ip.v6[0];
    nw_ipv6.ip.v6[1] = ipv6_addr.ip.v6[1];
    nw_ipv6.ip.v6[2] = ipv6_addr.ip.v6[2];
    nw_ipv6.ip.v6[3] = ipv6_addr.ip.v6[3];
    cy_nw_ntoa_ipv6(&nw_ipv6, ip6_str);
    printf("IPV6 address: %s\n", ip6_str);
    /* wait for 30 seconds to check whether AP is visible or not */
    vTaskDelay(30000);
    /* Stop AP */
    result = cy_wcm_stop_ap();
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_stop_ap failed....! \n");
    }
    return;
    }

    Snippet 8: Clients connected to the Soft AP

    The following snippet demonstrates usage of API function cy_wcm_get_associated_client_list to get the list of clients connected to the Soft AP.

    -
    #define WIFI_SSID_AP "AnyCloud"
    #define WIFI_KEY_AP "abcd@9009"
    #define INITIALISER_IPV4_ADDRESS1( addr_var, addr_val ) addr_var = { CY_WCM_IP_VER_V4, { .v4 = (uint32_t)(addr_val) } }
    #define MAKE_IPV4_ADDRESS1(a, b, c, d) ((((uint32_t) d) << 24) | (((uint32_t) c) << 16) | (((uint32_t) b) << 8) |((uint32_t) a))
    static const cy_wcm_ip_setting_t ap_ip_settings =
    {
    INITIALISER_IPV4_ADDRESS1( .ip_address, MAKE_IPV4_ADDRESS1( 192, 168, 0, 2 )),
    INITIALISER_IPV4_ADDRESS1( .netmask, MAKE_IPV4_ADDRESS1( 255, 255, 255, 0 )),
    INITIALISER_IPV4_ADDRESS1( .gateway, MAKE_IPV4_ADDRESS1( 192, 168, 0, 2 ) ),
    };
    static void print_ip_v6(uint32_t* ipv6)
    {
    uint16_t* ipv6_ptr = (uint16_t*) ipv6;
    printf("IPV6 Address : %0x, %0x, %0x, %0x, %0x, %0x, %0x, %0x \n", HTONS(ipv6_ptr[0]), HTONS(ipv6_ptr[1]), HTONS(ipv6_ptr[2]), HTONS(ipv6_ptr[3]), HTONS(ipv6_ptr[4]), HTONS(ipv6_ptr[5]), HTONS(ipv6_ptr[6]), HTONS(ipv6_ptr[7]));
    }
    static void print_ip_v4(uint32_t ip)
    {
    unsigned char bytes[4];
    bytes[0] = ip & 0xFF;
    bytes[1] = (ip >> 8) & 0xFF;
    bytes[2] = (ip >> 16) & 0xFF;
    bytes[3] = (ip >> 24) & 0xFF;
    printf("IPV4 addr = %d.%d.%d.%d\n", bytes[0], bytes[1], bytes[2], bytes[3]);
    }
    static void ap_eve_callback(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    printf("######### Received event changed from wcm, event = %d #######\n", event);
    {
    printf("Network is down! \n");
    }
    {
    printf("Network is up again! \n");
    }
    {
    printf("Connecting to AP ... \n");
    }
    {
    printf("Connected to AP and network is up !! \n");
    }
    {
    printf("Connection to AP Failed ! \n");
    }
    {
    if(event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    print_ip_v4(event_data->ip_addr.ip.v4);
    }
    }
    {
    printf("mac address of the STA which joined = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    }
    {
    printf("mac address of the STA which left = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    }
    }
    void snippet_wcm_ap_get_client()
    {
    cy_rslt_t result;
    /* Initialize the Wi-Fi device, Wi-Fi transport, and lwIP network stack.*/
    result = cy_wcm_init(&config);
    if(result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_init failed...!\n");
    return;
    }
    memset(&ap_conf, 0, sizeof(cy_wcm_ap_config_t));
    ap_conf.channel = 1;
    memcpy(ap_conf.ap_credentials.SSID, WIFI_SSID_AP, strlen(WIFI_SSID_AP) + 1);
    memcpy(ap_conf.ap_credentials.password, WIFI_KEY_AP, strlen(WIFI_KEY_AP) + 1);
    ap_conf.ip_settings.ip_address = ap_ip_settings.ip_address;
    ap_conf.ip_settings.netmask = ap_ip_settings.netmask;
    ap_conf.ip_settings.gateway = ap_ip_settings.gateway;
    printf("configured ip address of the AP = %u \n", (uint8_t)ap_conf.ip_settings.ip_address.ip.v4);
    print_ip_v4(ap_conf.ip_settings.ip_address.ip.v4);
    /* Start AP */
    result = cy_wcm_start_ap(&ap_conf);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_start_ap failed....! \n");
    return;
    }
    /* Register AP event callback */
    result = cy_wcm_register_event_callback(&ap_eve_callback);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_register_event_callback failed....! \n");
    return;
    }
    /* Link Local IPV6 AP address for AP */
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_get_ipv6_addr failed....! \n");
    return;
    }
    print_ip_v6(ipv6_addr.ip.v6);
    /* wait for 30 seconds for a client to connect */
    vTaskDelay(30000);
    /* get connected client */
    cy_wcm_mac_t mac_add;
    result = cy_wcm_get_associated_client_list(&mac_add, 1);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_get_associated_client_list failed....! \n");
    return;
    }
    printf("mac address obtained from cy_wcm_get_associated_client_list = %02X : %02X : %02X : %02X : %02X : %02X \n",
    mac_add[0], mac_add[1], mac_add[2],mac_add[3], mac_add[4], mac_add[5]);
    return;
    }

    +
    #define WIFI_SSID_AP "AnyCloud"
    #define WIFI_KEY_AP "abcd@9009"
    static cy_wcm_ip_setting_t ap_ip_settings;
    static void ap_eve_callback(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    char ip4_str[16];
    cy_nw_ip_address_t nw_ipv4;
    printf("######### Received event changed from wcm, event = %d #######\n", event);
    switch(event)
    {
    {
    printf("Network is down! \n");
    break;
    }
    {
    printf("Network is up again! \n");
    break;
    }
    {
    printf("Connecting to AP ... \n");
    break;
    }
    {
    printf("Connected to AP and network is up !! \n");
    break;
    }
    {
    printf("Connection to AP Failed ! \n");
    break;
    }
    {
    if(event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    nw_ipv4.ip.v4 = event_data->ip_addr.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    }
    break;
    }
    {
    printf("mac address of the STA which joined = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    break;
    }
    {
    printf("mac address of the STA which left = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    break;
    }
    default:
    {
    printf("Invalid event \n");
    break;
    }
    }
    }
    void snippet_wcm_ap_get_client()
    {
    cy_rslt_t result;
    char ip6_str[40];
    char ip4_str[16];
    char *ip = "192.168.0.2";
    char *netmask = "255.255.255.0";
    char *gateway = "192.168.0.2";
    cy_nw_ip_address_t nw_ipv6;
    cy_nw_ip_address_t nw_ipv4;
    /* Initialize the Wi-Fi device, Wi-Fi transport, and lwIP network stack.*/
    result = cy_wcm_init(&config);
    if(result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_init failed...!\n");
    return;
    }
    /* AP settings */
    cy_wcm_set_ap_ip_setting(&ap_ip_settings, ip, netmask, gateway, CY_WCM_IP_VER_V4);
    memset(&ap_conf, 0, sizeof(cy_wcm_ap_config_t));
    ap_conf.channel = 1;
    memcpy(ap_conf.ap_credentials.SSID, WIFI_SSID_AP, strlen(WIFI_SSID_AP) + 1);
    memcpy(ap_conf.ap_credentials.password, WIFI_KEY_AP, strlen(WIFI_KEY_AP) + 1);
    ap_conf.ip_settings.ip_address = ap_ip_settings.ip_address;
    ap_conf.ip_settings.netmask = ap_ip_settings.netmask;
    ap_conf.ip_settings.gateway = ap_ip_settings.gateway;
    printf("configured ip address of the AP = %u \n", (uint8_t)ap_conf.ip_settings.ip_address.ip.v4);
    nw_ipv4.ip.v4 = ap_conf.ip_settings.ip_address.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    /* Start AP */
    result = cy_wcm_start_ap(&ap_conf);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_start_ap failed....! \n");
    return;
    }
    /* Register AP event callback */
    result = cy_wcm_register_event_callback(&ap_eve_callback);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_register_event_callback failed....! \n");
    return;
    }
    /* Link Local IPV6 AP address for AP */
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_get_ipv6_addr failed....! \n");
    return;
    }
    nw_ipv6.ip.v6[0] = ipv6_addr.ip.v6[0];
    nw_ipv6.ip.v6[1] = ipv6_addr.ip.v6[1];
    nw_ipv6.ip.v6[2] = ipv6_addr.ip.v6[2];
    nw_ipv6.ip.v6[3] = ipv6_addr.ip.v6[3];
    cy_nw_ntoa_ipv6(&nw_ipv6, ip6_str);
    printf("IPV6 address: %s\n", ip6_str);
    /* wait for 30 seconds for a client to connect */
    vTaskDelay(30000);
    /* get connected client */
    cy_wcm_mac_t mac_add;
    result = cy_wcm_get_associated_client_list(&mac_add, 1);
    if( result != CY_RSLT_SUCCESS )
    {
    printf("\ncy_wcm_get_associated_client_list failed....! \n");
    return;
    }
    printf("mac address obtained from cy_wcm_get_associated_client_list = %02X : %02X : %02X : %02X : %02X : %02X \n",
    mac_add[0], mac_add[1], mac_add[2],mac_add[3], mac_add[4], mac_add[5]);
    return;
    }

    Snippet 9: AP+STA concurrent mode

    The following snippet demonstrates AP+STA concurrent mode operation.

    -
    /* Wi-Fi Credentials: Modify WIFI_SSID and WIFI_PASSWORD to match your Wi-Fi network
    * credentials.
    */
    #define WIFI_SSID "SSID"
    #define WIFI_PASSWORD "PASSWORD"
    #define WIFI_SSID_AP "AnyCloud"
    #define WIFI_KEY_AP "abcd@9009"
    #define MAX_WIFI_RETRY_COUNT (3u)
    #define WIFI_CONN_RETRY_INTERVAL_MSEC (100u)
    /* The size of the cy_wcm_ip_address_t array that is passed to
    * cy_wcm_get_ip_addr API. In the case of stand-alone AP or STA mode, the size of
    * the array is 1. In concurrent AP/STA mode, the size of the array is 2 where
    * the first index stores the IP address of the STA and the second index
    * stores the IP address of the AP.
    */
    #define SIZE_OF_IP_ARRAY_STA (1u)
    #define INITIALISER_IPV4_ADDRESS1( addr_var, addr_val ) addr_var = { CY_WCM_IP_VER_V4, { .v4 = (uint32_t)(addr_val) } }
    #define MAKE_IPV4_ADDRESS1(a, b, c, d) ((((uint32_t) d) << 24) | (((uint32_t) c) << 16) | (((uint32_t) b) << 8) |((uint32_t) a))
    static const cy_wcm_ip_setting_t ap_sta_mode_ip_settings =
    {
    INITIALISER_IPV4_ADDRESS1( .ip_address, MAKE_IPV4_ADDRESS1( 192, 168, 0, 2 )),
    INITIALISER_IPV4_ADDRESS1( .netmask, MAKE_IPV4_ADDRESS1( 255, 255, 255, 0 )),
    INITIALISER_IPV4_ADDRESS1( .gateway, MAKE_IPV4_ADDRESS1( 192, 168, 0, 2 ) ),
    };
    static void print_ip_6(uint32_t* ipv6)
    {
    uint16_t* ipv6_ptr = (uint16_t*) ipv6;
    printf("IPV6 Address : %0x, %0x, %0x, %0x, %0x, %0x, %0x, %0x \n", HTONS(ipv6_ptr[0]), HTONS(ipv6_ptr[1]), HTONS(ipv6_ptr[2]), HTONS(ipv6_ptr[3]), HTONS(ipv6_ptr[4]), HTONS(ipv6_ptr[5]), HTONS(ipv6_ptr[6]), HTONS(ipv6_ptr[7]));
    }
    static void print_ip_4(uint32_t ip)
    {
    unsigned char bytes[4];
    bytes[0] = ip & 0xFF;
    bytes[1] = (ip >> 8) & 0xFF;
    bytes[2] = (ip >> 16) & 0xFF;
    bytes[3] = (ip >> 24) & 0xFF;
    printf("IPV4 addr = %d.%d.%d.%d\n", bytes[0], bytes[1], bytes[2], bytes[3]);
    }
    void sta_event_callback(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    {
    printf("Disconnected from Wi-Fi\n");
    }
    else if (CY_WCM_EVENT_RECONNECTED == event)
    {
    printf("Reconnected to Wi-Fi.\n");
    }
    /* This event corresponds to the event when the IP address of the device
    * changes.
    */
    else if (CY_WCM_EVENT_IP_CHANGED == event)
    {
    cy_wcm_get_ip_addr(CY_WCM_INTERFACE_TYPE_STA, &ip_addr, SIZE_OF_IP_ARRAY_STA);
    if (event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    printf("IP Address: %d.%d.%d.%d\n", (uint8_t)event_data->ip_addr.ip.v4,
    (uint8_t)(event_data->ip_addr.ip.v4 >> 8), (uint8_t)(event_data->ip_addr.ip.v4 >> 16),
    (uint8_t)(event_data->ip_addr.ip.v4 >> 24));
    }
    else if(event_data->ip_addr.version == CY_WCM_IP_VER_V6)
    {
    printf("IP Address: %X:%X:%X:%X\n", (uint8_t)event_data->ip_addr.ip.v6[0],
    (uint8_t)(event_data->ip_addr.ip.v6[1]), (uint8_t)(event_data->ip_addr.ip.v6[2]),
    (uint8_t)(event_data->ip_addr.ip.v6[3]));
    }
    }
    }
    static void ap_event_callback(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    printf("######### Received event changed from wcm, event = %d #######\n", event);
    {
    printf("Network is down! \n");
    }
    {
    printf("Network is up again! \n");
    }
    {
    printf("Connecting to AP ... \n");
    }
    {
    printf("Connected to AP and network is up !! \n");
    }
    {
    printf("Connection to AP Failed ! \n");
    }
    {
    if(event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    print_ip_4(event_data->ip_addr.ip.v4);
    }
    }
    {
    printf("mac address of the STA which joined = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    }
    {
    printf("mac address of the STA which left = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    }
    }
    void snippet_wcm_concurrent_mode()
    {
    cy_rslt_t result;
    /* Initialize the Wi-Fi device as a STA.*/
    cy_wcm_connect_params_t connect_param;
    cy_wcm_ip_address_t ip_address,ipv4_addr,ipv6_addr;
    memset(&connect_param, 0, sizeof(cy_wcm_connect_params_t));
    memset(&ip_address, 0, sizeof(cy_wcm_ip_address_t));
    memset(&security, 0, sizeof(cy_wcm_security_t));
    memcpy(connect_param.ap_credentials.SSID, WIFI_SSID, sizeof(WIFI_SSID));
    memcpy(connect_param.ap_credentials.password, WIFI_PASSWORD, sizeof(WIFI_PASSWORD));
    connect_param.ap_credentials.security = security;
    /* Initialize the Wi-Fi device, Wi-Fi transport, and lwIP network stack.*/
    result = cy_wcm_init(&config);
    if(result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_init failed...!\n");
    return;
    }
    printf("\n*** Starting STA Mode ***\n");
    /* Attempt to connect to Wi-Fi until a connection is made or
    * MAX_WIFI_RETRY_COUNT attempts have been made.
    */
    for (uint32_t conn_retries = 0; conn_retries < MAX_WIFI_RETRY_COUNT; conn_retries++)
    {
    result = cy_wcm_connect_ap(&connect_param, &ip_address);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("Successfully connected to Wi-Fi network '%s'.\n", connect_param.ap_credentials.SSID);
    /* Register event callbacks for changes in the Wi-Fi link status. These
    * events could be related to IP address changes, connection, and
    * disconnection events.
    */
    cy_wcm_register_event_callback(sta_event_callback);
    break;
    }
    printf("Connection to Wi-Fi network failed with error code %d."
    "Retrying in %d ms...\n", (int)result, WIFI_CONN_RETRY_INTERVAL_MSEC);
    vTaskDelay(pdMS_TO_TICKS(WIFI_CONN_RETRY_INTERVAL_MSEC));
    }
    printf("\n*** Starting AP Mode ***\n");
    memset(&ap_conf, 0, sizeof(cy_wcm_ap_config_t));
    memset(&ipv4_addr, 0, sizeof(cy_wcm_ip_address_t));
    memset(&ipv6_addr, 0, sizeof(cy_wcm_ip_address_t));
    ap_conf.channel = 1;
    memcpy(ap_conf.ap_credentials.SSID, WIFI_SSID_AP, strlen(WIFI_SSID_AP) + 1);
    memcpy(ap_conf.ap_credentials.password, WIFI_KEY_AP, strlen(WIFI_KEY_AP) + 1);
    ap_conf.ip_settings.ip_address = ap_sta_mode_ip_settings.ip_address;
    ap_conf.ip_settings.netmask = ap_sta_mode_ip_settings.netmask;
    ap_conf.ip_settings.gateway = ap_sta_mode_ip_settings.gateway;
    printf("configured ip address of the AP = %u \n", (uint8_t)ap_conf.ip_settings.ip_address.ip.v4);
    print_ip4(ap_conf.ip_settings.ip_address.ip.v4);
    cy_wcm_register_event_callback(&ap_event_callback);
    result = cy_wcm_start_ap(&ap_conf);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_start_ap failed...! \n");
    return;
    }
    printf("\nAP started successfully... \n");
    /* Get IPV4 address for AP */
    result = cy_wcm_get_ip_addr(CY_WCM_INTERFACE_TYPE_AP, &ipv4_addr, 1);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_get_ip_addr failed...! \n");
    return;
    }
    printf("\nIPV4 address of AP : ");
    print_ip_4(ipv4_addr.ip.v4);
    /* Get IPV6 address for AP */
    printf("Link Local IPV6 AP address \n");
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_get_ipv6_addr failed...! \n");
    return;
    }
    printf("\nLink Local IPV6 AP address : ");
    print_ip_6(ipv6_addr.ip.v6);
    /* Get Link Local IPV6 STA address */
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_get_ipv6_addr failed...! \n");
    return;
    }
    printf("\nLink Local IPV6 STA address : ");
    print_ip_6(ipv6_addr.ip.v6);
    /* Get MAC address of both STA and AP interface using CY_WCM_INTERFACE_TYPE_AP_STA */
    cy_wcm_mac_t *mac_addr_ptr;
    mac_addr_ptr = (cy_wcm_mac_t*)malloc(sizeof(cy_wcm_mac_t) *2);
    cy_wcm_mac_t sta_mac, ap_mac;
    memcpy(&sta_mac, mac_addr_ptr, sizeof(sta_mac));
    printf("mac address of STA = %02X : %02X : %02X : %02X : %02X : %02X \n",
    sta_mac[0], sta_mac[1], sta_mac[2],sta_mac[3], sta_mac[4], sta_mac[5]);
    mac_addr_ptr++;
    memcpy(&ap_mac, mac_addr_ptr, sizeof(ap_mac));
    printf("mac address AP = %02X : %02X : %02X : %02X : %02X : %02X \n",
    ap_mac[0], ap_mac[1], ap_mac[2],ap_mac[3], ap_mac[4], ap_mac[5]);
    free(mac_addr_ptr);
    }
    +
    /* Wi-Fi Credentials: Modify WIFI_SSID and WIFI_PASSWORD to match your Wi-Fi network
    * credentials.
    */
    #define WIFI_SSID "SSID"
    #define WIFI_PASSWORD "PASSWORD"
    #define WIFI_SSID_AP "AnyCloud"
    #define WIFI_KEY_AP "abcd@9009"
    #define MAX_WIFI_RETRY_COUNT (3u)
    #define WIFI_CONN_RETRY_INTERVAL_MSEC (100u)
    /* The size of the cy_wcm_ip_address_t array that is passed to
    * cy_wcm_get_ip_addr API. In the case of stand-alone AP or STA mode, the size of
    * the array is 1. In concurrent AP/STA mode, the size of the array is 2 where
    * the first index stores the IP address of the STA and the second index
    * stores the IP address of the AP.
    */
    #define SIZE_OF_IP_ARRAY_STA (1u)
    static cy_wcm_ip_setting_t ap_sta_mode_ip_settings;
    void sta_event_callback(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    {
    printf("Disconnected from Wi-Fi\n");
    }
    else if (CY_WCM_EVENT_RECONNECTED == event)
    {
    printf("Reconnected to Wi-Fi.\n");
    }
    /* This event corresponds to the event when the IP address of the device
    * changes.
    */
    else if (CY_WCM_EVENT_IP_CHANGED == event)
    {
    cy_wcm_get_ip_addr(CY_WCM_INTERFACE_TYPE_STA, &ip_addr, SIZE_OF_IP_ARRAY_STA);
    if (event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    printf("IP Address: %d.%d.%d.%d\n", (uint8_t)event_data->ip_addr.ip.v4,
    (uint8_t)(event_data->ip_addr.ip.v4 >> 8), (uint8_t)(event_data->ip_addr.ip.v4 >> 16),
    (uint8_t)(event_data->ip_addr.ip.v4 >> 24));
    }
    else if(event_data->ip_addr.version == CY_WCM_IP_VER_V6)
    {
    printf("IP Address: %X:%X:%X:%X\n", (uint8_t)event_data->ip_addr.ip.v6[0],
    (uint8_t)(event_data->ip_addr.ip.v6[1]), (uint8_t)(event_data->ip_addr.ip.v6[2]),
    (uint8_t)(event_data->ip_addr.ip.v6[3]));
    }
    }
    }
    static void ap_event_callback(cy_wcm_event_t event, cy_wcm_event_data_t *event_data)
    {
    char ip4_str[16];
    cy_nw_ip_address_t nw_ipv4;
    printf("######### Received event changed from wcm, event = %d #######\n", event);
    switch(event)
    {
    {
    printf("Network is down! \n");
    break;
    }
    {
    printf("Network is up again! \n");
    break;
    }
    {
    printf("Connecting to AP ... \n");
    break;
    }
    {
    printf("Connected to AP and network is up !! \n");
    break;
    }
    {
    printf("Connection to AP Failed ! \n");
    break;
    }
    {
    if(event_data->ip_addr.version == CY_WCM_IP_VER_V4)
    {
    nw_ipv4.ip.v4 = event_data->ip_addr.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    }
    break;
    }
    {
    printf("mac address of the STA which joined = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    break;
    }
    {
    printf("mac address of the STA which left = %02X : %02X : %02X : %02X : %02X : %02X \n",
    event_data->sta_mac[0], event_data->sta_mac[1], event_data->sta_mac[2],
    event_data->sta_mac[3], event_data->sta_mac[4], event_data->sta_mac[5]);
    break;
    }
    default:
    {
    printf("Invalid event \n");
    break;
    }
    }
    }
    void snippet_wcm_concurrent_mode()
    {
    cy_rslt_t result;
    char ip6_str[40];
    char ip4_str[16];
    char *ip = "192.168.0.2";
    char *netmask = "255.255.255.0";
    char *gateway = "192.168.0.2";
    cy_nw_ip_address_t nw_ipv4;
    cy_nw_ip_address_t nw_ipv6;
    /* Initialize the Wi-Fi device as a STA.*/
    cy_wcm_connect_params_t connect_param;
    cy_wcm_ip_address_t ip_address,ipv4_addr,ipv6_addr;
    memset(&connect_param, 0, sizeof(cy_wcm_connect_params_t));
    memset(&ip_address, 0, sizeof(cy_wcm_ip_address_t));
    memset(&security, 0, sizeof(cy_wcm_security_t));
    memcpy(connect_param.ap_credentials.SSID, WIFI_SSID, sizeof(WIFI_SSID));
    memcpy(connect_param.ap_credentials.password, WIFI_PASSWORD, sizeof(WIFI_PASSWORD));
    connect_param.ap_credentials.security = security;
    /* Initialize the Wi-Fi device, Wi-Fi transport, and lwIP network stack.*/
    result = cy_wcm_init(&config);
    if(result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_init failed...!\n");
    return;
    }
    /* AP settings */
    cy_wcm_set_ap_ip_setting(&ap_sta_mode_ip_settings, ip, netmask, gateway, CY_WCM_IP_VER_V4);
    printf("\n*** Starting STA Mode ***\n");
    /* Attempt to connect to Wi-Fi until a connection is made or
    * MAX_WIFI_RETRY_COUNT attempts have been made.
    */
    for (uint32_t conn_retries = 0; conn_retries < MAX_WIFI_RETRY_COUNT; conn_retries++)
    {
    result = cy_wcm_connect_ap(&connect_param, &ip_address);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("Successfully connected to Wi-Fi network '%s'.\n", connect_param.ap_credentials.SSID);
    /* Register event callbacks for changes in the Wi-Fi link status. These
    * events could be related to IP address changes, connection, and
    * disconnection events.
    */
    cy_wcm_register_event_callback(sta_event_callback);
    break;
    }
    printf("Connection to Wi-Fi network failed with error code %d."
    "Retrying in %d ms...\n", (int)result, WIFI_CONN_RETRY_INTERVAL_MSEC);
    vTaskDelay(pdMS_TO_TICKS(WIFI_CONN_RETRY_INTERVAL_MSEC));
    }
    printf("\n*** Starting AP Mode ***\n");
    memset(&ap_conf, 0, sizeof(cy_wcm_ap_config_t));
    memset(&ipv4_addr, 0, sizeof(cy_wcm_ip_address_t));
    memset(&ipv6_addr, 0, sizeof(cy_wcm_ip_address_t));
    ap_conf.channel = 1;
    memcpy(ap_conf.ap_credentials.SSID, WIFI_SSID_AP, strlen(WIFI_SSID_AP) + 1);
    memcpy(ap_conf.ap_credentials.password, WIFI_KEY_AP, strlen(WIFI_KEY_AP) + 1);
    ap_conf.ip_settings.ip_address = ap_sta_mode_ip_settings.ip_address;
    ap_conf.ip_settings.netmask = ap_sta_mode_ip_settings.netmask;
    ap_conf.ip_settings.gateway = ap_sta_mode_ip_settings.gateway;
    printf("configured ip address of the AP = %u \n", (uint8_t)ap_conf.ip_settings.ip_address.ip.v4);
    nw_ipv4.ip.v4 = ap_conf.ip_settings.ip_address.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    cy_wcm_register_event_callback(&ap_event_callback);
    result = cy_wcm_start_ap(&ap_conf);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_start_ap failed...! \n");
    return;
    }
    printf("\nAP started successfully... \n");
    /* Get IPV4 address for AP */
    result = cy_wcm_get_ip_addr(CY_WCM_INTERFACE_TYPE_AP, &ipv4_addr, 1);
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_get_ip_addr failed...! \n");
    return;
    }
    printf("\nIPV4 address of AP : ");
    nw_ipv4.ip.v4 = ipv4_addr.ip.v4;
    cy_nw_ntoa(&nw_ipv4, ip4_str);
    printf("IPV4 address: %s\n", ip4_str);
    /* Get IPV6 address for AP */
    printf("Link Local IPV6 AP address \n");
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_get_ipv6_addr failed...! \n");
    return;
    }
    printf("\nLink Local IPV6 AP address : ");
    nw_ipv6.ip.v6[0] = ipv6_addr.ip.v6[0];
    nw_ipv6.ip.v6[1] = ipv6_addr.ip.v6[1];
    nw_ipv6.ip.v6[2] = ipv6_addr.ip.v6[2];
    nw_ipv6.ip.v6[3] = ipv6_addr.ip.v6[3];
    cy_nw_ntoa_ipv6(&nw_ipv6, ip6_str);
    printf("IPV6 address: %s\n", ip6_str);
    /* Get Link Local IPV6 STA address */
    if (result == CY_RSLT_SUCCESS)
    {
    printf("\ncy_wcm_get_ipv6_addr failed...! \n");
    return;
    }
    printf("\nLink Local IPV6 STA address : ");
    nw_ipv6.ip.v6[0] = ipv6_addr.ip.v6[0];
    nw_ipv6.ip.v6[1] = ipv6_addr.ip.v6[1];
    nw_ipv6.ip.v6[2] = ipv6_addr.ip.v6[2];
    nw_ipv6.ip.v6[3] = ipv6_addr.ip.v6[3];
    cy_nw_ntoa_ipv6(&nw_ipv6, ip6_str);
    printf("IPV6 address: %s\n", ip6_str);
    /* Get MAC address of both STA and AP interface using CY_WCM_INTERFACE_TYPE_AP_STA */
    cy_wcm_mac_t *mac_addr_ptr;
    mac_addr_ptr = (cy_wcm_mac_t*)malloc(sizeof(cy_wcm_mac_t) *2);
    cy_wcm_mac_t sta_mac, ap_mac;
    memcpy(&sta_mac, mac_addr_ptr, sizeof(sta_mac));
    printf("mac address of STA = %02X : %02X : %02X : %02X : %02X : %02X \n",
    sta_mac[0], sta_mac[1], sta_mac[2],sta_mac[3], sta_mac[4], sta_mac[5]);
    mac_addr_ptr++;
    memcpy(&ap_mac, mac_addr_ptr, sizeof(ap_mac));
    printf("mac address AP = %02X : %02X : %02X : %02X : %02X : %02X \n",
    ap_mac[0], ap_mac[1], ap_mac[2],ap_mac[3], ap_mac[4], ap_mac[5]);
    free(mac_addr_ptr);
    }

    Description

    -

    Structure used for providing the AP credential to connect to a AP using cy_wcm_connect_ap.

    +

    Structure used for providing the AP credential to connect to a AP using cy_wcm_connect_ap.

    diff --git a/docs/api_reference_manual/html/structcy__wcm__connect__params__t.html b/docs/api_reference_manual/html/structcy__wcm__connect__params__t.html index 1620ec9..f90127e 100644 --- a/docs/api_reference_manual/html/structcy__wcm__connect__params__t.html +++ b/docs/api_reference_manual/html/structcy__wcm__connect__params__t.html @@ -87,7 +87,7 @@

    Description

    -

    Structure used to pass the Wi-Fi connection parameter information to cy_wcm_connect_ap.

    +

    Structure used to pass the Wi-Fi connection parameter information to cy_wcm_connect_ap.

    Data Fields

    diff --git a/docs/api_reference_manual/html/structcy__wcm__ip__address__t.html b/docs/api_reference_manual/html/structcy__wcm__ip__address__t.html index c6fc40e..c283740 100644 --- a/docs/api_reference_manual/html/structcy__wcm__ip__address__t.html +++ b/docs/api_reference_manual/html/structcy__wcm__ip__address__t.html @@ -87,7 +87,7 @@

    Description

    -

    Structure used to receive the IP address information from cy_wcm_connect_ap.

    +

    Structure used to receive the IP address information from cy_wcm_connect_ap.

    Data Fields

    diff --git a/docs/api_reference_manual/html/structcy__wcm__ip__setting__t.html b/docs/api_reference_manual/html/structcy__wcm__ip__setting__t.html index 9aa0dee..ed1da4a 100644 --- a/docs/api_reference_manual/html/structcy__wcm__ip__setting__t.html +++ b/docs/api_reference_manual/html/structcy__wcm__ip__setting__t.html @@ -87,7 +87,7 @@

    Description

    -

    Structure used to pass the static IP address information to cy_wcm_connect_ap.

    +

    Structure used to pass the static IP address information to cy_wcm_connect_ap.

    Data Fields

    diff --git a/docs/api_reference_manual/html/structcy__wcm__scan__result__t.html b/docs/api_reference_manual/html/structcy__wcm__scan__result__t.html index c4bf1a8..391d734 100644 --- a/docs/api_reference_manual/html/structcy__wcm__scan__result__t.html +++ b/docs/api_reference_manual/html/structcy__wcm__scan__result__t.html @@ -142,6 +142,7 @@

    SSID (i.e., name of the AP).

    +

    In case of a hidden AP, SSID.value will be empty and SSID.length will be 0.

    diff --git a/include/cy_wcm.h b/include/cy_wcm.h index db85172..d85da58 100644 --- a/include/cy_wcm.h +++ b/include/cy_wcm.h @@ -305,13 +305,14 @@ typedef enum */ typedef enum { - CY_WCM_EVENT_CONNECTING = 0, /**< STA connecting to an AP. */ - CY_WCM_EVENT_CONNECTED, /**< STA connected to the AP. */ - CY_WCM_EVENT_CONNECT_FAILED, /**< STA connection to the AP failed. */ - CY_WCM_EVENT_RECONNECTED, /**< STA reconnected to the AP. */ - CY_WCM_EVENT_DISCONNECTED, /**< STA disconnected from the AP. */ - CY_WCM_EVENT_IP_CHANGED, /**< IP address change event. This event is notified after connection, re-connection, and IP address change due to DHCP renewal. */ - CY_WCM_EVENT_STA_JOINED_SOFTAP, /**< An STA device connected to SoftAP. */ + CY_WCM_EVENT_CONNECTING = 0, /**< STA connecting to an AP. */ + CY_WCM_EVENT_CONNECTED, /**< STA connected to the AP. */ + CY_WCM_EVENT_CONNECT_FAILED, /**< STA connection to the AP failed. */ + CY_WCM_EVENT_RECONNECTED, /**< STA reconnected to the AP. */ + CY_WCM_EVENT_DISCONNECTED, /**< STA disconnected from the AP. */ + CY_WCM_EVENT_IP_CHANGED, /**< IP address change event. This event is notified after connection, re-connection, and IP address change due to DHCP renewal. */ + CY_WCM_EVENT_INITIATED_RETRY, /**< Indicates that WCM will initiate a retry logic to re-connect to the AP */ + CY_WCM_EVENT_STA_JOINED_SOFTAP, /**< An STA device connected to SoftAP. */ CY_WCM_EVENT_STA_LEFT_SOFTAP /**< An STA device disconnected from SoftAP. */ } cy_wcm_event_t; @@ -475,7 +476,7 @@ typedef struct */ typedef struct { - cy_wcm_ssid_t SSID; /**< SSID (i.e., name of the AP). */ + cy_wcm_ssid_t SSID; /**< SSID (i.e., name of the AP). In case of a hidden AP, SSID.value will be empty and SSID.length will be 0. */ cy_wcm_mac_t BSSID; /**< Basic Service Set Identification (BSSID), i.e., MAC address of the AP. */ int16_t signal_strength; /**< RSSI in dBm. (<-90=Very poor, >-30=Excellent). */ uint32_t max_data_rate; /**< Maximum data rate in kbps. */ @@ -580,8 +581,12 @@ typedef struct * * @param[in] result_ptr : A pointer to the scan result; the scan result will be freed once the callback function returns from the application. * There will not be any scan result when the scan status is CY_WCM_SCAN_COMPLETE. + * For more details on content of result_ptr, refer \ref cy_wcm_scan_result_t. * @param[in] user_data : User-provided data. * @param[in] status : Status of the scan process. + * CY_WCM_SCAN_COMPLETE : Indicates the scan is completed. In this case the result_ptr will not contain any results. + * CY_WCM_SCAN_INCOMPLETE : Indicates the scan is in progress. In this case result_ptr contains one of the scan result. + * * * Note: The callback function will be executed in the context of the WCM. */ @@ -643,7 +648,8 @@ cy_rslt_t cy_wcm_deinit(void); * * @param[in] scan_callback : Callback function which receives the scan results; * callback will be executed in the context of the WCM. - * + * Scan results will be individually provided to this callback function. + * For more details on the scan results refer \ref cy_wcm_scan_result_callback_t. * @param[in] user_data : User data to be returned as an argument in the callback function * when the callback function is invoked. * @param[in] scan_filter : Scan filter parameter passed for scanning (optional). @@ -665,11 +671,15 @@ cy_rslt_t cy_wcm_stop_scan(void); /** * Connects the STA interface to a AP using the Wi-Fi credentials and configuration parameters provided. * On successful connection to the Wi-Fi network, the API returns the IP address. + * If the user does not know the security type of the AP then, connect_param.ap_credentials.security must + * be set to CY_WCM_SECURITY_UNKNOWN so that the library will internally find the security type before + * connecting to AP. * * This API is a blocking call; this function additionally performs the following checks: * 1) Checks for and ignores duplicate connect requests to an already connected AP. * 2) Checks the current connection state; if already connected, disconnects from the current * Wi-Fi network and connects to the new Wi-Fi network. + * 3) If the user does not know the security type of the AP, the library internally finds the security type. * * @param[in] connect_params : Configuration to join the AP. * @param[out] ip_addr : Pointer to return the IP address (optional). @@ -680,7 +690,7 @@ cy_rslt_t cy_wcm_stop_scan(void); * * @return CY_RSLT_SUCCESS if connection is successful; returns [WCM-specific error codes](./cy_wcm_error.h) otherwise. */ -cy_rslt_t cy_wcm_connect_ap(const cy_wcm_connect_params_t *connect_params, cy_wcm_ip_address_t *ip_addr); +cy_rslt_t cy_wcm_connect_ap(cy_wcm_connect_params_t *connect_params, cy_wcm_ip_address_t *ip_addr); /** * Disconnects the STA interface from the currently connected AP. @@ -895,6 +905,20 @@ cy_rslt_t cy_wcm_stop_ap(void); */ cy_rslt_t cy_wcm_get_associated_client_list(cy_wcm_mac_t *sta_list, uint8_t num_clients); +/** + * Stores the AP settings provided by the user. + * NOTE: Dotted-decimal format example: 192.168.0.1 + * + * @param[in] ip_addr : Pointer to an array containing IP address of the AP in dotted-decimal format. + * @param[in] netmask : Pointer to an array containing network mask in dotted-decimal format. + * @param[in] gateway_addr : Pointer to an array containing gateway address in dotted-decimal format. + * @param[in] ver : IP version. Possible values \ref CY_WCM_IP_VER_V6 or \ref CY_WCM_IP_VER_V4. + * @param[in] ap_ip : Pointer to variable which stores AP settings. + * + * @result CY_RSLT_SUCCESS if the AP settings are successfully stored in the user provided variable; returns [WCM-specific error codes](./cy_wcm_error.h) otherwise. + */ +cy_rslt_t cy_wcm_set_ap_ip_setting(cy_wcm_ip_setting_t *ap_ip, const char *ip_addr, const char *netmask, const char *gateway_addr, cy_wcm_ip_version_t ver); + /** \} group_wcm_functions */ diff --git a/include/cy_wcm_error.h b/include/cy_wcm_error.h index 66a0b10..e9a3c17 100644 --- a/include/cy_wcm_error.h +++ b/include/cy_wcm_error.h @@ -114,14 +114,16 @@ extern "C" { #define CY_RSLT_WCM_INTERFACE_NOT_UP (CY_RSLT_WCM_ERR_BASE + 34) /**< Interface is not initialized. */ #define CY_RSLT_WCM_NOT_INITIALIZED (CY_RSLT_WCM_ERR_BASE + 35) /**< WCM not initialized. */ #define CY_RSLT_WCM_SEMAPHORE_ERROR (CY_RSLT_WCM_ERR_BASE + 36) /**< Semaphore error. */ +#define CY_RSLT_WCM_SECURITY_NOT_FOUND (CY_RSLT_WCM_ERR_BASE + 37) /**< Security type could not be determined */ +#define CY_RSLT_WCM_CONNECT_IN_PROGRESS (CY_RSLT_WCM_ERR_BASE + 38) /**< Connect to AP is in progress */ /** WPS Error Codes */ -#define CY_RSLT_WCM_WPS_PBC_OVERLAP (CY_RSLT_WCM_ERR_BASE + 37) /**< WPS PBC overlap. */ -#define CY_RSLT_WCM_WPS_ERROR_RECEIVED_WEP_CREDENTIALS (CY_RSLT_WCM_ERR_BASE + 38) /**< WPS received incorrect credentials. */ -#define CY_RSLT_WCM_WPS_FAILED (CY_RSLT_WCM_ERR_BASE + 39) /**< WPS PBC/PIN mode failed. */ +#define CY_RSLT_WCM_WPS_PBC_OVERLAP (CY_RSLT_WCM_ERR_BASE + 39) /**< WPS PBC overlap. */ +#define CY_RSLT_WCM_WPS_ERROR_RECEIVED_WEP_CREDENTIALS (CY_RSLT_WCM_ERR_BASE + 40) /**< WPS received incorrect credentials. */ +#define CY_RSLT_WCM_WPS_FAILED (CY_RSLT_WCM_ERR_BASE + 41) /**< WPS PBC/PIN mode failed. */ /** DHCP Error Code */ -#define CY_RSLT_WCM_DHCP_TIMEOUT (CY_RSLT_WCM_ERR_BASE + 40) /**< DHCP timeout. */ +#define CY_RSLT_WCM_DHCP_TIMEOUT (CY_RSLT_WCM_ERR_BASE + 42) /**< DHCP timeout. */ /** \} error codes */ diff --git a/source/COMPONENT_43439/cy_chip_constants.h b/source/COMPONENT_43439/cy_chip_constants.h new file mode 100644 index 0000000..e7dd0c4 --- /dev/null +++ b/source/COMPONENT_43439/cy_chip_constants.h @@ -0,0 +1,43 @@ +/* + * Copyright 2021, Cypress Semiconductor Corporation (an Infineon company) or + * an affiliate of Cypress Semiconductor Corporation. All rights reserved. + * + * This software, including source code, documentation and related + * materials ("Software") is owned by Cypress Semiconductor Corporation + * or one of its affiliates ("Cypress") and is protected by and subject to + * worldwide patent protection (United States and foreign), + * United States copyright laws and international treaty provisions. + * Therefore, you may use this Software only as provided in the license + * agreement accompanying the software package from which you + * obtained this Software ("EULA"). + * If no EULA applies, Cypress hereby grants you a personal, non-exclusive, + * non-transferable license to copy, modify, and compile the Software + * source code solely for use in connection with Cypress's + * integrated circuit products. Any reproduction, modification, translation, + * compilation, or representation of this Software except as specified + * above is prohibited without the express written permission of Cypress. + * + * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress + * reserves the right to make changes to the Software without notice. Cypress + * does not assume any liability arising out of the application or use of the + * Software or any product or circuit described in the Software. Cypress does + * not authorize its products for use in any products where a malfunction or + * failure of the Cypress product may reasonably be expected to result in + * significant property damage, injury or death ("High Risk Product"). By + * including Cypress's product in a High Risk Product, the manufacturer + * of such system or application assumes all risk of such use and in doing + * so agrees to indemnify Cypress against all liability. + */ + +/** +* @file cy_chip_constant.h +* @brief Chip specific constants +*/ + +#define WL_CHANSPEC_BAND_MASK (0xc000) +#define WL_CHANSPEC_BW_MASK (0x3800) +#define WL_CHANSPEC_BW_10 (0x0800) +#define WL_CHANSPEC_BW_20 (0x1000) +#define WL_CHANSPEC_BW_40 (0x1800) diff --git a/source/COMPONENT_43907/cy_chip_constants.h b/source/COMPONENT_43907/cy_chip_constants.h new file mode 100644 index 0000000..e7dd0c4 --- /dev/null +++ b/source/COMPONENT_43907/cy_chip_constants.h @@ -0,0 +1,43 @@ +/* + * Copyright 2021, Cypress Semiconductor Corporation (an Infineon company) or + * an affiliate of Cypress Semiconductor Corporation. All rights reserved. + * + * This software, including source code, documentation and related + * materials ("Software") is owned by Cypress Semiconductor Corporation + * or one of its affiliates ("Cypress") and is protected by and subject to + * worldwide patent protection (United States and foreign), + * United States copyright laws and international treaty provisions. + * Therefore, you may use this Software only as provided in the license + * agreement accompanying the software package from which you + * obtained this Software ("EULA"). + * If no EULA applies, Cypress hereby grants you a personal, non-exclusive, + * non-transferable license to copy, modify, and compile the Software + * source code solely for use in connection with Cypress's + * integrated circuit products. Any reproduction, modification, translation, + * compilation, or representation of this Software except as specified + * above is prohibited without the express written permission of Cypress. + * + * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress + * reserves the right to make changes to the Software without notice. Cypress + * does not assume any liability arising out of the application or use of the + * Software or any product or circuit described in the Software. Cypress does + * not authorize its products for use in any products where a malfunction or + * failure of the Cypress product may reasonably be expected to result in + * significant property damage, injury or death ("High Risk Product"). By + * including Cypress's product in a High Risk Product, the manufacturer + * of such system or application assumes all risk of such use and in doing + * so agrees to indemnify Cypress against all liability. + */ + +/** +* @file cy_chip_constant.h +* @brief Chip specific constants +*/ + +#define WL_CHANSPEC_BAND_MASK (0xc000) +#define WL_CHANSPEC_BW_MASK (0x3800) +#define WL_CHANSPEC_BW_10 (0x0800) +#define WL_CHANSPEC_BW_20 (0x1000) +#define WL_CHANSPEC_BW_40 (0x1800) diff --git a/source/COMPONENT_LWIP/cy_wcm.c b/source/COMPONENT_LWIP/cy_wcm.c index 2f87d07..2f5c73a 100644 --- a/source/COMPONENT_LWIP/cy_wcm.c +++ b/source/COMPONENT_LWIP/cy_wcm.c @@ -74,6 +74,7 @@ #include #include "whd_debug.h" +#include "cy_nw_helper.h" /** * Macro for comparing MAC addresses @@ -99,7 +100,7 @@ #define CY_WCM_MAX_MUTEX_WAIT_TIME_MS (120000) #define CY_WCM_INTERFACE_TYPE_UNKNOWN (4) -#define CY_WCM_DEFAULT_STA_CHANNEL (1) +#define CY_WCM_DEFAULT_STA_CHANNEL (0) #define WCM_WORKER_THREAD_PRIORITY (CY_RTOS_PRIORITY_ABOVENORMAL) #define WCM_WORKER_THREAD_STACK_SIZE (10 * 1024) #define WCM_HANDSHAKE_TIMEOUT_MS (3000) @@ -119,6 +120,7 @@ #define PING_IF_NAME_LEN (6) #define PING_RESPONSE_LEN (64) #define SCAN_BSSID_ARR_LENGTH (50) +#define MAX_SCAN_RETRY (5) /* Macro for 43012 statistics */ #define WL_CNT_VER_30 (30) @@ -151,6 +153,7 @@ typedef struct cy_wcm_scan_filter_t scan_filter; /* Scan filtering type */ bool is_scanning; /* Indicates if scanning is ongoing */ bool is_stop_scan_req; /* Indicates if stop scan was requested */ + bool get_security_type; /* Indicates if cy_wcm_connect_ap is trying to find the security type */ }wcm_internal_scan_t; struct icmp_packet @@ -208,6 +211,7 @@ static whd_security_t sta_security_type; static cy_worker_thread_info_t cy_wcm_worker_thread; static bool is_olm_initialized = false; static void *olm_instance = NULL; +static bool is_disconnect_triggered = false; whd_scan_result_t scan_result; cy_wcm_scan_result_callback_t p_scan_calback; @@ -218,8 +222,8 @@ static cy_timer_t sta_retry_timer; static cy_wcm_event_callback_t wcm_event_handler[CY_WCM_MAXIMUM_CALLBACKS_COUNT]; static uint16_t sta_event_handler_index = 0xFF; static uint16_t ap_event_handler_index = 0xFF; -static const whd_event_num_t sta_link_events[] = {WLC_E_LINK, WLC_E_DEAUTH_IND, WLC_E_DISASSOC_IND, WLC_E_PSK_SUP, WLC_E_NONE}; -static const whd_event_num_t ap_link_events[] = {WLC_E_DISASSOC_IND, WLC_E_ASSOC_IND, WLC_E_REASSOC_IND, WLC_E_NONE}; +static const whd_event_num_t sta_link_events[] = {WLC_E_LINK, WLC_E_DEAUTH_IND, WLC_E_DISASSOC_IND, WLC_E_PSK_SUP, WLC_E_CSA_COMPLETE_IND, WLC_E_NONE}; +static const whd_event_num_t ap_link_events[] = {WLC_E_DISASSOC_IND, WLC_E_ASSOC_IND, WLC_E_REASSOC_IND, WLC_E_AUTHORIZED, WLC_E_NONE}; static bool too_many_ie_error = false; static bool link_up_event_received = false; static uint32_t retry_backoff_timeout = DEFAULT_RETRY_BACKOFF_TIMEOUT_IN_MS; @@ -227,6 +231,8 @@ static uint32_t retry_backoff_timeout = DEFAULT_RETRY_BACKOFF_TIMEOUT_IN_MS; static whd_mac_t *mac_addr_arr = NULL; static int current_bssid_arr_length = 0; static cy_semaphore_t stop_scan_semaphore; +static cy_semaphore_t security_type_start_scan_semaphore; +static cy_wcm_security_t ap_security; typedef uint16_t xtlv_opts_t; @@ -245,7 +251,7 @@ static void link_down(void); static void handshake_timeout_handler(cy_timer_callback_arg_t arg); static void handshake_error_callback(void *arg); static void lwip_ip_change_callback(void *arg); -static bool check_if_platform_supports_band(cy_wcm_wifi_band_t requested_band); +static bool check_if_platform_supports_band(whd_interface_t interface, cy_wcm_wifi_band_t requested_band); static void sta_link_down_handler(void* arg); static void sta_link_up_handler(void* arg); static void sta_link_up_renew_handler(void* arg); @@ -281,6 +287,7 @@ static int xtlv_size_for_data(int dlen, xtlv_opts_t opts, const uint8_t **data); static int ltoh16_ua(const uint8_t * bytes); static void process_scan_data(void *arg); static void notify_scan_completed(void *arg); + /****************************************************** * Function Definitions ******************************************************/ @@ -365,11 +372,21 @@ cy_rslt_t cy_wcm_init(cy_wcm_config_t *config) return CY_RSLT_WCM_MUTEX_ERROR; } + /* Initialize semaphore */ if(cy_rtos_init_semaphore(&stop_scan_semaphore, MAX_SEMA_COUNT, 0) != CY_RSLT_SUCCESS) { + cy_rtos_deinit_mutex(&wcm_mutex); + return CY_RSLT_WCM_SEMAPHORE_ERROR; + } + + if(cy_rtos_init_semaphore(&security_type_start_scan_semaphore, MAX_SEMA_COUNT, 0) != CY_RSLT_SUCCESS) + { + cy_rtos_deinit_semaphore(&stop_scan_semaphore); + cy_rtos_deinit_mutex(&wcm_mutex); return CY_RSLT_WCM_SEMAPHORE_ERROR; } + if((res = init_whd_wifi_interface(config->interface)) != CY_RSLT_SUCCESS) { cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Error : Initializing Wi-Fi interface \n"); @@ -445,9 +462,20 @@ cy_rslt_t cy_wcm_deinit() cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Error while stopping AP \n"); } - if ((res =cy_rtos_deinit_mutex(&wcm_mutex)) != CY_RSLT_SUCCESS) + if((res = cy_rtos_deinit_semaphore(&stop_scan_semaphore)) != CY_RSLT_SUCCESS) { - cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Error while de initializing mutex \n");; + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Error while de initializing stop_scan_semaphore semaphore \n"); + } + + if((res = cy_rtos_deinit_semaphore(&security_type_start_scan_semaphore)) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Error while de initializing security_type_start_scan_semaphore semaphore \n"); + } + + + if((res = cy_rtos_deinit_mutex(&wcm_mutex)) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Error while de initializing mutex \n"); } if(current_interface != CY_WCM_INTERFACE_TYPE_AP_STA) @@ -508,6 +536,12 @@ cy_rslt_t cy_wcm_start_scan(cy_wcm_scan_result_callback_t callback, void *user_d return CY_RSLT_WCM_WAIT_TIMEOUT; } + if(scan_handler.get_security_type) + { + res = CY_RSLT_WCM_CONNECT_IN_PROGRESS; + goto exit; + } + if(scan_handler.is_scanning) { res = CY_RSLT_WCM_SCAN_IN_PROGRESS; @@ -559,7 +593,7 @@ cy_rslt_t cy_wcm_start_scan(cy_wcm_scan_result_callback_t callback, void *user_d break; case CY_WCM_SCAN_FILTER_TYPE_BAND: /* check if the platform supports the requested band */ - if(!check_if_platform_supports_band(scan_filter->param.band)) + if(!check_if_platform_supports_band(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], scan_filter->param.band)) { cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "band not supported \n"); res = CY_RSLT_WCM_BAND_NOT_SUPPORTED; @@ -594,7 +628,7 @@ cy_rslt_t cy_wcm_start_scan(cy_wcm_scan_result_callback_t callback, void *user_d ssid, mac, NULL, NULL, internal_scan_callback, &scan_result, user_data); if(res != CY_RSLT_SUCCESS) { - cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "whd_wifi_scan error. Result = %d \n", res); + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "whd_wifi_scan error. Result = %d \n", res); res = CY_RSLT_WCM_SCAN_ERROR; goto exit; } @@ -640,6 +674,13 @@ cy_rslt_t cy_wcm_stop_scan() return CY_RSLT_WCM_WAIT_TIMEOUT; } + if(scan_handler.get_security_type) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "cy_wcm_connect_ap has initiated an internal scan to find the security type of AP. No active user scan running. \n"); + res = CY_RSLT_WCM_CONNECT_IN_PROGRESS; + goto exit; + } + if(!scan_handler.is_scanning) { res = CY_RSLT_WCM_NO_ACTIVE_SCAN; @@ -731,8 +772,104 @@ cy_rslt_t cy_wcm_deregister_event_callback(cy_wcm_event_callback_t event_callbac return CY_RSLT_WCM_BAD_ARG; } +/* whd scan callback to find the security type when user has not + * provided the security type to cy_wcm_connect_ap + */ +static void internal_scan_cb_get_security_type(whd_scan_result_t **result_ptr, void *user_data, whd_scan_status_t status) +{ + if(status == WHD_SCAN_ABORTED) + { + return; + } + if(status == WHD_SCAN_COMPLETED_SUCCESSFULLY) + { + goto exit; + } + else if(status == WHD_SCAN_INCOMPLETE) + { + if((**result_ptr).SSID.length != 0) + { + cy_wcm_connect_params_t *connect_params = (cy_wcm_connect_params_t *)user_data; + if(strcmp((char *)(**result_ptr).SSID.value, (char *)connect_params->ap_credentials.SSID) != 0) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Scanned SSID did not match SSID passed by user \n"); + return; + } + if (connect_params->ap_credentials.security == CY_WCM_SECURITY_UNKNOWN) + { + connect_params->ap_credentials.security = whd_to_wcm_security((**result_ptr).security); + } + } + } + +exit: + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex locked %s %d\r\n", __FILE__, __LINE__); + if(cy_rtos_get_mutex(&wcm_mutex, CY_WCM_MAX_MUTEX_WAIT_TIME_MS) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Unable to acquire WCM mutex \n"); + return; + } + + scan_handler.is_scanning = false; + scan_handler.get_security_type = false; + + if(cy_rtos_set_semaphore(&security_type_start_scan_semaphore, false) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "unable to set security_type_start_scan_semaphore \n"); + } + + if (cy_rtos_set_mutex(&wcm_mutex) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex unlock error %s %d\r\n", __FILE__, __LINE__); + } + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex unlocked %s %d\r\n", __FILE__, __LINE__); +} + +cy_rslt_t cy_wcm_scan_security_type(void *user_data) +{ + cy_rslt_t res = CY_RSLT_SUCCESS; + + if(!is_wcm_initalized) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "WCM STA interface is not initialized \n"); + return CY_RSLT_WCM_NOT_INITIALIZED; + } + + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex locked %s %d\r\n", __FILE__, __LINE__); + if(cy_rtos_get_mutex(&wcm_mutex, CY_WCM_MAX_MUTEX_WAIT_TIME_MS) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Unable to acquire WCM mutex \n"); + return CY_RSLT_WCM_WAIT_TIMEOUT; + } -cy_rslt_t cy_wcm_connect_ap(const cy_wcm_connect_params_t *connect_params, cy_wcm_ip_address_t *ip_addr) + if(scan_handler.is_scanning) + { + res = CY_RSLT_WCM_SCAN_IN_PROGRESS; + goto exit; + } + + res = whd_wifi_scan(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], WHD_SCAN_TYPE_ACTIVE, WHD_BSS_TYPE_ANY, + NULL, NULL, NULL, NULL, internal_scan_cb_get_security_type, &scan_result, user_data); + if(res != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "whd_wifi_scan error. Result = %d \n", res); + res = CY_RSLT_WCM_SCAN_ERROR; + goto exit; + } + scan_handler.is_scanning = true; + scan_handler.get_security_type = true; + +exit: + if (cy_rtos_set_mutex(&wcm_mutex) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex unlock error %s %d\r\n", __FILE__, __LINE__); + res = ((res != CY_RSLT_SUCCESS) ? res : CY_RSLT_WCM_MUTEX_ERROR); + } + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex unlocked %s %d\r\n", __FILE__, __LINE__); + + return res; +} +cy_rslt_t cy_wcm_connect_ap(cy_wcm_connect_params_t *connect_params, cy_wcm_ip_address_t *ip_addr) { cy_rslt_t res = CY_RSLT_SUCCESS; whd_ssid_t ssid; @@ -750,6 +887,7 @@ cy_rslt_t cy_wcm_connect_ap(const cy_wcm_connect_params_t *connect_params, cy_wc #endif uint8_t connection_status; struct netif *net_interface = NULL; + uint8_t num_scan = 0; if(!is_wcm_initalized) { @@ -757,33 +895,89 @@ cy_rslt_t cy_wcm_connect_ap(const cy_wcm_connect_params_t *connect_params, cy_wc return CY_RSLT_WCM_NOT_INITIALIZED; } + /* Security type not specified by user then scan to figure out the security type */ + if(connect_params->ap_credentials.security == CY_WCM_SECURITY_UNKNOWN) + { + while(connect_params->ap_credentials.security == CY_WCM_SECURITY_UNKNOWN && num_scan < MAX_SCAN_RETRY ) + { + res = cy_wcm_scan_security_type(connect_params); + if (res != CY_RSLT_SUCCESS) + { + if (res == CY_RSLT_WCM_SCAN_IN_PROGRESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Scan in progress...wait and try again \n"); + cy_rtos_delay_milliseconds(500); + continue; + } + else + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Scan failed... \n"); + return res; + } + } + if(cy_rtos_get_semaphore(&security_type_start_scan_semaphore, NEVER_TIMEOUT, false) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Error unable to set the security type semaphore \n"); + } + /* Stop scan before starting the next scan */ + whd_wifi_stop_scan(whd_ifs[CY_WCM_INTERFACE_TYPE_STA]); + num_scan++; + } + + if(connect_params->ap_credentials.security == CY_WCM_SECURITY_UNKNOWN) + { + /* Failed to get the security type of network */ + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Unable to get the security type of network \n"); + return CY_RSLT_WCM_SECURITY_NOT_FOUND; + } + } + memset(&connected_ap_details, 0, sizeof(connected_ap_details)); if((res = check_ap_credentials(connect_params)) != CY_RSLT_SUCCESS) { return res; } - if (is_connected_to_same_ap(connect_params)) - { - cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_INFO, "already connected to same AP \n"); - return CY_RSLT_SUCCESS; - } - if (wcm_sta_link_up && (cy_wcm_disconnect_ap() != CY_RSLT_SUCCESS)) - { - /** - * Notify user disconnection error occurred and - * reset the is_wifi_connected flag to false - */ - wcm_sta_link_up = false; - return CY_RSLT_WCM_STA_DISCONNECT_ERROR; - } cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex locked %s %d\r\n", __FILE__, __LINE__); if (cy_rtos_get_mutex(&wcm_mutex, CY_WCM_MAX_MUTEX_WAIT_TIME_MS) == CY_RSLT_SUCCESS) { whd_scan_result_t ap; + is_disconnect_triggered = false; + if (is_connected_to_same_ap(connect_params)) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_INFO, "already connected to same AP \n"); + /* Store the IP address before returning */ + net_interface = cy_lwip_get_interface(CY_LWIP_STA_NW_INTERFACE); +#if LWIP_IPV4 +#if LWIP_IPV6 + ipv4_addr = net_interface->ip_addr.u_addr.ip4.addr; + addr = &net_interface->ip_addr.u_addr.ip4; +#else + ipv4_addr = net_interface->ip_addr.addr; + addr = &net_interface->ip_addr; +#endif + if(ip_addr != NULL) + { + ip_addr->version = CY_WCM_IP_VER_V4; + ip_addr->ip.v4 = ipv4_addr; + } +#endif + goto exit; + } + if (wcm_sta_link_up && (cy_wcm_disconnect_ap() != CY_RSLT_SUCCESS)) + { + /** + * Notify user disconnection error occurred and + * reset the is_wifi_connected flag to false + */ + wcm_sta_link_up = false; + res = CY_RSLT_WCM_STA_DISCONNECT_ERROR; + goto exit; + } + convert_connect_params(connect_params, &ssid, &bssid, &key, &keylen, &security, &static_ip); sta_security_type = security; - + connection_status = CY_WCM_EVENT_CONNECTING; if((res = cy_worker_thread_enqueue(&cy_wcm_worker_thread, notify_connection_status, &connection_status)) != CY_RSLT_SUCCESS) { @@ -811,7 +1005,7 @@ cy_rslt_t cy_wcm_connect_ap(const cy_wcm_connect_params_t *connect_params, cy_wc if(connect_params->band == CY_WCM_WIFI_BAND_5GHZ) { /* check if this band is supported locally */ - if(check_if_platform_supports_band(CY_WCM_WIFI_BAND_5GHZ)) + if(check_if_platform_supports_band(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], CY_WCM_WIFI_BAND_5GHZ)) { whd_wifi_set_ioctl_value(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], WLC_SET_BAND, WLC_BAND_5G); } @@ -958,13 +1152,13 @@ cy_rslt_t cy_wcm_connect_ap(const cy_wcm_connect_params_t *connect_params, cy_wc memcpy(connected_ap_details.SSID.value, ssid.value, connected_ap_details.SSID.length+1); memcpy(connected_ap_details.sta_mac.octet, bssid.octet, CY_WCM_MAC_ADDR_LEN); memcpy(&connected_ap_details.static_ip, &static_ip, sizeof(static_ip)); + wcm_sta_link_up = true; connection_status = CY_WCM_EVENT_CONNECTED; if((res = cy_worker_thread_enqueue(&cy_wcm_worker_thread, notify_connection_status, &connection_status)) != CY_RSLT_SUCCESS) { cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "L%d : %s() : ERROR : Failed to send connection status. Err = [%lu]\r\n", __LINE__, __FUNCTION__, res); goto exit; } - wcm_sta_link_up = true; /* post IP change callback */ if((res = cy_worker_thread_enqueue(&cy_wcm_worker_thread, notify_ip_change, NULL)) != CY_RSLT_SUCCESS) { @@ -1031,6 +1225,7 @@ cy_rslt_t cy_wcm_disconnect_ap() } } exit: + is_disconnect_triggered = true; /* clear the saved ap credentials */ memset(&connected_ap_details, 0, sizeof(connected_ap_details)); if (cy_rtos_set_mutex(&wcm_mutex) != CY_RSLT_SUCCESS) @@ -2147,7 +2342,7 @@ cy_rslt_t cy_wcm_start_ap(const cy_wcm_ap_config_t *ap_config) cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Bad soft ap config \n"); return res; } - + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex locked %s %d\r\n", __FILE__, __LINE__); if(cy_rtos_get_mutex(&wcm_mutex, CY_WCM_MAX_MUTEX_WAIT_TIME_MS) != CY_RSLT_SUCCESS) { @@ -2162,6 +2357,8 @@ cy_rslt_t cy_wcm_start_ap(const cy_wcm_ap_config_t *ap_config) } read_ap_config(ap_config, &ssid, &key, &keylen, &security, &static_ip); + /* Store the SoftAP security type */ + ap_security = whd_to_wcm_security(security); /* set up the AP info */ res = whd_wifi_init_ap(whd_ifs[CY_WCM_INTERFACE_TYPE_AP], &ssid, security, (const uint8_t *)key, keylen, ap_config->channel); @@ -2170,7 +2367,7 @@ cy_rslt_t cy_wcm_start_ap(const cy_wcm_ap_config_t *ap_config) cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "ERROR initializing AP = %d \n", res); goto exit; } - + if (ap_config->ie_info) { res = whd_wifi_manage_custom_ie(whd_ifs[CY_WCM_INTERFACE_TYPE_AP], WHD_ADD_CUSTOM_IE, (const uint8_t *)ap_config->ie_info->oui, @@ -2805,7 +3002,35 @@ static void* ap_link_events_handler(whd_interface_t ifp, const whd_event_header_ } else if (event_header->event_type == WLC_E_ASSOC_IND || event_header->event_type == WLC_E_REASSOC_IND) { - ap_event_data->event = CY_WCM_EVENT_STA_JOINED_SOFTAP; + /* Set ap_event_data->event only if the security type of AP is CY_WCM_SECURITY_OPEN/CY_WCM_SECURITY_WEP_PSK/CY_WCM_SECURITY_WEP_SHARED. + * For all other security types wait for WLC_E_AUTHORIZED event to set ap_event_data->event to CY_WCM_EVENT_STA_JOINED_SOFTAP. + */ + if(ap_security == CY_WCM_SECURITY_OPEN || ap_security == CY_WCM_SECURITY_WEP_PSK || ap_security == CY_WCM_SECURITY_WEP_SHARED) + { + ap_event_data->event = CY_WCM_EVENT_STA_JOINED_SOFTAP; + } + else + { + /* Ignore other security types */ + free(ap_event_data); + return handler_user_data; + } + } + else if(event_header->event_type == WLC_E_AUTHORIZED) + { + /* If the security type of AP is other than CY_WCM_SECURITY_OPEN, CY_WCM_SECURITY_WEP_PSK, CY_WCM_SECURITY_WEP_SHARED and + * WLC_E_AUTHORIZED event is received, then set ap_event_data->event to CY_WCM_EVENT_STA_JOINED_SOFTAP. + */ + if(ap_security != CY_WCM_SECURITY_OPEN && ap_security != CY_WCM_SECURITY_WEP_PSK && ap_security != CY_WCM_SECURITY_WEP_SHARED) + { + ap_event_data->event = CY_WCM_EVENT_STA_JOINED_SOFTAP; + } + else + { + /* Ignore other security types */ + free(ap_event_data); + return handler_user_data; + } } else { @@ -2892,6 +3117,8 @@ static void* link_events_handler(whd_interface_t ifp, const whd_event_header_t * /* Check if the link down event is followed by too many RSN IE Error. If yes, try join again */ if (too_many_ie_error) { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_INFO, "Notify application that WCM will retry to connect to the AP!\n"); + invoke_app_callbacks(CY_WCM_EVENT_INITIATED_RETRY, NULL); /* Try to join the AP again */ handshake_timeout_handler(0); @@ -2947,7 +3174,12 @@ static void* link_events_handler(whd_interface_t ifp, const whd_event_header_t * } break; } - + case WLC_E_CSA_COMPLETE_IND: + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "recieved WLC_E_CSA_COMPLETE_IND \n"); + handshake_timeout_handler(0); + break; + } /* Note - These are listed to keep gcc pedantic checking happy */ case WLC_E_NONE: case WLC_E_ROAM: @@ -3026,7 +3258,6 @@ static void* link_events_handler(whd_interface_t ifp, const whd_event_header_t * case WLC_E_RM_COMPLETE: case WLC_E_HTSFSYNC: case WLC_E_OVERLAY_REQ: - case WLC_E_CSA_COMPLETE_IND: case WLC_E_EXCESS_PM_WAKE_EVENT: case WLC_E_PFN_SCAN_NONE: case WLC_E_PFN_SCAN_ALLGONE: @@ -3218,18 +3449,52 @@ static void handshake_error_callback(void *arg) /* stop the retry timer */ cy_rtos_stop_timer(&sta_retry_timer); - retry_backoff_timeout = DEFAULT_RETRY_BACKOFF_TIMEOUT_IN_MS; + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex locked %s %d\r\n", __FILE__, __LINE__); + if(cy_rtos_get_mutex(&wcm_mutex, CY_WCM_MAX_MUTEX_WAIT_TIME_MS) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Unable to acquire WCM mutex \n"); + return; + } + if (is_disconnect_triggered == true || cy_wcm_is_connected_to_ap()) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_INFO, + "is_disconnect_triggered(%d),cy_wcm_is_connected_to_ap()(%d) exit handshake_error_callback\n", + is_disconnect_triggered, cy_wcm_is_connected_to_ap()); + goto exit; + } /* De-register the link event handler */ whd_wifi_deregister_event_handler(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], sta_event_handler_index); /* Explicitly leave AP and then rejoin */ whd_wifi_leave(whd_ifs[CY_WCM_INTERFACE_TYPE_STA]); + if (cy_rtos_set_mutex(&wcm_mutex) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Mutex release error \n"); + return; + } + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex unlocked %s %d\r\n", __FILE__, __LINE__); + cy_rtos_delay_milliseconds(100); for(retries = 0; retries < JOIN_RETRY_ATTEMPTS; retries++) { cy_rslt_t join_result; + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex locked %s %d\r\n", __FILE__, __LINE__); + if(cy_rtos_get_mutex(&wcm_mutex, CY_WCM_MAX_MUTEX_WAIT_TIME_MS) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Unable to acquire WCM mutex \n"); + return; + } + + if (is_disconnect_triggered == true || cy_wcm_is_connected_to_ap()) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_INFO, + "is_disconnect_triggered(%d),cy_wcm_is_connected_to_ap()(%d) exit handshake_error_callback\n", + is_disconnect_triggered, cy_wcm_is_connected_to_ap()); + goto exit; + } + if(!NULL_MAC(connected_ap_details.sta_mac.octet)) { whd_scan_result_t ap; @@ -3250,14 +3515,17 @@ static void handshake_error_callback(void *arg) { whd_wifi_set_ioctl_value(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], WLC_SET_BAND, WLC_BAND_5G); } - else + else if(connected_ap_details.band == CY_WCM_WIFI_BAND_2_4GHZ) { /* * It could be possible on a dual band supported device, * the current band set is 5G and the requested band from user is 2.4Ghz */ whd_wifi_set_ioctl_value(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], WLC_SET_BAND, WLC_BAND_2G); - + } + else + { + whd_wifi_set_ioctl_value(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], WLC_SET_BAND, WLC_BAND_AUTO); } /** Join to Wi-Fi AP **/ join_result = whd_wifi_join(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], &connected_ap_details.SSID, connected_ap_details.security, connected_ap_details.key, connected_ap_details.keylen); @@ -3274,9 +3542,14 @@ static void handshake_error_callback(void *arg) } /* Reset retry-backoff-timeout */ retry_backoff_timeout = DEFAULT_RETRY_BACKOFF_TIMEOUT_IN_MS; + goto exit; + } + if (cy_rtos_set_mutex(&wcm_mutex) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Mutex release error \n"); return; } - + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex unlocked %s %d\r\n", __FILE__, __LINE__); } /* Register retry with network worker thread */ @@ -3288,6 +3561,15 @@ static void handshake_error_callback(void *arg) } /* Update backoff timeout */ retry_backoff_timeout = (retry_backoff_timeout < MAX_RETRY_BACKOFF_TIMEOUT_IN_MS)? (uint32_t)(retry_backoff_timeout * 2) : MAX_RETRY_BACKOFF_TIMEOUT_IN_MS; + return; + +exit: + if (cy_rtos_set_mutex(&wcm_mutex) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Mutex release error \n"); + return; + } + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex unlocked %s %d\r\n", __FILE__, __LINE__); } static void lwip_ip_change_callback(void *arg) @@ -3337,12 +3619,18 @@ void notify_ip_change(void *arg) } -static bool check_if_platform_supports_band(cy_wcm_wifi_band_t requested_band) +static bool check_if_platform_supports_band(whd_interface_t interface, cy_wcm_wifi_band_t requested_band) { whd_band_list_t band_list; - - CHECK_RETURN(whd_wifi_get_ioctl_buffer(whd_ifs[CY_WCM_INTERFACE_TYPE_STA], WLC_GET_BANDLIST, (uint8_t*)&band_list, sizeof(whd_band_list_t))); - + uint32_t res; + + res = whd_wifi_get_ioctl_buffer(interface, WLC_GET_BANDLIST, (uint8_t*)&band_list, sizeof(whd_band_list_t)); + if(res != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "Function whd_wifi_get_ioctl_buffer failed at line %d with result %u \n ", __LINE__, res); + return false; + } + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "band_list.current_band = %ld, band_list.number_of_bands = %ld , requested band = %d \n ", band_list.current_band, band_list.number_of_bands, requested_band); /* @@ -3661,7 +3949,16 @@ static cy_rslt_t check_soft_ap_config(const cy_wcm_ap_config_t *ap_config_params } else if((ap_config_params->channel > 35) && (ap_config_params->channel < 101)) { - if(!check_if_platform_supports_band(CY_WCM_WIFI_BAND_5GHZ)) + whd_interface_t prim_ifp; + if(whd_ifs[CY_WCM_INTERFACE_TYPE_AP] == NULL) + { + return CY_RSLT_WCM_INTERFACE_NOT_UP; + } + /* WAR for DRIVERS-7307. whd_wifi_get_ioctl_buffer is failing on secondary interface in concurrent mode, + * hence using the primary interface as a workaround. + */ + prim_ifp = whd_get_primary_interface(whd_ifs[CY_WCM_INTERFACE_TYPE_AP]->whd_driver); + if(!check_if_platform_supports_band(prim_ifp, CY_WCM_WIFI_BAND_5GHZ)) { return CY_RSLT_WCM_BAND_NOT_SUPPORTED; } @@ -3741,3 +4038,47 @@ static bool check_if_ent_auth_types(cy_wcm_security_t auth_type) return false; } + +cy_rslt_t cy_wcm_set_ap_ip_setting(cy_wcm_ip_setting_t *ap_ip, const char *ip_addr, const char *netmask, const char *gateway_addr, cy_wcm_ip_version_t ver) +{ + cy_rslt_t res = CY_RSLT_SUCCESS; + cy_nw_ip_address_t temp; + + if(ap_ip == NULL || ip_addr == NULL || netmask == NULL || gateway_addr == NULL) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_INFO, "Null value passed to cy_wcm_ap_ip_setting \n"); + return CY_RSLT_WCM_BAD_ARG; + } + + if((ver != CY_WCM_IP_VER_V4) && (ver != CY_WCM_IP_VER_V6)) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_INFO, "Invalid version passed to cy_wcm_set_ap_ip_setting \n"); + return CY_RSLT_WCM_BAD_ARG; + } + + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_DEBUG, "wcm mutex locked %s %d\r\n", __FILE__, __LINE__); + if((res = cy_rtos_get_mutex(&wcm_mutex, CY_WCM_MAX_MUTEX_WAIT_TIME_MS)) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Unable to acquire WCM mutex \n"); + return res; + } + + cy_nw_aton(ip_addr,&temp); + ap_ip->ip_address.ip.v4 = temp.ip.v4; + + cy_nw_aton(netmask,&temp); + ap_ip->netmask.ip.v4 = temp.ip.v4; + + cy_nw_aton(gateway_addr,&temp); + ap_ip->gateway.ip.v4 = temp.ip.v4; + + ap_ip->ip_address.version = ver; + ap_ip->netmask.version = ver; + ap_ip->gateway.version = ver; + + if ((res = cy_rtos_set_mutex(&wcm_mutex)) != CY_RSLT_SUCCESS) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "Unable to release WCM mutex \n"); + } + return res; +} diff --git a/source/COMPONENT_WPS/cy_wcm_wps.c b/source/COMPONENT_WPS/cy_wcm_wps.c index e3f4ce6..ecdd2d2 100644 --- a/source/COMPONENT_WPS/cy_wcm_wps.c +++ b/source/COMPONENT_WPS/cy_wcm_wps.c @@ -193,6 +193,13 @@ cy_rslt_t cy_wcm_wps_enrollee(cy_wcm_wps_config_t* wps_config, const cy_wcm_wps_ return CY_RSLT_WCM_OUT_OF_MEMORY; } + if( cy_wcm_is_connected_to_ap() ) + { + cy_wcm_log_msg(CYLF_MIDDLEWARE, CY_LOG_INFO, "Currently connected to an AP, disconnect from the current AP before trying to connect using WPS \n"); + free(workspace); + return CY_RSLT_WCM_WPS_FAILED; + } + result = cy_wps_init ( workspace, (cy_wps_device_detail_t*) details, CY_WPS_ENROLLEE_AGENT, whd_ifs[CY_WCM_INTERFACE_TYPE_STA] ); if( result != CY_RSLT_SUCCESS ) { diff --git a/version.txt b/version.txt deleted file mode 100644 index f40c89f..0000000 --- a/version.txt +++ /dev/null @@ -1 +0,0 @@ -2.0.3.1021 diff --git a/version.xml b/version.xml new file mode 100644 index 0000000..c11c602 --- /dev/null +++ b/version.xml @@ -0,0 +1 @@ +2.0.4.1307

    Data Fields