Permalink
Browse files

Merge branch 'master' of ../wifishield

  • Loading branch information...
2 parents 532a46a + ed51181 commit 3f5298d19fc575301fd36a689cf5a234b5fab996 @damellis damellis committed Sep 13, 2012
Showing with 4,275 additions and 0 deletions.
  1. +199 −0 libraries/WiFi/WiFi.cpp
  2. +183 −0 libraries/WiFi/WiFi.h
  3. +179 −0 libraries/WiFi/WiFiClient.cpp
  4. +40 −0 libraries/WiFi/WiFiClient.h
  5. +88 −0 libraries/WiFi/WiFiServer.cpp
  6. +27 −0 libraries/WiFi/WiFiServer.h
  7. +121 −0 libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino
  8. +126 −0 libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino
  9. +116 −0 libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino
  10. +119 −0 libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino
  11. +111 −0 libraries/WiFi/examples/WifiChatServer/WifiChatServer.ino
  12. +190 −0 libraries/WiFi/examples/WifiPachubeClient/WifiPachubeClient.ino
  13. +177 −0 libraries/WiFi/examples/WifiPachubeClientString/WifiPachubeClientString.ino
  14. +163 −0 libraries/WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino
  15. +121 −0 libraries/WiFi/examples/WifiWebClient/WifiWebClient.ino
  16. +138 −0 libraries/WiFi/examples/WifiWebClientRepeating/WifiWebClientRepeating.ino
  17. +132 −0 libraries/WiFi/examples/WifiWebServer/WifiWebServer.ino
  18. +43 −0 libraries/WiFi/keywords.txt
  19. +77 −0 libraries/WiFi/utility/debug.h
  20. +260 −0 libraries/WiFi/utility/server_drv.cpp
  21. +34 −0 libraries/WiFi/utility/server_drv.h
  22. +20 −0 libraries/WiFi/utility/socket.c
  23. +87 −0 libraries/WiFi/utility/socket.h
  24. +506 −0 libraries/WiFi/utility/spi_drv.cpp
  25. +83 −0 libraries/WiFi/utility/spi_drv.h
  26. +491 −0 libraries/WiFi/utility/wifi_drv.cpp
  27. +219 −0 libraries/WiFi/utility/wifi_drv.h
  28. +144 −0 libraries/WiFi/utility/wifi_spi.h
  29. +50 −0 libraries/WiFi/utility/wl_definitions.h
  30. +31 −0 libraries/WiFi/utility/wl_types.h
View
@@ -0,0 +1,199 @@
+#include "wifi_drv.h"
+#include "WiFi.h"
+
+extern "C" {
+ #include "utility/wl_definitions.h"
+ #include "utility/wl_types.h"
+ #include "debug.h"
+}
+
+// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
+int16_t WiFiClass::_state[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
+uint16_t WiFiClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
+
+WiFiClass::WiFiClass()
+{
+ // Driver initialization
+ init();
+}
+
+void WiFiClass::init()
+{
+ WiFiDrv::wifiDriverInit();
+}
+
+uint8_t WiFiClass::getSocket()
+{
+ for (uint8_t i = 0; i < MAX_SOCK_NUM; ++i)
+ {
+ if (WiFiClass::_server_port[i] == 0)
+ {
+ return i;
+ }
+ }
+ return NO_SOCKET_AVAIL;
+}
+
+char* WiFiClass::firmwareVersion()
+{
+ return WiFiDrv::getFwVersion();
+}
+
+int WiFiClass::begin(char* ssid)
+{
+ uint8_t status = WL_IDLE_STATUS;
+ uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
+
+ if (WiFiDrv::wifiSetNetwork(ssid, strlen(ssid)) != WL_FAILURE)
+ {
+ do
+ {
+ delay(WL_DELAY_START_CONNECTION);
+ status = WiFiDrv::getConnectionStatus();
+ }
+ while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
+ }else
+ {
+ status = WL_CONNECT_FAILED;
+ }
+ return status;
+}
+
+int WiFiClass::begin(char* ssid, uint8_t key_idx, const char *key)
+{
+ uint8_t status = WL_IDLE_STATUS;
+ uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
+
+ // set encryption key
+ if (WiFiDrv::wifiSetKey(ssid, strlen(ssid), key_idx, key, strlen(key)) != WL_FAILURE)
+ {
+ do
+ {
+ delay(WL_DELAY_START_CONNECTION);
+ status = WiFiDrv::getConnectionStatus();
+ }
+ while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
+ }else{
+ status = WL_CONNECT_FAILED;
+ }
+ return status;
+}
+
+int WiFiClass::begin(char* ssid, const char *passphrase)
+{
+ uint8_t status = WL_IDLE_STATUS;
+ uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
+
+ // set passphrase
+ if (WiFiDrv::wifiSetPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase))!= WL_FAILURE)
+ {
+ do
+ {
+ delay(WL_DELAY_START_CONNECTION);
+ status = WiFiDrv::getConnectionStatus();
+ }
+ while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
+ }else{
+ status = WL_CONNECT_FAILED;
+ }
+ return status;
+}
+
+int WiFiClass::disconnect()
+{
+ return WiFiDrv::disconnect();
+}
+
+uint8_t* WiFiClass::macAddress(uint8_t* mac)
+{
+ uint8_t* _mac = WiFiDrv::getMacAddress();
+ memcpy(mac, _mac, WL_MAC_ADDR_LENGTH);
+ return mac;
+}
+
+IPAddress WiFiClass::localIP()
+{
+ IPAddress ret;
+ WiFiDrv::getIpAddress(ret);
+ return ret;
+}
+
+IPAddress WiFiClass::subnetMask()
+{
+ IPAddress ret;
+ WiFiDrv::getSubnetMask(ret);
+ return ret;
+}
+
+IPAddress WiFiClass::gatewayIP()
+{
+ IPAddress ret;
+ WiFiDrv::getGatewayIP(ret);
+ return ret;
+}
+
+char* WiFiClass::SSID()
+{
+ return WiFiDrv::getCurrentSSID();
+}
+
+uint8_t* WiFiClass::BSSID(uint8_t* bssid)
+{
+ uint8_t* _bssid = WiFiDrv::getCurrentBSSID();
+ memcpy(bssid, _bssid, WL_MAC_ADDR_LENGTH);
+ return bssid;
+}
+
+int32_t WiFiClass::RSSI()
+{
+ return WiFiDrv::getCurrentRSSI();
+}
+
+uint8_t WiFiClass::encryptionType()
+{
+ return WiFiDrv::getCurrentEncryptionType();
+}
+
+
+int8_t WiFiClass::scanNetworks()
+{
+ uint8_t attempts = 10;
+ uint8_t numOfNetworks = 0;
+
+ if (WiFiDrv::startScanNetworks() == WL_FAILURE)
+ return WL_FAILURE;
+ do
+ {
+ delay(2000);
+ numOfNetworks = WiFiDrv::getScanNetworks();
+ }
+ while (( numOfNetworks == 0)&&(--attempts>0));
+ return numOfNetworks;
+}
+
+char* WiFiClass::SSID(uint8_t networkItem)
+{
+ return WiFiDrv::getSSIDNetoworks(networkItem);
+}
+
+int32_t WiFiClass::RSSI(uint8_t networkItem)
+{
+ return WiFiDrv::getRSSINetoworks(networkItem);
+}
+
+uint8_t WiFiClass::encryptionType(uint8_t networkItem)
+{
+ return WiFiDrv::getEncTypeNetowrks(networkItem);
+}
+
+uint8_t WiFiClass::status()
+{
+ return WiFiDrv::getConnectionStatus();
+}
+
+int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
+{
+ return WiFiDrv::getHostByName(aHostname, aResult);
+}
+
+WiFiClass WiFi;
View
@@ -0,0 +1,183 @@
+#ifndef WiFi_h
+#define WiFi_h
+
+#include <inttypes.h>
+
+extern "C" {
+ #include "utility/wl_definitions.h"
+ #include "utility/wl_types.h"
+}
+
+#include "IPAddress.h"
+#include "WiFiClient.h"
+#include "WiFiServer.h"
+
+class WiFiClass
+{
+private:
+
+ static void init();
+public:
+ static int16_t _state[MAX_SOCK_NUM];
+ static uint16_t _server_port[MAX_SOCK_NUM];
+
+ WiFiClass();
+
+ /*
+ * Get the first socket available
+ */
+ static uint8_t getSocket();
+
+ /*
+ * Get firmware version
+ */
+ static char* firmwareVersion();
+
+
+ /* Start Wifi connection for OPEN networks
+ *
+ * param ssid: Pointer to the SSID string.
+ */
+ int begin(char* ssid);
+
+ /* 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
+ *
+ * param ssid: Pointer to the SSID string.
+ * 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
+ *
+ * return: one value of wl_status_t enum
+ */
+ int disconnect(void);
+
+ /*
+ * Get the interface MAC address.
+ *
+ * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
+ */
+ uint8_t* macAddress(uint8_t* mac);
+
+ /*
+ * Get the interface IP address.
+ *
+ * return: Ip address value
+ */
+ IPAddress localIP();
+
+ /*
+ * Get the interface subnet mask address.
+ *
+ * return: subnet mask address value
+ */
+ IPAddress subnetMask();
+
+ /*
+ * Get the gateway ip address.
+ *
+ * return: gateway ip address value
+ */
+ IPAddress gatewayIP();
+
+ /*
+ * Return the current SSID associated with the network
+ *
+ * return: ssid string
+ */
+ char* SSID();
+
+ /*
+ * Return the current BSSID associated with the network.
+ * It is the MAC address of the Access Point
+ *
+ * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
+ */
+ uint8_t* BSSID(uint8_t* bssid);
+
+ /*
+ * Return the current RSSI /Received Signal Strength in dBm)
+ * associated with the network
+ *
+ * return: signed value
+ */
+ int32_t RSSI();
+
+ /*
+ * Return the Encryption Type associated with the network
+ *
+ * return: one value of wl_enc_type enum
+ */
+ uint8_t encryptionType();
+
+ /*
+ * Start scan WiFi networks available
+ *
+ * return: Number of discovered networks
+ */
+ int8_t scanNetworks();
+
+ /*
+ * Return the SSID discovered during the network scan.
+ *
+ * param networkItem: specify from which network item want to get the information
+ *
+ * return: ssid string of the specified item on the networks scanned list
+ */
+ char* SSID(uint8_t networkItem);
+
+ /*
+ * Return the encryption type of the networks discovered during the scanNetworks
+ *
+ * param networkItem: specify from which network item want to get the information
+ *
+ * return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
+ */
+ uint8_t encryptionType(uint8_t networkItem);
+
+ /*
+ * Return the RSSI of the networks discovered during the scanNetworks
+ *
+ * param networkItem: specify from which network item want to get the information
+ *
+ * return: signed value of RSSI of the specified item on the networks scanned list
+ */
+ int32_t RSSI(uint8_t networkItem);
+
+ /*
+ * Return Connection status.
+ *
+ * return: one of the value defined in wl_status_t
+ */
+ uint8_t status();
+
+ /*
+ * Resolve the given hostname to an IP address.
+ * param aHostname: Name to be resolved
+ * param aResult: IPAddress structure to store the returned IP address
+ * result: 1 if aIPAddrString was successfully converted to an IP address,
+ * else error code
+ */
+ int hostByName(const char* aHostname, IPAddress& aResult);
+
+ friend class WiFiClient;
+ friend class WiFiServer;
+};
+
+extern WiFiClass WiFi;
+
+#endif
Oops, something went wrong.

0 comments on commit 3f5298d

Please sign in to comment.