This snip demonstrates how a WICED device can be configured to work simultaneously as an access point and station.
Testing the snip step by step
Launch WICED Studio and open the apsta.c file. It is available at 43xxx_Wi-Fi/apps/snip/apsta as shown below.
When the WICED device would work as STA, it will join the access point configured in the Wi-Fi configuration DCT. Change the Client AP SSID and Client AP passphrase so that they match with your access point as shown below. The Wi-Fi DCT configuration file wifi_config_dct.h is available at 43xxx_Wi-Fi/include.
We will run this snip on the platform BCM943438WCD1. Create a new make target and write the target name “snip.apsta- BCM943438WCD1 download run” without the double quotes as shown below.
To build and run the target, double click on the target name that we just made as shown below.
WICED will build the project and display the various steps that it is executing during the build process in the console window. The apsta snip will start running after the console displays the “Target running” message.
Open a UART terminal such as Tera term and select the COM port of the BCM943438WCD1 platform and configure the baud rate to 115200. The following output will be displayed on the UART terminal.
As shown above, the STA pings the gateway periodically using its IP address.
We shall test the WICED SoftAP interface. Connect the Wi-Fi of your computer to the SSID of the SoftAP interface configured in wifi_config_dct.h. By default, the SSID is "WICED Soft AP" and the passphrase is "abcd1234" without quotes. Open a web browser and type www.wiced.com. The server should redirect you to a page with the extension "/apps/apsta/ap_top.html" as shown below.
This completes the testing of the apsta snip. We shall try to understand the application code written in apsta.c.
Understanding the application code
In the application code, the function wiced_init() is used for initializing the RTOS, platform, WLAN radio of the WICED device.
The STA interface is brought up using wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL); The last field is basically used for configuring the IP settings of the WICED device. It is assigned “NULL” because we configured the network to use external DHCP server. This uses the Dynamic Host Configuration Protocol (DHCP) to assign IP address to the STA. The STA attempts to join the AP configured in wifi_config_dct.h under the Client AP settings. If the join is successful, it obtains the IPv4 address for the STA using DHCP protocol.
The IPv4 address of the gateway to which the STA had connected to is then obtained using wiced_ip_get_gateway_address( WICED_STA_INTERFACE, &ping_target_ip ); This address will be used by the STA to ping the gateway.
An RTOS event is registered using wiced_rtos_register_timed_event( &ping_timed_event, WICED_NETWORKING_WORKER_THREAD, &send_ping, PING_PERIOD, 0 ); with a callback function send_ping( void *arg ). This callback will be triggered every PING_PERIOD ms and the function wiced_ping( WICED_STA_INTERFACE, &ping_target_ip, PING_TIMEOUT, &elapsed_ms ); will be called to ping the gateway with timeout equal to PING_TIMEOUT ms. This callback will be executed in the networking worker thread.
Subsequently the SoftAP interface is brought up using wiced_network_up(WICED_AP_INTERFACE, WICED_USE_INTERNAL_DHCP_SERVER, &ap_ip_settings); The ap_ip_settings contains the IP address, gateway address and netmask settings for the SoftAP. The SoftAP settings in DCT are read and the AP is started using these settings. The NetX API nx_ip_create() is used for creating an IP instance during the bring-up. Specifically the IPv4 settings, packet pools, softAP interface driver, memory, network object and priority of the IP thread are defined by the API. An RTOS thread is created to start a DHCP server and then NetX determines whether the IP address has been resolved or not. If it has been successfully resolved, NetX obtains the IPv4 address and it is displayed on UART terminal. The function wiced_dns_redirector_start( &dns_redirector, WICED_AP_INTERFACE ); is used for redirecting the URL www.wiced.com to www.wiced.com/apps/apsta/ap_top.html in the HTTP page database. Subsequently the function wiced_http_server_start ( &ap_http_server, 80, max_sockets, ap_web_pages, WICED_AP_INTERFACE, DEFAULT_URL_PROCESSOR_STACK_SIZE ) starts an HTTP webserver. The instance ap_web_pages of struct wiced_http_page_t encapsulates the redirect link "/apps/apsta/ap_top.html" which is basically found in 43xxx_Wi-Fi/resources/apps/apsta/ap_top.html. It also contains the HTTP MIME type; for instance the MIME type for "/apps/apsta/ap_top.html" is "text/html". WICED_RESOURCE_URL_CONTENT in the structure specifies that the http page ap_top.html is provided by WICED resource. It provides a resource handle structure specifying the location (whether it is in memory, filesystem or external storage), the appropriate resource handle depending on location.
Show LessAttached is the OTA2 update files for SDK-3.7.0.
The BCM943907AEVAL1F_1 evaluation board is used for updating firmware over the air firmware update.
The sample firmware is build for BCM943907AEVAL1F_1 using ota2_example and scan snip applications for future firmware to updates.
Extract the content of the attached compressed file OTA2Update_WicedSDK-3.7.0.tgz into Wiced SDK-3.7.0 release.
Content of OTA2Update_WicedSDK-3.7.0.tgz:
apps/snip/ota2_example/ota2_example.mk
apps/snip/ota2_example/ota2_test.c
apps/snip/ota2_example/ota2_test.h
apps/snip/ota2_example/ota2_test_config.c
apps/snip/ota2_example/ota2_test_config.h
apps/snip/ota2_example/ota2_test_dct.c
apps/snip/ota2_example/ota2_test_dct.h
apps/snip/ota2_example/wifi_config_dct.h
apps/snip/ota2_extract/ota2_extract.c
apps/snip/ota2_extract/ota2_extract.mk
apps/snip/scan/scan.c
apps/snip/scan/scan.mk
apps/snip/scan/wifi_config_dct.h
libraries/daemons/ota2_server/ota2_server.c
libraries/daemons/ota2_server/ota2_server.h
libraries/daemons/ota2_server/ota2_server.mk
libraries/daemons/ota2_server/ota2_server_web_page.c
libraries/daemons/ota2_server/ota2_server_web_page.h
libraries/daemons/ota2_server/wiced_ota2_server.c
libraries/daemons/ota2_server/wiced_ota2_server.h
libraries/daemons/ota2_service/ota2_service.mk
libraries/daemons/ota2_service/wiced_ota2_network.c
libraries/daemons/ota2_service/wiced_ota2_network.h
libraries/daemons/ota2_service/wiced_ota2_service.c
libraries/daemons/ota2_service/wiced_ota2_service.h
libraries/utilities/command_console/dct/command_console_dct.c
libraries/utilities/command_console/dct/command_console_dct.h
libraries/utilities/command_console/dct/dct.mk
WICED/platform/MCU/wiced_dct_external_common.c
WICED/platform/MCU/wiced_dct_internal_common.c
tools/makefiles/wiced_apps.mk
1.
Build the snip.ota2_extract snip application first. The ota_extract elf file is needed by the snip.ota2_example and snip.scan will be build later. The ota2_extact elf file could be found in .../build/snip.ota2_extract-BCM943907AEVAL1F_1.B1/binary/snip.ota2_extract-BCM943907AEVAL1F_1.B1.stripped.elf OTA location.
Use the following make target command to build the ota2_extract:
snip.ota2_extract-<Platform>
snip.ota2_extract-BCM943907AEVAL1F_1.B1
2.
Build snip.scan snip application that simulates the new firmware that will updated using OTA. Building snip.scan will cause the firmware to be downloaded to the target device.
Use the following make target to build the snip.scan:
snip.scan-BCM943907AEVAL1F_1.B1 ota2_image
3.
Build the snip.ota2_example snip application using the attached snip.ota2_example files.
This snip application demonstrates a firmware upgrade using OTA by following means:
- Command like interface to initiate new firmware update using over the air
- The target device could be brought up as an Soft-AP and new firmware update could be initiated using html page served by the target device.
Use the following make target to build the snip.ota2_example:
snip.ota2_example-BCM943907AEVAL1F_1.B1 download download_apps ota2_image run
4.
As a result of building snip.ota2_example and snip.scan application binary files will be generated for each build. These binary files will be used to update the firmware on the device using OTA. Initial release of firmware snip.ota2_example will be updated by snip.scan then back to snip.ota2_example.
The /build/snip.ota2_example-BCM943907AEVAL1F_1.B1/OTA2_image_file.bin is named as OTA2ExampleFW.bin
The /build/snip.scan-BCM943907AEVAL1F_1.B1/OTA2_image_file.bin binary file is renamed as FW2BeUpdatedUsingOTA.bin
The both binary files are attached as reference only.
Both binary files are copied into the web server default file server location. In this case, mongoose (is used to serve the firmware binary files to be pulled and pushed by the target device.
The default port used by the ota2_example is port 80. Either the web server port could be changed to match the ota2_example port number or web server port number could be passed to the ota2_example.
5.
After building and loading the loading the snip.ota2_example to the target, by default the target device boots and tries to connect to the AP defined in /apps/snip/ota2_example/wifi_config_dct.h.
#define CLIENT_AP_SSID "BroadcomSA_24"
#define CLIENT_AP_PASSPHRASE "123456789SA"
Connect the device that running the web server to the same network as the target device (BCM943907AEVAL1F_1) is connected. In this case the windows laptop is also connected to BroadcomSA_24 and has the IP address of 192.168.0.100.
Using the snip.ota2_example application, the command line interface is used to initiate a new firmware update using OTA.
Issue the following command to start OTA of the snip.scan application as new firmware to update.
get_update <web-server>/<New Firmware To OTA>
In this case, below command is used to initiate a new firmware to be pulled down to the target device:
get_update 192.168.0.100/FW2BeUpdatedUsingOTA.bin
> get_update 192.168.0.100/FW2BeUpdatedUsingOTA.bin
> PLAYER_EVENT_GET_UPDATE !
ota2_test_get_update() player->ota2_bg_service 0x0
ota2_test_get_update() wiced_ota2_service_init() bg_service:0x505c80
Download the OTA Image file - get it NOW!
wiced_ota2_service_network_switch_to_ota2_ap() network to switch to.
----------------------------- OTA2 Service Called : AP_CONNECTED -----------------------------
return SUCESS (not used by service). This is informational
Try 0 Connecting to 192.168.0.100:80 (192.168.0.100) !
----------------------------- OTA2 Service Called : SERVER_CONNECTED -----------------------------
return SUCESS (not used by service). This is informational
----------------------------- OTA2 Service Called : UPDATE_AVAILABLE -----------------------------
return SUCCESS, let Service perform the download.
Try 0 Connecting to 192.168.0.100:80 (192.168.0.100) !
----------------------------- OTA2 Service Called : SERVER_CONNECTED -----------------------------
return SUCESS (not used by service). This is informational
----------------------------- OTA2 Service Called : PERFORM_UPDATE -----------------------------
return SUCCESS, let Service extract update on next reboot.
Set WICED_OTA2_IMAGE_EXTRACT_ON_NEXT_BOOT!
After download, reboot the target by "update_reboot" to extract the new firmware.
After extract, reboot the target again to start new firmware running.
Note: A full terminal output is attached as well.
6.
Now the updated firmware of snip.scan is running on the target.
If the button 1 (push button connected between BCM943907AEVAL1F_1 J6-2 and gnd) on target is pressed and hold at reset of the target and released after 5 seconds of reset, the target device boots as Soft-AP with SSID and passphrase defined in the /apps/snip/scan/wifi_config_dct.h
#define SOFT_AP_SSID "Scan WICED Soft AP"
#define SOFT_AP_PASSPHRASE "abcd1234"
Connect the client device to the "Scan WICED Soft AP" where the OTA2ExampleFW.bin binary is located.
Using a web browser on the client device open the default web page of the target device.
The target device IP address is printed on the terminal:
Hi, I'm the OTA2 extraction app (ota2_extract).
IPv4 network ready IP: 192.168.10.1
Setting IPv6 link-local address
IPv6 network ready IP: FE80:0000:0000:0000:9AF1:70FF:FE6F:7D92
Using "Choose File" select the next firmware to update. In this case the snip.ota2_example firmware will be loaded back on the target by pushing new firmware to target via OTA.
Same above step could be done using snip.ota2_example snip application running on the target. In this case the target device will boot up as Soft-AP where the SSID and passphrase defined in the /apps/snip/ota2_example/wifi_config_dct.h
#define SOFT_AP_SSID "Ota2Ex WICED Soft AP"
#define SOFT_AP_PASSPHRASE "abcd1234"
7. DCT Structure Update for OTA
After the device firmware is updated using OTA2, the DCT data is updated from previous version to new version. For OTA2 example the version of the Wiced SDK is used for reference. Final device could use different version number then the Wiced SDK and incorporate SDK to final product changes into one. Existing DCT data structures are copied to new DCT structures and new locations. Any updates on the DCT by new version are implemented by the following files in the Wiced SDK:
.../WICED/platform/MCU/wiced_dct_external_common.c
.../WICED/platform/MCU/wiced_dct_external_ota2.c
.../WICED/platform/MCU/wiced_dct_internal_common.c
.../WICED/platform/MCU/wiced_dct_internal_ota2.c
The DCT structure is defined in the .../WICED/platform/include/platform_dct.h used by the OTA application to update the DCT data.
/* The structure for the complete system DCT layout.
* The application DCT data follows this structure in the DCT section of FLASH.
*/
typedef struct
{
platform_dct_header_t dct_header;
platform_dct_mfg_info_t mfg_info;
platform_dct_security_t security_credentials;
platform_dct_wifi_config_t wifi_config;
platform_dct_ethernet_config_t ethernet_config;
platform_dct_network_config_t network_config;
platform_dct_bt_config_t bt_config;
platform_dct_p2p_config_t p2p_config;
platform_dct_ota2_config_t ota2_config;
platform_dct_version_t dct_version;
} platform_dct_data_t;
The DCT offsets are defined in the wiced_dct_external_common.c to copy the DCT data corresponding locations.
static const uint32_t DCT_section_offsets[ ] =
{
[DCT_APP_SECTION] = sizeof(platform_dct_data_t),
[DCT_SECURITY_SECTION] = OFFSETOF( platform_dct_data_t, security_credentials ),
[DCT_MFG_INFO_SECTION] = OFFSETOF( platform_dct_data_t, mfg_info ),
[DCT_WIFI_CONFIG_SECTION] = OFFSETOF( platform_dct_data_t, wifi_config ),
#ifdef WICED_DCT_INCLUDE_BT_CONFIG
[DCT_BT_CONFIG_SECTION] = OFFSETOF( platform_dct_data_t, bt_config ),
#endif
[DCT_INTERNAL_SECTION] = 0,
};
The new DCT structures are updated with the existing data from the device by wiced_result_t wiced_dct_external_dct_update(…) in ../platform/MCU/wiced_dct_external_common.c
/*
* dct_source - Start address of the DCT to read from to update to current SDK's DCT layout
* dct_destination - Start address of the DCT to write current SDK's DCT layout
*/
static wiced_result_t wiced_dct_external_dct_update(uint32_t dct_destination, uint32_t dct_source)
For example the WiFi configuration (platform_dct_wifi_config_t ) is updated by the wiced_dct_update_wifi_config_to_current(…) call in ../platform/MCU/wiced_dct_external_common.c
/* wifi config */
memset( dst_dct_buffer, 0x00, LARGEST_DCT_SUB_STRUCTURE_SIZE);
if (sflash_read( &sflash_handle, (dct_source + OFFSETOF(bootloader_dct_data_t, wifi_config)), src_dct_buffer, sizeof(platform_dct_wifi_config_t)) == WICED_SUCCESS)
{
if (wiced_dct_update_wifi_config_to_current((platform_dct_wifi_config_t*)dst_dct_buffer, (platform_dct_wifi_config_t*)src_dct_buffer) == WICED_SUCCESS)
{
if ( sflash_write( &sflash_handle, dct_destination + OFFSETOF(platform_dct_data_t, wifi_config), dst_dct_buffer, sizeof(platform_dct_wifi_config_t) ) != PLATFORM_SUCCESS)
{
goto _update_fail;
}
}
}
Any specific changes made in the WiFi configuration could be included in the wiced_dct_update_wifi_config_to_current(…). Currently the current data is copied to the new DCT structure and any specific changes could be incorporated into here.
wiced_result_t wiced_dct_update_wifi_config_to_current (platform_dct_wifi_config_t* wifi_config_destination,
platform_dct_wifi_config_t* wifi_config_source)
Currently OTA2 is tested on the BCM43907 and BCM43909 based platforms.
Support for other platforms will be available soon.