Extending the X_NUCLEO_IDW01M1 to allow configuration of the board as an access point

Dependents:   X_NUCLEO_IDW01M1_AP_Test

Fork of X_NUCLEO_IDW01M1 by ST

Revision:
18:b265b3b696f1
Parent:
12:3799f8475c8a
Child:
19:9ab60b80872e
--- a/Spwf_API/SpwfSADevice.cpp	Thu Jun 02 06:01:26 2016 +0000
+++ b/Spwf_API/SpwfSADevice.cpp	Tue Jun 21 20:20:50 2016 +0000
@@ -35,6 +35,7 @@
   
 
 #include "SpwfSADevice.h" 
+#include "wifi_module.h"
 
 
 #ifdef __cplusplus
@@ -51,6 +52,9 @@
 
 extern void setSpwfSADevice(SpwfSADevice * dev);
 
+#define FORMAT_HEX_STRING       "0x%08x"
+#define HEX_STRING_LENGTH       11
+
 /**
 * @brief  SpwfSADevice constructor         
 * @param  tx: Pin USART TX  
@@ -91,6 +95,7 @@
 */
 int SpwfSADevice::init(void) 
 {
+    printf("SpwfSADevice::init()\n");
     WiFi_Status_t status = WiFi_MODULE_SUCCESS;
     Timer timer;
     
@@ -108,8 +113,12 @@
     uart_.attach(Rx_irq_handler, SerialBase::RxIrq);
 
     config.power=wifi_active;
-    config.power_level=high;
+    config.power_level=max;
     config.dhcp=on;//use DHCP IP address
+    config.ip_addr = "192.168.0.50";
+    config.netmask_addr = "255.255.255.0";
+    config.gateway_addr = "192.168.0.1";
+    config.dns_addr = "192.168.0.1";
     
     /*Initialize the tickers*/
     wifi_isr.attach_us(Wifi_ticker, 1000); //decreasing the time period to 1ms may be causing overrun issue with UART?\
@@ -124,7 +133,6 @@
     {
         return -1;
     }
-    
     while(!sync_wait_signal)
     {
         if (timer.read_ms() > _timeout) {
@@ -169,6 +177,62 @@
 }
 
 /**
+* @brief start the mini access point
+* @param ssid: start with this SSID
+* @param sec_key: passphrase for STAtions to connect with
+* @param priv_mode: type of security to set up with
+* @param channel_num: WiFi channel to use
+* @param data_rates: bitmap of operational data rates to support
+* @retval NSAPI Error Type
+*/
+int SpwfSADevice::start_access_point(char * ssid, char * sec_key, WiFi_Priv_Mode priv_mode, int channel_num, unsigned int data_rates)
+{
+    WiFi_Status_t status = WiFi_MODULE_SUCCESS;
+    Timer timer;
+    
+    timer.start();
+    
+    // Reset the data rate values
+    uint32_t modeNEnabled = 1;
+    char oprMask[] = "0x003fffcf";
+    if (0x3fffcf != data_rates)
+    {
+        // All data rates must be enabled to allow wireless N (high throughput/HT) mode
+        modeNEnabled = 0;
+        sprintf(oprMask, (const char*)FORMAT_HEX_STRING, data_rates);
+
+        // Different basic rate mask
+        char basMask[HEX_STRING_LENGTH];
+        sprintf(basMask, FORMAT_HEX_STRING, data_rates & 0xf);
+        status = SET_Configuration_Addr(WIFI_BAS_RATE_MASK, basMask);
+        if(status != WiFi_MODULE_SUCCESS) return -1;
+    }
+    
+    status = SET_Configuration_Value(WIFI_HT_MODE, modeNEnabled);
+    if(status != WiFi_MODULE_SUCCESS) return -1;
+    status = SET_Configuration_Addr(WIFI_OPR_RATE_MASK, oprMask);
+    if(status != WiFi_MODULE_SUCCESS) return -1;
+
+    // Start the access point
+    sync_wait_signal = false;        
+    status = wifi_ap_start((uint8_t*)ssid, (uint8_t)channel_num);
+    if(status!=WiFi_MODULE_SUCCESS)
+    {
+        return -1;
+    }        
+    
+    while(!sync_wait_signal)
+    {
+        if (timer.read_ms() > _timeout) {
+            return -1;
+        }
+        __NOP();
+    } 
+    
+    return 0;
+}
+
+/**
 * @brief  network disconnect
           wrapper function for FW
 * @param  none