diff --git a/ISM43362/ISM43362.cpp b/ISM43362/ISM43362.cpp index e38d352..686b7e8 100644 --- a/ISM43362/ISM43362.cpp +++ b/ISM43362/ISM43362.cpp @@ -177,7 +177,7 @@ bool ISM43362::dhcp(bool enabled) return (_parser.send("C4=%d", enabled ? 1:0) && check_response()); } -bool ISM43362::connect(const char *ap, const char *passPhrase) +bool ISM43362::connect(const char *ap, const char *passPhrase, ism_security_t ap_sec) { if (!(_parser.send("C1=%s", ap) && check_response())) { return false; @@ -186,8 +186,14 @@ bool ISM43362::connect(const char *ap, const char *passPhrase) if (!(_parser.send("C2=%s", passPhrase) && check_response())) { return false; } - /* TODO security level = 3 , is it hardcoded or not ???? */ - if (!(_parser.send("C3=3") && check_response())) { + + /* Check security level is acceptable */ + if (ap_sec > ISM_SECURITY_WPA_WPA2 ) { + debug_if(ism_debug, "Unsupported security level %d\n", ap_sec); + return false; + } + + if (!(_parser.send("C3=%d", ap_sec) && check_response())) { return false; } /* now connect */ diff --git a/ISM43362/ISM43362.h b/ISM43362/ISM43362.h index 9466a9b..f846a50 100644 --- a/ISM43362/ISM43362.h +++ b/ISM43362/ISM43362.h @@ -28,10 +28,18 @@ #define ES_WIFI_RTOS_REV_SIZE 16 // The input range for AT Command 'R1' is 0 to 1200 bytes -// ‘R1’ Set Read Transport Packet Size (bytes) +// 'R1' Set Read Transport Packet Size (bytes) #define ES_WIFI_MAX_RX_PACKET_SIZE 1200 // Module maxume DATA payload for Tx packet is 1460 #define ES_WIFI_MAX_TX_PACKET_SIZE 1460 +typedef enum ism_security { + ISM_SECURITY_NONE = 0x0, /*!< open access point */ + ISM_SECURITY_WEP = 0x1, /*!< phrase conforms to WEP */ + ISM_SECURITY_WPA = 0x2, /*!< phrase conforms to WPA */ + ISM_SECURITY_WPA2 = 0x3, /*!< phrase conforms to WPA2 */ + ISM_SECURITY_WPA_WPA2 = 0x4, /*!< phrase conforms to WPA/WPA2 */ + ISM_SECURITY_UNKNOWN = 0xFF, /*!< unknown/unsupported security in scan results */ +} ism_security_t; /** ISM43362Interface class. This is an interface to a ISM43362 radio. @@ -68,9 +76,10 @@ class ISM43362 * * @param ap the name of the AP * @param passPhrase the password of AP + * @param ap_sec the security level of network AP * @return true only if ISM43362 is connected successfully */ - bool connect(const char *ap, const char *passPhrase); + bool connect(const char *ap, const char *passPhrase, ism_security_t ap_sec); /** * Disconnect ISM43362 from AP diff --git a/ISM43362Interface.cpp b/ISM43362Interface.cpp index 4ff23d6..3cf320b 100644 --- a/ISM43362Interface.cpp +++ b/ISM43362Interface.cpp @@ -85,7 +85,7 @@ int ISM43362Interface::connect() _ism.setTimeout(ISM43362_CONNECT_TIMEOUT); - if (!_ism.connect(ap_ssid, ap_pass)) { + if (!_ism.connect(ap_ssid, ap_pass, ap_sec)) { return NSAPI_ERROR_NO_CONNECTION; } @@ -136,7 +136,26 @@ int ISM43362Interface::set_credentials(const char *ssid, const char *pass, nsapi memset(ap_pass, 0, sizeof(ap_pass)); strncpy(ap_pass, pass, sizeof(ap_pass)); - ap_sec = security; + switch(security) { + case NSAPI_SECURITY_NONE: + ap_sec = ISM_SECURITY_NONE; + break; + case NSAPI_SECURITY_WEP: + ap_sec = ISM_SECURITY_WEP; + break; + case NSAPI_SECURITY_WPA: + ap_sec = ISM_SECURITY_WPA; + break; + case NSAPI_SECURITY_WPA2: + ap_sec = ISM_SECURITY_WPA2; + break; + case NSAPI_SECURITY_WPA_WPA2: + ap_sec = ISM_SECURITY_WPA_WPA2; + break; + default: + ap_sec = ISM_SECURITY_UNKNOWN; + break; + } _mutex.unlock(); return 0; diff --git a/ISM43362Interface.h b/ISM43362Interface.h index 447d1c9..5587a1a 100644 --- a/ISM43362Interface.h +++ b/ISM43362Interface.h @@ -278,7 +278,7 @@ class ISM43362Interface : public NetworkStack, public WiFiInterface Mutex _mutex; Thread thread_read_socket; char ap_ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */ - nsapi_security_t ap_sec; + ism_security_t ap_sec; uint8_t ap_ch; char ap_pass[64]; /* The longest allowed passphrase */