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
Diff: SPWFInterface.cpp
- Revision:
- 18:b265b3b696f1
- Parent:
- 17:2c47c2aab4a4
- Child:
- 19:9ab60b80872e
--- a/SPWFInterface.cpp Thu Jun 02 06:01:26 2016 +0000 +++ b/SPWFInterface.cpp Tue Jun 21 20:20:50 2016 +0000 @@ -91,6 +91,84 @@ return (_spwf.init()); } +/** +* @brief Setup as an access point +* @param ap: SSID to set the access point up with (1-32 characters) +* @param pass_phrase: Password/key of the access point to set up (currently only Open AP is supported, this param is ignored) +* @param security: type of NSAPI security supported (currently only Open AP is supported) +* @param channelNum: Channel for the AP to operate on 1-14 (depending on region) +* @retval NSAPI Error Type +*/ +int SpwfSAInterface::start_access_point( + const char *ap, + const char *pass_phrase, + nsapi_security_t security, + int channel_num, + unsigned int data_rates) +{ + WiFi_Priv_Mode mode = convert_security(security); + + // Check for valid channel_num + if (channel_num < 1 || channel_num > 14) + { + printf("channel_num must be between 1 and 14\n"); + return NSAPI_ERROR_PARAMETER; + } + + // Verify that the access point is between 1-32 + if ((NULL == ap && mode != None) || strlen(ap) < 1 || strlen(ap) > 32) + { + printf("ap length must be between 1 and 32\n"); + return NSAPI_ERROR_PARAMETER; + } + + //initialize the device before starting the AP + if(!isInitialized) + { + if(init()==0) + isInitialized=true; + else return NSAPI_ERROR_DEVICE_ERROR; + } + + _spwf.setTimeout(SPWF_CONNECT_TIMEOUT); + + switch (mode) + { +// case WEP: +// { +// break; +// } +// case WPA_Personal: +// { +// break; +// } + default: + { + printf("Assuming open wifi access point\n"); + mode = None; + pass_phrase = NULL; + } + } + + return (_spwf.start_access_point((char*)ap, (char*)pass_phrase, mode, channel_num, data_rates)); +} + +WiFi_Priv_Mode SpwfSAInterface::convert_security(int security) +{ + switch(security) + { + case NSAPI_SECURITY_NONE: + return (WiFi_Priv_Mode) None; + case NSAPI_SECURITY_WEP: + return (WiFi_Priv_Mode) WEP; + case NSAPI_SECURITY_WPA: + case NSAPI_SECURITY_WPA2: + return (WiFi_Priv_Mode) WPA_Personal; + default: + return (WiFi_Priv_Mode) WPA_Personal; + } +} + /** * @brief network connect connects to Access Point @@ -115,23 +193,11 @@ } _spwf.setTimeout(SPWF_CONNECT_TIMEOUT); - - switch(security) + + mode = convert_security(security); + if ((WiFi_Priv_Mode) None == mode) { - case NSAPI_SECURITY_NONE: - mode = (WiFi_Priv_Mode) None; - pass_phrase = NULL; - break; - case NSAPI_SECURITY_WEP: - mode = (WiFi_Priv_Mode) WEP; - break; - case NSAPI_SECURITY_WPA: - case NSAPI_SECURITY_WPA2: - mode = (WiFi_Priv_Mode) WPA_Personal; - break; - default: - mode = (WiFi_Priv_Mode) WPA_Personal; - break; + pass_phrase = NULL; } return (_spwf.connect((char*)ap, (char*)pass_phrase, mode));