diff --git a/WiFi/WiFi.cpp b/WiFi/WiFi.cpp index 9d30c0ade..e613bc2f2 100755 --- a/WiFi/WiFi.cpp +++ b/WiFi/WiFi.cpp @@ -40,13 +40,6 @@ uint8_t WiFiClass::getSocket() return NO_SOCKET_AVAIL; } -int WiFiClass::begin() -{ - // Add procedure to read the latest configuration from eeprom/dataflash - // and start the wifi connection - return WL_IDLE_STATUS; -} - int WiFiClass::begin(char* ssid) { uint8_t status = WL_IDLE_STATUS; @@ -188,11 +181,4 @@ uint8_t WiFiClass::status() return WiFiDrv::getConnectionStatus(); } -uint8_t WiFiClass::test() -{ - return WiFiDrv::testCmd(); -} - - - WiFiClass WiFi; diff --git a/WiFi/WiFi.h b/WiFi/WiFi.h index fbb1225d2..cabfd139a 100755 --- a/WiFi/WiFi.h +++ b/WiFi/WiFi.h @@ -4,9 +4,10 @@ #include extern "C" { - #include "utility/wl_definitions.h" + #include "utility/wl_definitions.h" + #include "utility/wl_types.h" } - + #include "IPAddress.h" #include "WiFiClient.h" #include "WiFiServer.h" @@ -28,20 +29,31 @@ public: WiFiClass(); - // Get thefirst socket available + // Get the first socket available static uint8_t getSocket(); - // Start Wifi connection with latest settings - int begin(); - - // Start Wifi connection with no encryption + /* Start Wifi connection for OPEN networks + * + * param ssid: Pointer to the SSID string. + */ int begin(char* ssid); - // Start Wifi connection with WEP encryption + /* Start Wifi connection with WEP encryption. + * Configure a key into the device. The key type (WEP-40, WEP-104) + * is determined by the size of the key (5 bytes for WEP-40, 13 bytes for WEP-104). + * + * param ssid: Pointer to the SSID string. + * param key_idx: The key index to set. Valid values are 0-3. + * param key: Key input buffer. + */ int begin(char* ssid, uint8_t key_idx, const char* key); - // Start Wifi connection with passphrase - // the most secure supported mode will be automatically selected + /* Start Wifi connection with passphrase + * the most secure supported mode will be automatically selected + * + * param passphrase: Passphrase. Valid characters in a passphrase + * must be between ASCII 32-126 (decimal). + */ int begin(char* ssid, const char *passphrase); // Disconnect from the network @@ -83,12 +95,12 @@ public: // Return the current RSSI /Received Signal Strength in dBm) associated with the network identified with networkItem int32_t RSSI(uint8_t networkItem); - // Return Connection status + /* Return Connection status. + * + * return: one of the value defined in wl_status_t + */ uint8_t status(); - // function used for test - uint8_t test(); - friend class WiFiClient; friend class WiFiServer; }; diff --git a/WiFi/utility/spi_drv.cpp b/WiFi/utility/spi_drv.cpp index 93c693149..aaa596fcf 100644 --- a/WiFi/utility/spi_drv.cpp +++ b/WiFi/utility/spi_drv.cpp @@ -2,7 +2,7 @@ #include "Arduino.h" #include "spi_drv.h" #include "pins_arduino.h" -#define _DEBUG_ +//#define _DEBUG_ extern "C" { #include "debug.h" } diff --git a/WiFi/utility/wifi_drv.cpp b/WiFi/utility/wifi_drv.cpp index 24d160674..6065107d6 100644 --- a/WiFi/utility/wifi_drv.cpp +++ b/WiFi/utility/wifi_drv.cpp @@ -15,6 +15,9 @@ extern "C" { } char WiFiDrv::_networkSsid[][WL_SSID_MAX_LENGTH] = {{"1"},{"2"},{"3"},{"4"},{"5"}}; +int32_t WiFiDrv::_networkRssi[WL_NETWORKS_LIST_MAXNUM] = { 0 }; +uint8_t WiFiDrv::_networkEncr[WL_NETWORKS_LIST_MAXNUM] = { 0 }; + char WiFiDrv::_ssid[] = {0}; uint8_t WiFiDrv::_bssid[] = {0}; uint8_t WiFiDrv::_mac[] = {0}; @@ -289,7 +292,7 @@ uint8_t WiFiDrv::getCurrentEncryptionType() // Wait for reply uint8_t dataLen = 0; uint8_t encType = 0; - SpiDrv::waitResponseCmd(GET_CURR_ENCT_CMD, PARAM_NUMS_1, (uint8_t*)encType, &dataLen); + SpiDrv::waitResponseCmd(GET_CURR_ENCT_CMD, PARAM_NUMS_1, (uint8_t*)&encType, &dataLen); SpiDrv::spiSlaveDeselect(); @@ -303,9 +306,6 @@ uint8_t WiFiDrv::scanNetworks() // Send Command SpiDrv::sendCmd(SCAN_NETWORKS, PARAM_NUMS_0); -// uint8_t _dummy = DUMMY_DATA; -// SpiDrv::sendParam(&_dummy, 1, LAST_PARAM); - //Wait the reply elaboration SpiDrv::waitForSlaveReady(); @@ -330,10 +330,25 @@ uint8_t WiFiDrv::getEncTypeNetowrks(uint8_t networkItem) { if (networkItem >= WL_NETWORKS_LIST_MAXNUM) return NULL; - uint8_t networkEncType = 0; - //TODO make an RPC call to get the encryption type associated with networkItem - return networkEncType; + WAIT_FOR_SLAVE_SELECT(); + + // Send Command + SpiDrv::sendCmd(GET_IDX_ENCT_CMD, PARAM_NUMS_1); + + SpiDrv::sendParam(&networkItem, 1, LAST_PARAM); + + //Wait the reply elaboration + SpiDrv::waitForSlaveReady(); + + // Wait for reply + uint8_t dataLen = 0; + uint8_t encType = 0; + SpiDrv::waitResponseCmd(GET_IDX_ENCT_CMD, PARAM_NUMS_1, (uint8_t*)&encType, &dataLen); + + SpiDrv::spiSlaveDeselect(); + + return encType; } int32_t WiFiDrv::getRSSINetoworks(uint8_t networkItem) @@ -342,29 +357,23 @@ int32_t WiFiDrv::getRSSINetoworks(uint8_t networkItem) return NULL; int32_t networkRssi = 0; - //TODO make an RPC call to get the rssi associated with networkItem - return networkRssi; -} - -uint8_t WiFiDrv::testCmd() -{ WAIT_FOR_SLAVE_SELECT(); // Send Command - SpiDrv::sendCmd(TEST_CMD, PARAM_NUMS_0); + SpiDrv::sendCmd(GET_IDX_RSSI_CMD, PARAM_NUMS_1); + + SpiDrv::sendParam(&networkItem, 1, LAST_PARAM); //Wait the reply elaboration SpiDrv::waitForSlaveReady(); // Wait for reply - uint8_t _data = 0; - uint8_t _dataLen = 0; - SpiDrv::waitResponseCmd(TEST_CMD, PARAM_NUMS_1, &_data, &_dataLen); + uint8_t dataLen = 0; + SpiDrv::waitResponseCmd(GET_IDX_RSSI_CMD, PARAM_NUMS_1, (uint8_t*)&networkRssi, &dataLen); SpiDrv::spiSlaveDeselect(); - return _data; + return networkRssi; } - WiFiDrv wiFiDrv; diff --git a/WiFi/utility/wifi_drv.h b/WiFi/utility/wifi_drv.h index 80cc2d8a0..6a3e77dd4 100644 --- a/WiFi/utility/wifi_drv.h +++ b/WiFi/utility/wifi_drv.h @@ -14,6 +14,8 @@ class WiFiDrv private: // settings of requested network static char _networkSsid[WL_NETWORKS_LIST_MAXNUM][WL_SSID_MAX_LENGTH]; + static int32_t _networkRssi[WL_NETWORKS_LIST_MAXNUM]; + static uint8_t _networkEncr[WL_NETWORKS_LIST_MAXNUM]; // settings of current selected network static char _ssid[WL_SSID_MAX_LENGTH]; @@ -63,7 +65,6 @@ public: static uint8_t getEncTypeNetowrks(uint8_t networkItem); - static uint8_t testCmd(); }; extern WiFiDrv wiFiDrv; diff --git a/WiFi/utility/wifi_spi.h b/WiFi/utility/wifi_spi.h index cdcc02fea..daa06ea45 100644 --- a/WiFi/utility/wifi_spi.h +++ b/WiFi/utility/wifi_spi.h @@ -41,8 +41,11 @@ enum { START_CLIENT_TCP_CMD= 0x2D, STOP_CLIENT_TCP_CMD = 0x2E, GET_CLIENT_STATE_TCP_CMD= 0x2F, - DISCONNECT_CMD = 0x30, + GET_IDX_SSID_CMD = 0x31, + GET_IDX_RSSI_CMD = 0x32, + GET_IDX_ENCT_CMD = 0x33, + // All command with DATA_FLAG 0x40 send a 16bit Len SEND_DATA_TCP_CMD = 0x44, diff --git a/WiFi/utility/wl_definitions.h b/WiFi/utility/wl_definitions.h index e28064a3d..e3db8b608 100644 --- a/WiFi/utility/wl_definitions.h +++ b/WiFi/utility/wl_definitions.h @@ -35,5 +35,15 @@ typedef enum { WL_DISCONNECTED } wl_status_t; +/* Encryption modes */ +enum wl_enc_type { /* Values map to 802.11 encryption suites... */ + ENC_TYPE_WEP = 5, + ENC_TYPE_TKIP = 2, + ENC_TYPE_CCMP = 4, + /* ... except these two, 7 and 8 are reserved in 802.11-2007 */ + ENC_TYPE_NONE = 7, + ENC_TYPE_AUTO = 8 +}; + #endif /* WL_DEFINITIONS_H_ */ diff --git a/WiFi/utility/wl_types.h b/WiFi/utility/wl_types.h index 7f6e8f22c..82b309d7f 100644 --- a/WiFi/utility/wl_types.h +++ b/WiFi/utility/wl_types.h @@ -28,15 +28,4 @@ enum wl_auth_mode { AUTH_MODE_WPA2_PSK }; - -/* Encryption modes */ -enum wl_enc_type { /* Values map to 802.11 encryption suites... */ - ENC_TYPE_WEP = 5, - ENC_TYPE_TKIP = 2, - ENC_TYPE_CCMP = 4, - /* ... except these two, 7 and 8 are reserved in 802.11-2007 */ - ENC_TYPE_NONE = 7, - ENC_TYPE_AUTO = 8 -}; - #endif //_WL_TYPES_H_