diff --git a/HISTORY.rst b/HISTORY.rst index 3746622a37..86667d056e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,20 @@ Release History 1.0.0 (?) --------- +0.5.0 (2014-08-04) +------------------ + +* Improved nested lookups for libraries +* Disabled default warning flag "-Wall" +* Added auto-conversation from \*.ino to valid \*.cpp for Arduino/Energia + frameworks (`issue #7 `_) +* Added `Arduino example `_ + with external library (Adafruit CC3000) +* Implemented ``platformio upgrade`` command and "auto-check" for the latest + version (`issue #8 `_) +* Fixed issue with "auto-reset" for Raspduino board (thanks [David Mills](https://github.com/g7uvw) for testing) +* Fixed bug with nested libs building (thanks [Antonio Vanegas](https://github.com/hpsaturn) for testing) + 0.4.0 (2014-07-31) ------------------ diff --git a/README.rst b/README.rst index 4d8dd77069..d5a398ae31 100644 --- a/README.rst +++ b/README.rst @@ -26,8 +26,7 @@ PlatformIO `Blog `_ -**PlatformIO** is a console tool to build code with different development -platforms. +**PlatformIO** is a cross-platform code builder and library manager. You have no need to install any *IDE* or compile any toolchains. *PlatformIO* has pre-built different development platforms including: compiler, debugger, @@ -284,6 +283,7 @@ To print all available commands and options: show Show details about an installed platforms uninstall Uninstall platforms update Update installed platforms + upgrade Upgrade PlatformIO to the latest version ``platformio init`` @@ -564,7 +564,7 @@ To uninstall platform: ``platformio update`` -~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~ To check or update installed platforms: @@ -603,6 +603,19 @@ To check or update installed platforms: Versions: Current=1, Latest=1 [Up-to-date] +``platformio upgrade`` +~~~~~~~~~~~~~~~~~~~~~~ + +To check or upgrade PlatformIO to the latest version: + +.. code-block:: bash + + $ platformio upgrade + + # If you have problem with permissions try: + $ sudo platformio upgrade + + Questions & Bugs ---------------- diff --git a/examples/arduino-adafruit-library/README.rst b/examples/arduino-adafruit-library/README.rst new file mode 100644 index 0000000000..8115b6392c --- /dev/null +++ b/examples/arduino-adafruit-library/README.rst @@ -0,0 +1,22 @@ +Arduino Example: Build \*.ino file with external Adafruit library +================================================================= + +1. Download ``platformio`` + `sources `_ +2. Extract ZIP archive +3. Then run these commands: + +.. code-block:: bash + + # Change directory to example + $ cd platformio-develop/examples/arduino-adafruit-library/ + + # Install Atmel AVR development platform with Arduino Framework + $ platformio install atmelavr + + # Process example project + $ platformio run + + # Upload firmware + $ platformio run -t upload + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000.cpp new file mode 100755 index 0000000000..5b7210d864 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000.cpp @@ -0,0 +1,1557 @@ +/**************************************************************************/ +/*! + @file Adafruit_CC3000.cpp + @author KTOWN (Kevin Townsend for Adafruit Industries) + @license BSD (see license.txt) + + This is a library for the Adafruit CC3000 WiFi breakout board + This library works with the Adafruit CC3000 breakout + ----> https://www.adafruit.com/products/1469 + + Check out the links above for our tutorials and wiring diagrams + These chips use SPI to communicate. + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + @section HISTORY + + v1.0 - Initial release +*/ +/**************************************************************************/ +#include "Adafruit_CC3000.h" +#include "ccspi.h" + +#include "utility/cc3000_common.h" +#include "utility/evnt_handler.h" +#include "utility/hci.h" +#include "utility/netapp.h" +#include "utility/nvmem.h" +#include "utility/security.h" +#include "utility/socket.h" +#include "utility/wlan.h" +#include "utility/debug.h" +#include "utility/sntp.h" + +uint8_t g_csPin, g_irqPin, g_vbatPin, g_IRQnum, g_SPIspeed; + +static const uint8_t dreqinttable[] = { +#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328__) || defined(__AVR_ATmega8__) + 2, 0, + 3, 1, +#elif defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) + 2, 0, + 3, 1, + 21, 2, + 20, 3, + 19, 4, + 18, 5, +#elif defined(__AVR_ATmega32U4__) && defined(CORE_TEENSY) + 5, 0, + 6, 1, + 7, 2, + 8, 3, +#elif defined(__AVR_AT90USB1286__) && defined(CORE_TEENSY) + 0, 0, + 1, 1, + 2, 2, + 3, 3, + 36, 4, + 37, 5, + 18, 6, + 19, 7, +#elif defined(__arm__) && defined(CORE_TEENSY) + 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, + 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, + 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, + 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, + 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, + 30, 30, 31, 31, 32, 32, 33, 33, +#elif defined(__AVR_ATmega32U4__) + 7, 4, + 3, 0, + 2, 1, + 0, 2, + 1, 3, +#elif defined(__arm__) && defined(__SAM3X8E__) // Arduino Due + 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, + 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, + 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, + 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, + 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, + 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, + 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, + 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, + 45, 45, 46, 46, 47, 47, 48, 48, 49, 49, + 50, 50, 51, 51, 52, 52, 53, 53, 54, 54, + 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, + 60, 60, 61, 61, 62, 62, 63, 63, 64, 64, + 65, 65, 66, 66, 67, 67, 68, 68, 69, 69, + 70, 70, 71, 71, +#endif +}; + +/***********************/ + +uint8_t pingReportnum; +netapp_pingreport_args_t pingReport; + +#define CC3000_SUCCESS (0) +#define CHECK_SUCCESS(func,Notify,errorCode) {if ((func) != CC3000_SUCCESS) { CHECK_PRINTER CC3KPrinter->println(F(Notify)); return errorCode;}} + +#define MAXSSID (32) +#define MAXLENGTHKEY (32) /* Cleared for 32 bytes by TI engineering 29/08/13 */ + +#define MAX_SOCKETS 32 // can change this +boolean closed_sockets[MAX_SOCKETS] = {false, false, false, false}; + +/* *********************************************************************** */ +/* */ +/* PRIVATE FIELDS (SmartConfig) */ +/* */ +/* *********************************************************************** */ + +class CC3000BitSet { +public: + static const byte IsSmartConfigFinished = 0x01; + static const byte IsConnected = 0x02; + static const byte HasDHCP = 0x04; + static const byte OkToShutDown = 0x08; + + void clear() { + flags = 0; + } + + bool test(const byte flag) { + return (flags & flag) != 0; + } + + void set(const byte flag) { + flags |= flag; + } + + void reset(const byte flag) { + flags &= ~flag; + } +private: + volatile byte flags; +}cc3000Bitset; + +volatile long ulSocket; +char _cc3000_prefix[] = { 'T', 'T', 'T' }; +Print* CC3KPrinter; // user specified output stream for general messages and debug + +/* *********************************************************************** */ +/* */ +/* PRIVATE FUNCTIONS */ +/* */ +/* *********************************************************************** */ + +/**************************************************************************/ +/*! + @brief Scans for SSID/APs in the CC3000's range + + @note This command isn't available when the CC3000 is configured + in 'CC3000_TINY_DRIVER' mode + + @returns False if an error occured! +*/ +/**************************************************************************/ +#ifndef CC3000_TINY_DRIVER +bool Adafruit_CC3000::scanSSIDs(uint32_t time) +{ + const unsigned long intervalTime[16] = { 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000 }; + + if (!_initialised) + { + return false; + } + + // We can abort a scan with a time of 0 + if (time) + { + CHECK_PRINTER { + CC3KPrinter->println(F("Started AP/SSID scan\n\r")); + } + } + + // Set SSID Scan params to includes channels above 11 + CHECK_SUCCESS( + wlan_ioctl_set_scan_params(time, 20, 100, 5, 0x1FFF, -120, 0, 300, + (unsigned long * ) &intervalTime), + "Failed setting params for SSID scan", false); + + return true; +} +#endif + +/* *********************************************************************** */ +/* */ +/* CONSTRUCTORS */ +/* */ +/* *********************************************************************** */ + +/**************************************************************************/ +/*! + @brief Instantiates a new CC3000 class +*/ +/**************************************************************************/ +Adafruit_CC3000::Adafruit_CC3000(uint8_t csPin, uint8_t irqPin, uint8_t vbatPin, uint8_t SPIspeed) +{ + _initialised = false; + g_csPin = csPin; + g_irqPin = irqPin; + g_vbatPin = vbatPin; + g_IRQnum = 0xFF; + g_SPIspeed = SPIspeed; + + cc3000Bitset.clear(); + + #if defined(UDR0) || defined(UDR1) || defined(CORE_TEENSY) || ( defined (__arm__) && defined (__SAM3X8E__) ) + CC3KPrinter = &Serial; + #else + CC3KPrinter = 0; + // no default serial port found + #endif +} + +/* *********************************************************************** */ +/* */ +/* PUBLIC FUNCTIONS */ +/* */ +/* *********************************************************************** */ + +/**************************************************************************/ +/*! + @brief Setups the HW + + @args[in] patchReq + Set this to true if we are starting a firmware patch, + otherwise false for normal operation + @args[in] useSmartConfig + Set this to true if you want to use the connection details + that were stored on the device from the SmartConfig process, + otherwise false to erase existing profiles and start a + clean connection +*/ +/**************************************************************************/ +bool Adafruit_CC3000::begin(uint8_t patchReq, bool useSmartConfigData, const char *_deviceName) +{ + if (_initialised) return true; + + #ifndef CORE_ADAX + // determine irq # + for (uint8_t i=0; iprintln(F("IRQ pin is not an INT pin!")); + } + return false; + } + #else + g_IRQnum = g_irqPin; + // (almost) every single pin on Xmega supports interrupt + #endif + + init_spi(); + + DEBUGPRINT_F("init\n\r"); + wlan_init(CC3000_UsynchCallback, + sendWLFWPatch, sendDriverPatch, sendBootLoaderPatch, + ReadWlanInterruptPin, + WlanInterruptEnable, + WlanInterruptDisable, + WriteWlanPin); + DEBUGPRINT_F("start\n\r"); + + wlan_start(patchReq); + + DEBUGPRINT_F("ioctl\n\r"); + // Check if we should erase previous stored connection details + // (most likely written with data from the SmartConfig app) + if (!useSmartConfigData) + { + // Manual connection only (no auto, profiles, etc.) + wlan_ioctl_set_connection_policy(0, 0, 0); + // Delete previous profiles from memory + wlan_ioctl_del_profile(255); + } + else + { + // Auto Connect - the C3000 device tries to connect to any AP it detects during scanning: + // wlan_ioctl_set_connection_policy(1, 0, 0) + + // Fast Connect - the CC3000 device tries to reconnect to the last AP connected to: + // wlan_ioctl_set_connection_policy(0, 1, 0) + + // Use Profiles - the CC3000 device tries to connect to an AP from profiles: + wlan_ioctl_set_connection_policy(0, 0, 1); + } + + CHECK_SUCCESS( + wlan_set_event_mask(HCI_EVNT_WLAN_UNSOL_INIT | + //HCI_EVNT_WLAN_ASYNC_PING_REPORT |// we want ping reports + //HCI_EVNT_BSD_TCP_CLOSE_WAIT | + //HCI_EVNT_WLAN_TX_COMPLETE | + HCI_EVNT_WLAN_KEEPALIVE), + "WLAN Set Event Mask FAIL", false); + + _initialised = true; + + // Wait for re-connection if we're using SmartConfig data + if (useSmartConfigData) + { + // Wait for a connection + uint32_t timeout = 0; + while(!cc3000Bitset.test(CC3000BitSet::IsConnected)) + { + cc3k_int_poll(); + if(timeout > WLAN_CONNECT_TIMEOUT) + { + CHECK_PRINTER { + CC3KPrinter->println(F("Timed out using SmartConfig data")); + } + return false; + } + timeout += 10; + delay(10); + } + + delay(1000); + if (cc3000Bitset.test(CC3000BitSet::HasDHCP)) + { + mdnsAdvertiser(1, (char *) _deviceName, strlen(_deviceName)); + } + } + + return true; +} + +/**************************************************************************/ +/*! + @brief Prints a hexadecimal value in plain characters + + @param data Pointer to the byte data + @param numBytes Data length in bytes +*/ +/**************************************************************************/ +void Adafruit_CC3000::printHex(const byte * data, const uint32_t numBytes) +{ + if (CC3KPrinter == 0) return; + + uint32_t szPos; + for (szPos=0; szPos < numBytes; szPos++) + { + CC3KPrinter->print(F("0x")); + // Append leading 0 for small values + if (data[szPos] <= 0xF) + CC3KPrinter->print(F("0")); + CC3KPrinter->print(data[szPos], HEX); + if ((numBytes > 1) && (szPos != numBytes - 1)) + { + CC3KPrinter->print(' '); + } + } + CC3KPrinter->println(); +} + +/**************************************************************************/ +/*! + @brief Prints a hexadecimal value in plain characters, along with + the char equivalents in the following format + + 00 00 00 00 00 00 ...... + + @param data Pointer to the byte data + @param numBytes Data length in bytes +*/ +/**************************************************************************/ +void Adafruit_CC3000::printHexChar(const byte * data, const uint32_t numBytes) +{ + if (CC3KPrinter == 0) return; + + uint32_t szPos; + for (szPos=0; szPos < numBytes; szPos++) + { + // Append leading 0 for small values + if (data[szPos] <= 0xF) + CC3KPrinter->print('0'); + CC3KPrinter->print(data[szPos], HEX); + if ((numBytes > 1) && (szPos != numBytes - 1)) + { + CC3KPrinter->print(' '); + } + } + CC3KPrinter->print(" "); + for (szPos=0; szPos < numBytes; szPos++) + { + if (data[szPos] <= 0x1F) + CC3KPrinter->print('.'); + else + CC3KPrinter->print(data[szPos]); + } + CC3KPrinter->println(); +} + +/**************************************************************************/ +/*! + @brief Helper function to display an IP address with dots +*/ +/**************************************************************************/ + +void Adafruit_CC3000::printIPdots(uint32_t ip) { + if (CC3KPrinter == 0) return; + CC3KPrinter->print((uint8_t)(ip)); + CC3KPrinter->print('.'); + CC3KPrinter->print((uint8_t)(ip >> 8)); + CC3KPrinter->print('.'); + CC3KPrinter->print((uint8_t)(ip >> 16)); + CC3KPrinter->print('.'); + CC3KPrinter->print((uint8_t)(ip >> 24)); +} + +/**************************************************************************/ +/*! + @brief Helper function to display an IP address with dots, printing + the bytes in reverse order +*/ +/**************************************************************************/ +void Adafruit_CC3000::printIPdotsRev(uint32_t ip) { + if (CC3KPrinter == 0) return; + CC3KPrinter->print((uint8_t)(ip >> 24)); + CC3KPrinter->print('.'); + CC3KPrinter->print((uint8_t)(ip >> 16)); + CC3KPrinter->print('.'); + CC3KPrinter->print((uint8_t)(ip >> 8)); + CC3KPrinter->print('.'); + CC3KPrinter->print((uint8_t)(ip)); +} + +/**************************************************************************/ +/*! + @brief Helper function to convert four bytes to a U32 IP value +*/ +/**************************************************************************/ +uint32_t Adafruit_CC3000::IP2U32(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { + uint32_t ip = a; + ip <<= 8; + ip |= b; + ip <<= 8; + ip |= c; + ip <<= 8; + ip |= d; + + return ip; +} + +/**************************************************************************/ +/*! + @brief Reboot CC3000 (stop then start) +*/ +/**************************************************************************/ +void Adafruit_CC3000::reboot(uint8_t patch) +{ + if (!_initialised) + { + return; + } + + wlan_stop(); + delay(5000); + wlan_start(patch); +} + +/**************************************************************************/ +/*! + @brief Stop CC3000 +*/ +/**************************************************************************/ +void Adafruit_CC3000::stop(void) +{ + if (!_initialised) + { + return; + } + + wlan_stop(); +} + +/**************************************************************************/ +/*! + @brief Disconnects from the network + + @returns False if an error occured! +*/ +/**************************************************************************/ +bool Adafruit_CC3000::disconnect(void) +{ + if (!_initialised) + { + return false; + } + + long retVal = wlan_disconnect(); + + return retVal != 0 ? false : true; +} + +/**************************************************************************/ +/*! + @brief Deletes all profiles stored in the CC3000 + + @returns False if an error occured! +*/ +/**************************************************************************/ +bool Adafruit_CC3000::deleteProfiles(void) +{ + if (!_initialised) + { + return false; + } + + CHECK_SUCCESS(wlan_ioctl_set_connection_policy(0, 0, 0), + "deleteProfiles connection failure", false); + CHECK_SUCCESS(wlan_ioctl_del_profile(255), + "Failed deleting profiles", false); + + return true; +} + +/**************************************************************************/ +/*! + @brief Reads the MAC address + + @param address Buffer to hold the 6 byte Mac Address + + @returns False if an error occured! +*/ +/**************************************************************************/ +bool Adafruit_CC3000::getMacAddress(uint8_t address[6]) +{ + if (!_initialised) + { + return false; + } + + CHECK_SUCCESS(nvmem_read(NVMEM_MAC_FILEID, 6, 0, address), + "Failed reading MAC address!", false); + + return true; +} + +/**************************************************************************/ +/*! + @brief Sets a new MAC address + + @param address Buffer pointing to the 6 byte Mac Address + + @returns False if an error occured! +*/ +/**************************************************************************/ +bool Adafruit_CC3000::setMacAddress(uint8_t address[6]) +{ + if (!_initialised) + { + return false; + } + + if (address[0] == 0) + { + return false; + } + + CHECK_SUCCESS(netapp_config_mac_adrress(address), + "Failed setting MAC address!", false); + + wlan_stop(); + delay(200); + wlan_start(0); + + return true; +} + +/**************************************************************************/ +/*! + @brief Set the CC3000 to use a static IP address when it's connected + to the network. Use the cc3000.IP2U32 function to specify the + IP, subnet mask (typically 255.255.255.0), default gateway + (typically 192.168.1.1), and DNS server (can use Google's DNS + of 8.8.8.8 or 8.8.4.4). Note that the static IP configuration + will be saved in the CC3000's non-volatile storage and reused + on next reconnect. This means you only need to call this once + and the CC3000 will remember the setting forever. To revert + back to use DHCP, call the cc3000.setDHCP function. + + @param ip IP address + @param subnetmask Subnet mask + @param defaultGateway Default gateway + @param dnsServer DNS server + + @returns False if an error occurred, true if successfully set. +*/ +/**************************************************************************/ +bool Adafruit_CC3000::setStaticIPAddress(uint32_t ip, uint32_t subnetMask, uint32_t defaultGateway, uint32_t dnsServer) +{ + // Reverse order of bytes in parameters so IP2U32 packed values can be used with the netapp_dhcp function. + ip = (ip >> 24) | ((ip >> 8) & 0x0000FF00L) | ((ip << 8) & 0x00FF0000L) | (ip << 24); + subnetMask = (subnetMask >> 24) | ((subnetMask >> 8) & 0x0000FF00L) | ((subnetMask << 8) & 0x00FF0000L) | (subnetMask << 24); + defaultGateway = (defaultGateway >> 24) | ((defaultGateway >> 8) & 0x0000FF00L) | ((defaultGateway << 8) & 0x00FF0000L) | (defaultGateway << 24); + dnsServer = (dnsServer >> 24) | ((dnsServer >> 8) & 0x0000FF00L) | ((dnsServer << 8) & 0x00FF0000L) | (dnsServer << 24); + // Update DHCP state with specified values. + if (netapp_dhcp(&ip, &subnetMask, &defaultGateway, &dnsServer) != 0) { + return false; + } + // Reset CC3000 to use modified setting. + wlan_stop(); + delay(200); + wlan_start(0); + return true; +} + +/**************************************************************************/ +/*! + @brief Set the CC3000 to use request an IP and network configuration + using DHCP. Note that this DHCP state will be saved in the + CC3000's non-volatile storage and reused on next reconnect. + This means you only need to call this once and the CC3000 will + remember the setting forever. To switch to use a static IP, + call the cc3000.setStaticIPAddress function. + + @returns False if an error occurred, true if successfully set. +*/ +/**************************************************************************/ +bool Adafruit_CC3000::setDHCP() +{ + return setStaticIPAddress(0,0,0,0); +} + +/**************************************************************************/ +/*! + @brief Reads the current IP address + + @returns False if an error occured! +*/ +/**************************************************************************/ +bool Adafruit_CC3000::getIPAddress(uint32_t *retip, uint32_t *netmask, uint32_t *gateway, uint32_t *dhcpserv, uint32_t *dnsserv) +{ + if (!_initialised) return false; + if (!cc3000Bitset.test(CC3000BitSet::IsConnected)) return false; + if (!cc3000Bitset.test(CC3000BitSet::HasDHCP)) return false; + + tNetappIpconfigRetArgs ipconfig; + netapp_ipconfig(&ipconfig); + + /* If byte 1 is 0 we don't have a valid address */ + if (ipconfig.aucIP[3] == 0) return false; + + memcpy(retip, ipconfig.aucIP, 4); + memcpy(netmask, ipconfig.aucSubnetMask, 4); + memcpy(gateway, ipconfig.aucDefaultGateway, 4); + memcpy(dhcpserv, ipconfig.aucDHCPServer, 4); + memcpy(dnsserv, ipconfig.aucDNSServer, 4); + + return true; +} + +/**************************************************************************/ +/*! + @brief Gets the two byte ID for the firmware patch version + + @note This command isn't available when the CC3000 is configured + in 'CC3000_TINY_DRIVER' mode + + @returns False if an error occured! +*/ +/**************************************************************************/ +#ifndef CC3000_TINY_DRIVER +bool Adafruit_CC3000::getFirmwareVersion(uint8_t *major, uint8_t *minor) +{ + uint8_t fwpReturn[2]; + + if (!_initialised) + { + return false; + } + + CHECK_SUCCESS(nvmem_read_sp_version(fwpReturn), + "Unable to read the firmware version", false); + + *major = fwpReturn[0]; + *minor = fwpReturn[1]; + + return true; +} +#endif + +/**************************************************************************/ +/*! + @Brief Prints out the current status flag of the CC3000 + + @note This command isn't available when the CC3000 is configured + in 'CC3000_TINY_DRIVER' mode +*/ +/**************************************************************************/ +#ifndef CC3000_TINY_DRIVER +status_t Adafruit_CC3000::getStatus() +{ + if (!_initialised) + { + return STATUS_DISCONNECTED; + } + + long results = wlan_ioctl_statusget(); + + switch(results) + { + case 1: + return STATUS_SCANNING; + break; + case 2: + return STATUS_CONNECTING; + break; + case 3: + return STATUS_CONNECTED; + break; + case 0: + default: + return STATUS_DISCONNECTED; + break; + } +} +#endif + +/**************************************************************************/ +/*! + @brief Calls listSSIDs and then displays the results of the SSID scan + + For the moment we only list these via CC3KPrinter->print since + this can consume a lot of memory passing all the data + back with a buffer + + @note This command isn't available when the CC3000 is configured + in 'CC3000_TINY_DRIVER' mode + + @returns False if an error occured! +*/ +/**************************************************************************/ +#ifndef CC3000_TINY_DRIVER + +ResultStruct_t SSIDScanResultBuff; + + +uint16_t Adafruit_CC3000::startSSIDscan() { + uint16_t index = 0; + + if (!_initialised) + { + return false; + } + + // Setup a 4 second SSID scan + if (!scanSSIDs(4000)) + { + // Oops ... SSID scan failed + return false; + } + + // Wait for results + delay(4500); + + CHECK_SUCCESS(wlan_ioctl_get_scan_results(0, (uint8_t* ) &SSIDScanResultBuff), + "SSID scan failed!", false); + + index = SSIDScanResultBuff.num_networks; + return index; +} + +void Adafruit_CC3000::stopSSIDscan(void) { + + // Stop scanning + scanSSIDs(0); +} + +uint8_t Adafruit_CC3000::getNextSSID(uint8_t *rssi, uint8_t *secMode, char *ssidname) { + uint8_t valid = (SSIDScanResultBuff.rssiByte & (~0xFE)); + *rssi = (SSIDScanResultBuff.rssiByte >> 1); + *secMode = (SSIDScanResultBuff.Sec_ssidLen & (~0xFC)); + uint8_t ssidLen = (SSIDScanResultBuff.Sec_ssidLen >> 2); + strncpy(ssidname, (char *)SSIDScanResultBuff.ssid_name, ssidLen); + ssidname[ssidLen] = 0; + + CHECK_SUCCESS(wlan_ioctl_get_scan_results(0, (uint8_t* ) &SSIDScanResultBuff), + "Problem with the SSID scan results", false); + return valid; +} +#endif + +/**************************************************************************/ +/*! + @brief Starts the smart config connection process + + @note This command isn't available when the CC3000 is configured + in 'CC3000_TINY_DRIVER' mode + + @returns False if an error occured! +*/ +/**************************************************************************/ +#ifndef CC3000_TINY_DRIVER +bool Adafruit_CC3000::startSmartConfig(const char *_deviceName, const char *smartConfigKey) +{ + bool enableAES = smartConfigKey != NULL; + cc3000Bitset.clear(); + + uint32_t timeout = 0; + + if (!_initialised) { + return false; + } + + // Reset all the previous configurations + CHECK_SUCCESS(wlan_ioctl_set_connection_policy(WIFI_DISABLE, WIFI_DISABLE, WIFI_DISABLE), + "Failed setting the connection policy", false); + + // Delete existing profile data + CHECK_SUCCESS(wlan_ioctl_del_profile(255), + "Failed deleting existing profiles", false); + + // CC3KPrinter->println("Disconnecting"); + // Wait until CC3000 is disconnected + while (cc3000Bitset.test(CC3000BitSet::IsConnected)) { + cc3k_int_poll(); + CHECK_SUCCESS(wlan_disconnect(), + "Failed to disconnect from AP", false); + delay(10); + hci_unsolicited_event_handler(); + } + + // Reset the CC3000 + wlan_stop(); + delay(1000); + wlan_start(0); + + // create new entry for AES encryption key + CHECK_SUCCESS(nvmem_create_entry(NVMEM_AES128_KEY_FILEID,16), + "Failed create NVMEM entry", false); + + if (enableAES) + { + // write AES key to NVMEM + CHECK_SUCCESS(aes_write_key((unsigned char *)(smartConfigKey)), + "Failed writing AES key", false); + } + //CC3KPrinter->println("Set prefix"); + // Wait until CC3000 is disconnected + CHECK_SUCCESS(wlan_smart_config_set_prefix((char *)&_cc3000_prefix), + "Failed setting the SmartConfig prefix", false); + + //CC3KPrinter->println("Start config"); + // Start the SmartConfig start process + CHECK_SUCCESS(wlan_smart_config_start(enableAES), + "Failed starting smart config", false); + + // Wait for smart config process complete (event in CC3000_UsynchCallback) + while (!cc3000Bitset.test(CC3000BitSet::IsSmartConfigFinished)) + { + cc3k_int_poll(); + // waiting here for event SIMPLE_CONFIG_DONE + timeout+=10; + if (timeout > 60000) // ~60s + { + return false; + } + delay(10); // ms + // CC3KPrinter->print('.'); + } + + CHECK_PRINTER { + CC3KPrinter->println(F("Got smart config data")); + } + if (enableAES) { + CHECK_SUCCESS(wlan_smart_config_process(), + "wlan_smart_config_process failed", + false); + } + + // ****************************************************** + // Decrypt configuration information and add profile + // ToDo: This is causing stack overflow ... investigate + // CHECK_SUCCESS(wlan_smart_config_process(), + // "Smart config failed", false); + // ****************************************************** + + // Connect automatically to the AP specified in smart config settings + CHECK_SUCCESS(wlan_ioctl_set_connection_policy(WIFI_DISABLE, WIFI_DISABLE, WIFI_ENABLE), + "Failed setting connection policy", false); + + // Reset the CC3000 + wlan_stop(); + delay(1000); + wlan_start(0); + + // Mask out all non-required events + CHECK_SUCCESS(wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE | + HCI_EVNT_WLAN_UNSOL_INIT + //HCI_EVNT_WLAN_ASYNC_PING_REPORT | + //HCI_EVNT_WLAN_TX_COMPLETE + ), + "Failed setting event mask", false); + + // Wait for a connection + timeout = 0; + while(!cc3000Bitset.test(CC3000BitSet::IsConnected)) + { + cc3k_int_poll(); + if(timeout > WLAN_CONNECT_TIMEOUT) // ~20s + { + CHECK_PRINTER { + CC3KPrinter->println(F("Timed out waiting to connect")); + } + return false; + } + timeout += 10; + delay(10); + } + + delay(1000); + if (cc3000Bitset.test(CC3000BitSet::HasDHCP)) + { + mdnsAdvertiser(1, (char *) _deviceName, strlen(_deviceName)); + } + + return true; +} + +#endif + +/**************************************************************************/ +/*! + Connect to an unsecured SSID/AP(security) + + @param ssid The named of the AP to connect to (max 32 chars) + @param ssidLen The size of the ssid name + + @returns False if an error occured! +*/ +/**************************************************************************/ +bool Adafruit_CC3000::connectOpen(const char *ssid) +{ + if (!_initialised) { + return false; + } + + #ifndef CC3000_TINY_DRIVER + CHECK_SUCCESS(wlan_ioctl_set_connection_policy(0, 0, 0), + "Failed to set connection policy", false); + delay(500); + CHECK_SUCCESS(wlan_connect(WLAN_SEC_UNSEC, + (const char*)ssid, strlen(ssid), + 0 ,NULL,0), + "SSID connection failed", false); + #else + wlan_connect(ssid, ssidLen); + #endif + + return true; +} + +//***************************************************************************** +// +//! CC3000_UsynchCallback +//! +//! @param lEventType Event type +//! @param data +//! @param length +//! +//! @return none +//! +//! @brief The function handles asynchronous events that come from CC3000 +//! device and operates a led for indicate +// +//***************************************************************************** +void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length) +{ + if (lEventType == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE) + { + cc3000Bitset.set(CC3000BitSet::IsSmartConfigFinished); + } + + if (lEventType == HCI_EVNT_WLAN_UNSOL_CONNECT) + { + cc3000Bitset.set(CC3000BitSet::IsConnected); + } + + if (lEventType == HCI_EVNT_WLAN_UNSOL_DISCONNECT) + { + cc3000Bitset.reset(CC3000BitSet::IsConnected | CC3000BitSet::HasDHCP); + } + + if (lEventType == HCI_EVNT_WLAN_UNSOL_DHCP) + { + cc3000Bitset.set(CC3000BitSet::HasDHCP); + } + + if (lEventType == HCI_EVENT_CC3000_CAN_SHUT_DOWN) + { + cc3000Bitset.set(CC3000BitSet::OkToShutDown); + } + + if (lEventType == HCI_EVNT_WLAN_ASYNC_PING_REPORT) + { + //PRINT_F("CC3000: Ping report\n\r"); + pingReportnum++; + memcpy(&pingReport, data, length); + } + + if (lEventType == HCI_EVNT_BSD_TCP_CLOSE_WAIT) { + uint8_t socketnum; + socketnum = data[0]; + //PRINT_F("TCP Close wait #"); printDec(socketnum); + if (socketnum < MAX_SOCKETS) + closed_sockets[socketnum] = true; + } +} + +/**************************************************************************/ +/*! + Connect to an SSID/AP(security) + + @note This command isn't available when the CC3000 is configured + in 'CC3000_TINY_DRIVER' mode + + @returns False if an error occured! +*/ +/**************************************************************************/ +#ifndef CC3000_TINY_DRIVER +bool Adafruit_CC3000::connectSecure(const char *ssid, const char *key, int32_t secMode) +{ + if (!_initialised) { + return false; + } + + if ( (secMode < 0) || (secMode > 3)) { + CHECK_PRINTER { + CC3KPrinter->println(F("Security mode must be between 0 and 3")); + } + return false; + } + + if (strlen(ssid) > MAXSSID) { + CHECK_PRINTER { + CC3KPrinter->print(F("SSID length must be < ")); + CC3KPrinter->println(MAXSSID); + } + return false; + } + + if (strlen(key) > MAXLENGTHKEY) { + CHECK_PRINTER { + CC3KPrinter->print(F("Key length must be < ")); + CC3KPrinter->println(MAXLENGTHKEY); + } + return false; + } + + CHECK_SUCCESS(wlan_ioctl_set_connection_policy(0, 0, 0), + "Failed setting the connection policy", + false); + delay(500); + CHECK_SUCCESS(wlan_connect(secMode, (char *)ssid, strlen(ssid), + NULL, + (unsigned char *)key, strlen(key)), + "SSID connection failed", false); + + /* Wait for 'HCI_EVNT_WLAN_UNSOL_CONNECT' in CC3000_UsynchCallback */ + + return true; +} +#endif + +// Connect with timeout +bool Adafruit_CC3000::connectToAP(const char *ssid, const char *key, uint8_t secmode, uint8_t attempts) { + if (!_initialised) { + return false; + } + + int16_t timer; + + // If attempts is zero interpret that as no limit on number of retries. + bool retryForever = attempts == 0; + + do { + // Stop if the max number of attempts have been tried. + if (!retryForever) { + if (attempts == 0) { + return checkConnected(); + } + attempts -= 1; + } + + cc3k_int_poll(); + /* MEME: not sure why this is absolutely required but the cc3k freaks + if you dont. maybe bootup delay? */ + // Setup a 4 second SSID scan + scanSSIDs(4000); + // Wait for results + delay(4500); + scanSSIDs(0); + + /* Attempt to connect to an access point */ + CHECK_PRINTER { + CC3KPrinter->print(F("\n\rConnecting to ")); + CC3KPrinter->print(ssid); + CC3KPrinter->print(F("...")); + } + if ((secmode == 0) || (strlen(key) == 0)) { + /* Connect to an unsecured network */ + if (! connectOpen(ssid)) { + CHECK_PRINTER { + CC3KPrinter->println(F("Failed!")); + } + continue; + } + } else { + /* NOTE: Secure connections are not available in 'Tiny' mode! */ +#ifndef CC3000_TINY_DRIVER + /* Connect to a secure network using WPA2, etc */ + if (! connectSecure(ssid, key, secmode)) { + CHECK_PRINTER { + CC3KPrinter->println(F("Failed!")); + } + continue; + } +#endif + } + + timer = WLAN_CONNECT_TIMEOUT; + + /* Wait around a bit for the async connected signal to arrive or timeout */ + CHECK_PRINTER { + CC3KPrinter->print(F("Waiting to connect...")); + } + while ((timer > 0) && !checkConnected()) + { + cc3k_int_poll(); + delay(10); + timer -= 10; + } + if (timer <= 0) { + CHECK_PRINTER { + CC3KPrinter->println(F("Timed out!")); + } + } + } while (!checkConnected()); + + return true; +} + + +#ifndef CC3000_TINY_DRIVER +uint16_t Adafruit_CC3000::ping(uint32_t ip, uint8_t attempts, uint16_t timeout, uint8_t size) { + if (!_initialised) return 0; + if (!cc3000Bitset.test(CC3000BitSet::IsConnected)) return 0; + if (!cc3000Bitset.test(CC3000BitSet::HasDHCP)) return 0; + + uint32_t revIP = (ip >> 24) | ((ip >> 8) & 0xFF00) | ((ip & 0xFF00) << 8) | (ip << 24); + + pingReportnum = 0; + pingReport.packets_received = 0; + + //if (CC3KPrinter != 0) { + // CC3KPrinter->print(F("Pinging ")); printIPdots(revIP); CC3KPrinter->print(" "); + // CC3KPrinter->print(attempts); CC3KPrinter->println(F(" times")); + //} + + netapp_ping_send(&revIP, attempts, size, timeout); + delay(timeout*attempts*2); + //if (CC3KPrinter != 0) CC3KPrinter->println(F("Req report")); + //netapp_ping_report(); + //if (CC3KPrinter != 0) { CC3KPrinter->print(F("Reports: ")); CC3KPrinter->println(pingReportnum); } + + if (pingReportnum) { + /* + if (CC3KPrinter != 0) { + CC3KPrinter->print(F("Sent: ")); CC3KPrinter->println(pingReport.packets_sent); + CC3KPrinter->print(F("Recv: ")); CC3KPrinter->println(pingReport.packets_received); + CC3KPrinter->print(F("MinT: ")); CC3KPrinter->println(pingReport.min_round_time); + CC3KPrinter->print(F("MaxT: ")); CC3KPrinter->println(pingReport.max_round_time); + CC3KPrinter->print(F("AvgT: ")); CC3KPrinter->println(pingReport.avg_round_time); + } + //*/ + return pingReport.packets_received; + } else { + return 0; + } +} + +#endif + +#ifndef CC3000_TINY_DRIVER +uint16_t Adafruit_CC3000::getHostByName(char *hostname, uint32_t *ip) { + if (!_initialised) return 0; + if (!cc3000Bitset.test(CC3000BitSet::IsConnected)) return 0; + if (!cc3000Bitset.test(CC3000BitSet::HasDHCP)) return 0; + + int16_t r = gethostbyname(hostname, strlen(hostname), ip); + //if (CC3KPrinter != 0) { CC3KPrinter->print("Errno: "); CC3KPrinter->println(r); } + return r; +} +#endif + +/**************************************************************************/ +/*! + Checks if the device is connected or not + + @returns True if connected +*/ +/**************************************************************************/ +bool Adafruit_CC3000::checkConnected(void) +{ + return cc3000Bitset.test(CC3000BitSet::IsConnected); +} + +/**************************************************************************/ +/*! + Checks if the DHCP process is complete or not + + @returns True if DHCP process is complete (IP address assigned) +*/ +/**************************************************************************/ +bool Adafruit_CC3000::checkDHCP(void) +{ + return cc3000Bitset.test(CC3000BitSet::HasDHCP); +} + +/**************************************************************************/ +/*! + Checks if the smart config process is finished or not + + @returns True if smart config is finished +*/ +/**************************************************************************/ +bool Adafruit_CC3000::checkSmartConfigFinished(void) +{ + return cc3000Bitset.test(CC3000BitSet::IsSmartConfigFinished); +} + +#ifndef CC3000_TINY_DRIVER +/**************************************************************************/ +/*! + Gets the IP config settings (if connected) + + @returns True if smart config is finished +*/ +/**************************************************************************/ +bool Adafruit_CC3000::getIPConfig(tNetappIpconfigRetArgs *ipConfig) +{ + if (!_initialised) return false; + if (!cc3000Bitset.test(CC3000BitSet::IsConnected)) return false; + if (!cc3000Bitset.test(CC3000BitSet::HasDHCP)) return false; + + netapp_ipconfig(ipConfig); + return true; +} +#endif + + +/**************************************************************************/ +/*! + @brief Quick socket test to pull contents from the web +*/ +/**************************************************************************/ +Adafruit_CC3000_Client Adafruit_CC3000::connectTCP(uint32_t destIP, uint16_t destPort) +{ + sockaddr socketAddress; + int32_t tcp_socket; + + // Create the socket(s) + //if (CC3KPrinter != 0) CC3KPrinter->print(F("Creating socket ... ")); + tcp_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (-1 == tcp_socket) + { + CHECK_PRINTER { + CC3KPrinter->println(F("Failed to open socket")); + } + return Adafruit_CC3000_Client(); + } + //CC3KPrinter->print(F("DONE (socket ")); CC3KPrinter->print(tcp_socket); CC3KPrinter->println(F(")")); + + closed_sockets[tcp_socket] = false; // Clear any previous closed event + + // Try to open the socket + memset(&socketAddress, 0x00, sizeof(socketAddress)); + socketAddress.sa_family = AF_INET; + socketAddress.sa_data[0] = (destPort & 0xFF00) >> 8; // Set the Port Number + socketAddress.sa_data[1] = (destPort & 0x00FF); + socketAddress.sa_data[2] = destIP >> 24; + socketAddress.sa_data[3] = destIP >> 16; + socketAddress.sa_data[4] = destIP >> 8; + socketAddress.sa_data[5] = destIP; + + CHECK_PRINTER { + CC3KPrinter->print(F("\n\rConnect to ")); + printIPdotsRev(destIP); + CC3KPrinter->print(':'); + CC3KPrinter->println(destPort); + } + + //printHex((byte *)&socketAddress, sizeof(socketAddress)); + //if (CC3KPrinter != 0) CC3KPrinter->print(F("Connecting socket ... ")); + if (-1 == connect(tcp_socket, &socketAddress, sizeof(socketAddress))) + { + CHECK_PRINTER { + CC3KPrinter->println(F("Connection error")); + } + closesocket(tcp_socket); + return Adafruit_CC3000_Client(); + } + //if (CC3KPrinter != 0) CC3KPrinter->println(F("DONE")); + return Adafruit_CC3000_Client(tcp_socket); +} + + +Adafruit_CC3000_Client Adafruit_CC3000::connectUDP(uint32_t destIP, uint16_t destPort) +{ + sockaddr socketAddress; + int32_t udp_socket; + + // Create the socket(s) + // socket = SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW + // protocol = IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW + //if (CC3KPrinter != 0) CC3KPrinter->print(F("Creating socket... ")); + udp_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (-1 == udp_socket) + { + CHECK_PRINTER { + CC3KPrinter->println(F("Failed to open socket")); + } + return Adafruit_CC3000_Client(); + } + //if (CC3KPrinter != 0) { CC3KPrinter->print(F("DONE (socket ")); CC3KPrinter->print(udp_socket); CC3KPrinter->println(F(")")); } + + // Try to open the socket + memset(&socketAddress, 0x00, sizeof(socketAddress)); + socketAddress.sa_family = AF_INET; + socketAddress.sa_data[0] = (destPort & 0xFF00) >> 8; // Set the Port Number + socketAddress.sa_data[1] = (destPort & 0x00FF); + socketAddress.sa_data[2] = destIP >> 24; + socketAddress.sa_data[3] = destIP >> 16; + socketAddress.sa_data[4] = destIP >> 8; + socketAddress.sa_data[5] = destIP; + + CHECK_PRINTER { + CC3KPrinter->print(F("Connect to ")); + printIPdotsRev(destIP); + CC3KPrinter->print(':'); + CC3KPrinter->println(destPort); + } + + //printHex((byte *)&socketAddress, sizeof(socketAddress)); + if (-1 == connect(udp_socket, &socketAddress, sizeof(socketAddress))) + { + CHECK_PRINTER { + CC3KPrinter->println(F("Connection error")); + } + closesocket(udp_socket); + return Adafruit_CC3000_Client(); + } + + return Adafruit_CC3000_Client(udp_socket); +} + + +/**********************************************************************/ +Adafruit_CC3000_Client::Adafruit_CC3000_Client(void) { + _socket = -1; +} + +Adafruit_CC3000_Client::Adafruit_CC3000_Client(uint16_t s) { + _socket = s; + bufsiz = 0; + _rx_buf_idx = 0; +} + +Adafruit_CC3000_Client::Adafruit_CC3000_Client(const Adafruit_CC3000_Client& copy) { + // Copy all the members to construct this client. + _socket = copy._socket; + bufsiz = copy.bufsiz; + _rx_buf_idx = copy._rx_buf_idx; + memcpy(_rx_buf, copy._rx_buf, RXBUFFERSIZE); +} + +void Adafruit_CC3000_Client::operator=(const Adafruit_CC3000_Client& other) { + // Copy all the members to assign a new value to this client. + _socket = other._socket; + bufsiz = other.bufsiz; + _rx_buf_idx = other._rx_buf_idx; + memcpy(_rx_buf, other._rx_buf, RXBUFFERSIZE); +} + +bool Adafruit_CC3000_Client::connected(void) { + if (_socket < 0) return false; + + if (! available() && closed_sockets[_socket] == true) { + //if (CC3KPrinter != 0) CC3KPrinter->println("No more data, and closed!"); + closesocket(_socket); + closed_sockets[_socket] = false; + _socket = -1; + return false; + } + + else return true; +} + +int16_t Adafruit_CC3000_Client::write(const void *buf, uint16_t len, uint32_t flags) +{ + return send(_socket, buf, len, flags); +} + + +size_t Adafruit_CC3000_Client::write(uint8_t c) +{ + int32_t r; + r = send(_socket, &c, 1, 0); + if ( r < 0 ) return 0; + return r; +} + +size_t Adafruit_CC3000_Client::fastrprint(const __FlashStringHelper *ifsh) +{ + char _tx_buf[TXBUFFERSIZE]; + uint8_t idx = 0; + + const char PROGMEM *p = (const char PROGMEM *)ifsh; + size_t n = 0; + while (1) { + unsigned char c = pgm_read_byte(p++); + if (c == 0) break; + _tx_buf[idx] = c; + idx++; + if (idx >= TXBUFFERSIZE) { + // lets send it! + n += send(_socket, _tx_buf, TXBUFFERSIZE, 0); + idx = 0; + } + } + if (idx > 0) { + // Send any remaining data in the transmit buffer. + n += send(_socket, _tx_buf, idx, 0); + } + + return n; +} + +size_t Adafruit_CC3000_Client::fastrprintln(const __FlashStringHelper *ifsh) +{ + size_t r = 0; + r = fastrprint(ifsh); + r+= fastrprint(F("\r\n")); + return r; +} + +size_t Adafruit_CC3000_Client::fastrprintln(const char *str) +{ + size_t r = 0; + size_t len = strlen(str); + if (len > 0) { + if ((r = write(str, len, 0)) <= 0) return 0; + } + if ((r += write("\r\n", 2, 0)) <= 0) return 0; // meme fix + return r; +} + +size_t Adafruit_CC3000_Client::fastrprint(const char *str) +{ + size_t len = strlen(str); + if (len > 0) { + return write(str, len, 0); + } + else { + return 0; + } +} + +size_t Adafruit_CC3000_Client::fastrprint(char *str) +{ + size_t len = strlen(str); + if (len > 0) { + return write(str, len, 0); + } + else { + return 0; + } +} + +size_t Adafruit_CC3000_Client::fastrprintln(char *str) { + size_t r = 0; + r = fastrprint(str); + r+= fastrprint(F("\r\n")); + return r; +} + +int16_t Adafruit_CC3000_Client::read(void *buf, uint16_t len, uint32_t flags) +{ + return recv(_socket, buf, len, flags); + +} + +int32_t Adafruit_CC3000_Client::close(void) { + int32_t x = closesocket(_socket); + _socket = -1; + return x; +} + +uint8_t Adafruit_CC3000_Client::read(void) +{ + while ((bufsiz <= 0) || (bufsiz == _rx_buf_idx)) { + cc3k_int_poll(); + // buffer in some more data + bufsiz = recv(_socket, _rx_buf, sizeof(_rx_buf), 0); + if (bufsiz == -57) { + close(); + return 0; + } + //if (CC3KPrinter != 0) { CC3KPrinter->println("Read "); CC3KPrinter->print(bufsiz); CC3KPrinter->println(" bytes"); } + _rx_buf_idx = 0; + } + uint8_t ret = _rx_buf[_rx_buf_idx]; + _rx_buf_idx++; + //if (CC3KPrinter != 0) { CC3KPrinter->print("("); CC3KPrinter->write(ret); CC3KPrinter->print(")"); } + return ret; +} + +uint8_t Adafruit_CC3000_Client::available(void) { + // not open! + if (_socket < 0) return 0; + + if ((bufsiz > 0) // we have some data in the internal buffer + && (_rx_buf_idx < bufsiz)) { // we havent already spit it all out + return (bufsiz - _rx_buf_idx); + } + + // do a select() call on this socket + timeval timeout; + fd_set fd_read; + + memset(&fd_read, 0, sizeof(fd_read)); + FD_SET(_socket, &fd_read); + + timeout.tv_sec = 0; + timeout.tv_usec = 5000; // 5 millisec + + int16_t s = select(_socket+1, &fd_read, NULL, NULL, &timeout); + //if (CC3KPrinter != 0) } CC3KPrinter->print(F("Select: ")); CC3KPrinter->println(s); } + if (s == 1) return 1; // some data is available to read + else return 0; // no data is available +} + +void Adafruit_CC3000::setPrinter(Print* p) { + CC3KPrinter = p; +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000.h new file mode 100755 index 0000000000..a0079fad07 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000.h @@ -0,0 +1,179 @@ +/**************************************************************************/ +/*! + @file Adafruit_CC3000.h + @author KTOWN (Kevin Townsend for Adafruit Industries) + @license BSD (see license.txt) + + This is a library for the Adafruit CC3000 WiFi breakout board + This library works with the Adafruit CC3000 breakout + ----> https://www.adafruit.com/products/1469 + + Check out the links above for our tutorials and wiring diagrams + These chips use SPI to communicate. + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! +*/ +/**************************************************************************/ + +#ifndef ADAFRUIT_CC3000_H +#define ADAFRUIT_CC3000_H + +#if ARDUINO >= 100 + #include "Arduino.h" +#else + #include "WProgram.h" +#endif +#include "utility/cc3000_common.h" +#include "utility/wlan.h" +#include "utility/netapp.h" +#include "ccspi.h" + +#if defined(__arm__) && defined(__SAM3X8E__) // Arduino Due + #define SPI_CLOCK_DIVIDER 6 // used to set the speed for the SPI bus; 6 == 14 Mhz on the Arduino Due +#else + #define SPI_CLOCK_DIVIDER SPI_CLOCK_DIV2 // Don't set this to a slower speed (i.e. larger div value) + // or communication will be flakey on 16mhz chips! +#endif + +//#define ENABLE_CC3K_PRINTER + +#ifdef ENABLE_CC3K_PRINTER +#define CHECK_PRINTER if(CC3KPrinter != 0) +#else +#define CHECK_PRINTER if(false) +#endif + +#define WLAN_CONNECT_TIMEOUT 10000 // how long to wait, in milliseconds +#define RXBUFFERSIZE 64 // how much to buffer on the incoming side +#define TXBUFFERSIZE 32 // how much to buffer on the outgoing side + +#define WIFI_ENABLE 1 +#define WIFI_DISABLE 0 +#define WIFI_STATUS_CONNECTED 1 + +typedef struct Result_Struct +{ + uint32_t num_networks; + uint32_t scan_status; + uint8_t rssiByte; + uint8_t Sec_ssidLen; + uint16_t time; + uint8_t ssid_name[32]; + uint8_t bssid[6]; +} ResultStruct_t; /**!ResultStruct_t : data struct to store SSID scan results */ + +/* Enum for wlan_ioctl_statusget results */ +typedef enum +{ + STATUS_DISCONNECTED = 0, + STATUS_SCANNING = 1, + STATUS_CONNECTING = 2, + STATUS_CONNECTED = 3 +} status_t; + +class Adafruit_CC3000; + +class Adafruit_CC3000_Client : public Print { + public: + Adafruit_CC3000_Client(uint16_t s); + Adafruit_CC3000_Client(void); + Adafruit_CC3000_Client(const Adafruit_CC3000_Client& copy); + void operator=(const Adafruit_CC3000_Client& other); + + // NOTE: If public functions below are added/modified/removed please make sure to update the + // Adafruit_CC3000_ClientRef class to match! + + bool connected(void); + size_t write(uint8_t c); + + size_t fastrprint(const char *str); + size_t fastrprintln(const char *str); + size_t fastrprint(char *str); + size_t fastrprintln(char *str); + size_t fastrprint(const __FlashStringHelper *ifsh); + size_t fastrprintln(const __FlashStringHelper *ifsh); + + int16_t write(const void *buf, uint16_t len, uint32_t flags = 0); + int16_t read(void *buf, uint16_t len, uint32_t flags = 0); + uint8_t read(void); + int32_t close(void); + uint8_t available(void); + + uint8_t _rx_buf[RXBUFFERSIZE], _rx_buf_idx; + int16_t bufsiz; + + private: + int16_t _socket; + +}; + +// Ugly but necessary to include the server header after the client is fully defined. +// A forward reference in the server header won't cut it because the server needs to contain +// instances of the client. The client definition above can be pulled into a separate +// header in a later change to make this cleaner. +#include "Adafruit_CC3000_Server.h" + +class Adafruit_CC3000 { + public: + Adafruit_CC3000(uint8_t csPin, uint8_t irqPin, uint8_t vbatPin, uint8_t spispeed = SPI_CLOCK_DIVIDER); + bool begin(uint8_t patchReq = 0, bool useSmartConfigData = false, const char *_deviceName = NULL); + void reboot(uint8_t patchReq = 0); + void stop(void); + bool disconnect(void); + bool deleteProfiles(void); + void printHex(const byte * data, const uint32_t numBytes); + void printHexChar(const byte * data, const uint32_t numBytes); + void printIPdots(uint32_t ip); + void printIPdotsRev(uint32_t ip); + uint32_t IP2U32(uint8_t a, uint8_t b, uint8_t c, uint8_t d); + bool getMacAddress(uint8_t address[6]); + bool setMacAddress(uint8_t address[6]); + bool setStaticIPAddress(uint32_t ip, uint32_t subnetMask, uint32_t defaultGateway, uint32_t dnsServer); + bool setDHCP(); + + bool connectToAP(const char *ssid, const char *key, uint8_t secmode, uint8_t attempts = 0); + bool connectSecure(const char *ssid, const char *key, int32_t secMode); + bool connectOpen(const char *ssid); + bool checkConnected(void); + bool checkDHCP(void); + bool getIPAddress(uint32_t *retip, uint32_t *netmask, uint32_t *gateway, uint32_t *dhcpserv, uint32_t *dnsserv); + + bool checkSmartConfigFinished(void); + + Adafruit_CC3000_Client connectTCP(uint32_t destIP, uint16_t destPort); + Adafruit_CC3000_Client connectUDP(uint32_t destIP, uint16_t destPort); + + #ifndef CC3000_TINY_DRIVER + bool getFirmwareVersion(uint8_t *major, uint8_t *minor); + status_t getStatus(void); + uint16_t startSSIDscan(void); + void stopSSIDscan(); + uint8_t getNextSSID(uint8_t *rssi, uint8_t *secMode, char *ssidname); + + bool listSSIDResults(void); + bool startSmartConfig(const char *_deviceName = NULL, const char *smartConfigKey = NULL); + + bool getIPConfig(tNetappIpconfigRetArgs *ipConfig); + + + uint16_t ping(uint32_t ip, uint8_t attempts=3, uint16_t timeout=500, uint8_t size=32); + uint16_t getHostByName(char *hostname, uint32_t *ip); + #endif + + /* Functions that aren't available with the tiny driver */ + #ifndef CC3000_TINY_DRIVER + bool scanSSIDs(uint32_t time); + #endif + + void setPrinter(Print*); + + private: + bool _initialised; + +}; + +extern Print* CC3KPrinter; + +#endif diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000_Server.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000_Server.cpp new file mode 100755 index 0000000000..e82d720e7b --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000_Server.cpp @@ -0,0 +1,221 @@ +/**************************************************************************/ +/*! + @file Adafruit_CC3000_Server.cpp + @author Tony DiCola (tony@tonydicola.com) + @license BSD (see license.txt) + + Adafruit CC3000 TCP server implementation based on the same interface as + the Arduino Ethernet library server class. + + See http://arduino.cc/en/Reference/Ethernet for documentation on the + Arduino Ethernet library and its server interface. + +*/ +/**************************************************************************/ +#include "Adafruit_CC3000_Server.h" + +#include "utility/socket.h" + +#define CC3K_PRINTLN_F(text) CHECK_PRINTER { if(CC3KPrinter != NULL) { CC3KPrinter->println(F(text)); } } + +#define HANDLE_NULL(client, value) { if (client == NULL) return value; } + + +/**************************************************************************/ +/* + Adafruit_CC3000_ClientRef implementation +*/ +/**************************************************************************/ + +Adafruit_CC3000_ClientRef::Adafruit_CC3000_ClientRef(Adafruit_CC3000_Client* client) + : _client(client) +{ } + +// Return true if the referenced client is connected. This is provided for +// compatibility with Ethernet library code. +Adafruit_CC3000_ClientRef::operator bool() { + return connected(); +} +// Below are wrappers around the public client functions. These hide the fact that users +// are dealing with a reference to a client instance and allow code to be written using +// value semantics like in the Ethernet library. +bool Adafruit_CC3000_ClientRef::connected(void) { + HANDLE_NULL(_client, false); + return _client->connected(); +} + +size_t Adafruit_CC3000_ClientRef::write(uint8_t c) { + HANDLE_NULL(_client, 0); + return _client->write(c); +} + +size_t Adafruit_CC3000_ClientRef::fastrprint(const char *str) { + HANDLE_NULL(_client, 0); + return _client->fastrprint(str); +} + +size_t Adafruit_CC3000_ClientRef::fastrprintln(const char *str) { + HANDLE_NULL(_client, 0); + return _client->fastrprintln(str); +} + +size_t Adafruit_CC3000_ClientRef::fastrprint(char *str) { + HANDLE_NULL(_client, 0); + return _client->fastrprint(str); +} + +size_t Adafruit_CC3000_ClientRef::fastrprintln(char *str) { + HANDLE_NULL(_client, 0); + return _client->fastrprintln(str); +} + +size_t Adafruit_CC3000_ClientRef::fastrprint(const __FlashStringHelper *ifsh) { + HANDLE_NULL(_client, 0); + return _client->fastrprint(ifsh); +} + +size_t Adafruit_CC3000_ClientRef::fastrprintln(const __FlashStringHelper *ifsh) { + HANDLE_NULL(_client, 0); + return _client->fastrprintln(ifsh); +} + +int16_t Adafruit_CC3000_ClientRef::write(const void *buf, uint16_t len, uint32_t flags) { + HANDLE_NULL(_client, 0); + return _client->write(buf, len, flags); +} + +int16_t Adafruit_CC3000_ClientRef::read(void *buf, uint16_t len, uint32_t flags) { + HANDLE_NULL(_client, 0); + return _client->read(buf, len, flags); +} + +uint8_t Adafruit_CC3000_ClientRef::read(void) { + HANDLE_NULL(_client, 0); + return _client->read(); +} + +int32_t Adafruit_CC3000_ClientRef::close(void) { + HANDLE_NULL(_client, 0); + return _client->close(); +} + +uint8_t Adafruit_CC3000_ClientRef::available(void) { + HANDLE_NULL(_client, 0); + return _client->available(); +} + + +/**************************************************************************/ +/* + Adafruit_CC3000_Server implementation +*/ +/**************************************************************************/ + +// Construct a TCP server to listen on the specified port. +Adafruit_CC3000_Server::Adafruit_CC3000_Server(uint16_t port) + : _port(port) + , _listenSocket(-1) +{ } + +// Return a reference to a client instance which has data available to read. +Adafruit_CC3000_ClientRef Adafruit_CC3000_Server::available() { + acceptNewConnections(); + // Find the first client which is ready to read and return it. + for (int i = 0; i < MAX_SERVER_CLIENTS; ++i) { + if (_clients[i].connected() && _clients[i].available() > 0) { + return Adafruit_CC3000_ClientRef(&_clients[i]); + } + } + // Couldn't find a client ready to read, so return a client that is not + // connected to signal no clients are available for reading (convention + // used by the Ethernet library). + return Adafruit_CC3000_ClientRef(NULL); +} + +// Initialize the server and start listening for connections. +void Adafruit_CC3000_Server::begin() { + // Set the CC3000 inactivity timeout to 0 (never timeout). This will ensure + // the CC3000 does not close the listening socket when it's idle for more than + // 60 seconds (the default timeout). See more information from: + // http://e2e.ti.com/support/low_power_rf/f/851/t/292664.aspx + unsigned long aucDHCP = 14400; + unsigned long aucARP = 3600; + unsigned long aucKeepalive = 30; + unsigned long aucInactivity = 0; + cc3k_int_poll(); + if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) { + CC3K_PRINTLN_F("Error setting inactivity timeout!"); + return; + } + // Create a TCP socket + cc3k_int_poll(); + int16_t soc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (soc < 0) { + CC3K_PRINTLN_F("Couldn't create listening socket!"); + return; + } + // Set the socket's accept call as non-blocking. + cc3k_int_poll(); + char arg = SOCK_ON; // nsd: looked in TI example code and they pass this as a 'short' in one example, and 'char' in two others. 'char' seems as likely work, and has no endianess issue + if (setsockopt(soc, SOL_SOCKET, SOCKOPT_ACCEPT_NONBLOCK, &arg, sizeof(arg)) < 0) { + CC3K_PRINTLN_F("Couldn't set socket as non-blocking!"); + return; + } + // Bind the socket to a TCP address. + sockaddr_in address; + address.sin_family = AF_INET; + address.sin_addr.s_addr = htonl(0); // Listen on any network interface, equivalent to INADDR_ANY in sockets programming. + address.sin_port = htons(_port); // Listen on the specified port. + cc3k_int_poll(); + if (bind(soc, (sockaddr*) &address, sizeof(address)) < 0) { + CC3K_PRINTLN_F("Error binding listen socket to address!"); + return; + } + // Start listening for connections. + // The backlog parameter is 0 as it is not supported on TI's CC3000 firmware. + cc3k_int_poll(); + if (listen(soc, 0) < 0) { + CC3K_PRINTLN_F("Error opening socket for listening!"); + return; + } + _listenSocket = soc; +} + +// Write data to all connected clients. Buffer is a pointer to an array +// of bytes, and size specifies how many bytes to write from the buffer. +// Return the sum of bytes written to all clients. +size_t Adafruit_CC3000_Server::write(const uint8_t *buffer, size_t size) { + size_t written = 0; + for (int i = 0; i < MAX_SERVER_CLIENTS; ++i) { + if (_clients[i].connected()) { + written += _clients[i].write(buffer, size); + } + } + return written; +} + +// Write a byte value to all connected clients. +// Return the sum of bytes written to all clients. +size_t Adafruit_CC3000_Server::write(uint8_t value) { + return write(&value, 1); +} + +// Accept new connections and update the connected clients. +void Adafruit_CC3000_Server::acceptNewConnections() { + // For any unconnected client, see if new connections are pending and accept + // them as a new client. + for (int i = 0; i < MAX_SERVER_CLIENTS; ++i) { + if (!_clients[i].connected()) { + // Note: Because the non-blocking option was set for the listening + // socket this call will not block and instead return SOC_IN_PROGRESS (-2) + // if there are no pending client connections. Also, the address of the + // connected client is not needed, so those parameters are set to NULL. + cc3k_int_poll(); + int soc = accept(_listenSocket, NULL, NULL); + if (soc > -1) { + _clients[i] = Adafruit_CC3000_Client(soc); + } + // else either there were no sockets to accept or an error occured. + } + } +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000_Server.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000_Server.h new file mode 100755 index 0000000000..86bdc99929 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/Adafruit_CC3000_Server.h @@ -0,0 +1,100 @@ +/**************************************************************************/ +/*! + @file Adafruit_CC3000_Server.h + @author Tony DiCola (tony@tonydicola.com) + @license BSD (see license.txt) + + Adafruit CC3000 TCP server implementation based on the same interface as + the Arduino Ethernet library server class. + + See http://arduino.cc/en/Reference/Ethernet for documentation on the + Arduino Ethernet library and its server interface. + + The only difference between this implementation and the Ethernet library + is that a special client reference facade is returned by the available() + function, instead of a copy of a client like in the Ethernet library. This + is necessary to ensure the buffers that client instances contain aren't + copied and get out of sync. + +*/ +/**************************************************************************/ + +#ifndef ADAFRUIT_CC3000_SERVER_H +#define ADAFRUIT_CC3000_SERVER_H + +#include "Adafruit_CC3000.h" + +#include "Print.h" +#include "Server.h" + +// Assume 4 sockets available, 1 of which is used for listening, so at most 3 +// clients can be connected at once. +#define MAX_SERVER_CLIENTS 3 + +// Facade that wraps a reference to a client instance into something that looks +// and acts like a client instance value. This is done to mimic the semantics +// of the Ethernet library, without running into problems allowing client buffers +// to be copied and get out of sync. +class Adafruit_CC3000_ClientRef : public Print { + public: + Adafruit_CC3000_ClientRef(Adafruit_CC3000_Client* client); + // Return true if the referenced client is connected. This is provided for + // compatibility with Ethernet library code. + operator bool(); + // Below are all the public methods of the client class: + bool connected(void); + size_t write(uint8_t c); + + size_t fastrprint(const char *str); + size_t fastrprintln(const char *str); + size_t fastrprint(char *str); + size_t fastrprintln(char *str); + size_t fastrprint(const __FlashStringHelper *ifsh); + size_t fastrprintln(const __FlashStringHelper *ifsh); + + int16_t write(const void *buf, uint16_t len, uint32_t flags = 0); + int16_t read(void *buf, uint16_t len, uint32_t flags = 0); + uint8_t read(void); + int32_t close(void); + uint8_t available(void); + + private: + // Hide the fact that users are really dealing with a pointer to a client + // instance. Note: this class does not own the contents of the client + // pointer and should NEVER attempt to free/delete this pointer. + Adafruit_CC3000_Client* _client; + +}; + + +class Adafruit_CC3000_Server : public Server { +public: + // Construct a TCP server to listen on the specified port. + Adafruit_CC3000_Server(uint16_t port); + // Return a reference to a client instance which has data available to read. + Adafruit_CC3000_ClientRef available(); + // Initialize the server and start listening for connections. + virtual void begin(); + // Write data to all connected clients. Buffer is a pointer to an array + // of bytes, and size specifies how many bytes to write from the buffer. + // Return the sum of bytes written to all clients. + virtual size_t write(const uint8_t *buffer, size_t size); + // Write a byte value to all connected clients. + // Return the sum of bytes written to all clients. + virtual size_t write(uint8_t value); + // Make the overloads of write from the Print base class available. + using Print::write; + +private: + // Store the clients in a simple array. + Adafruit_CC3000_Client _clients[MAX_SERVER_CLIENTS]; + // The port this server will listen for connections on. + uint16_t _port; + // The id of the listening socket. + uint16_t _listenSocket; + + // Accept new connections and update the connected clients. + void acceptNewConnections(); +}; + +#endif \ No newline at end of file diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/README.txt b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/README.txt new file mode 100755 index 0000000000..378375447f --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/README.txt @@ -0,0 +1,24 @@ +This is a library for the Adafruit CC3000 WiFi Breakouts etc + +Designed specifically to work with the Adafruit CC3000 Breakout + ----> https://www.adafruit.com/products/1469 + +These modules use SPI to communicate, 6 pins are required to interface + +Adafruit invests time and resources providing this open source code, +please support Adafruit and open-source hardware by purchasing +products from Adafruit! + +Check out the links above for our tutorials and wiring diagrams + +Arduino library Written by Limor Fried & Kevin Townsend for Adafruit Industries. +CC3000 host core written by TI + +To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_CC3000 +Check that the Adafruit_CC3000 folder contains Adafruit_CC3000.cpp and Adafruit_CC3000.h + +Place the Adafruit_CC3000 library folder your *arduinosketchfolder*/libraries/ folder. +You may need to create the libraries subfolder if its your first library. Restart the IDE. + +NOTE: the 'SendTweet' example currently DOES NOT WORK due to Twitter API changes. The code is being kept for posterity in case a workaround can be developed. + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/ccspi.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/ccspi.cpp new file mode 100755 index 0000000000..9320500765 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/ccspi.cpp @@ -0,0 +1,769 @@ +/***************************************************************************** +* +* spi.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#include +#include "ccspi.h" +#include "utility/hci.h" +#include "utility/netapp.h" +#include "utility/evnt_handler.h" +#include "utility/cc3000_common.h" +#include "utility/debug.h" + +extern uint8_t g_csPin, g_irqPin, g_vbatPin, g_IRQnum, g_SPIspeed; + +#define READ (3) +#define WRITE (1) +#define HI(value) (((value) & 0xFF00) >> 8) +#define LO(value) ((value) & 0x00FF) +#define HEADERS_SIZE_EVNT (SPI_HEADER_SIZE + 5) +#define SPI_HEADER_SIZE (5) + +#define eSPI_STATE_POWERUP (0) +#define eSPI_STATE_INITIALIZED (1) +#define eSPI_STATE_IDLE (2) +#define eSPI_STATE_WRITE_IRQ (3) +#define eSPI_STATE_WRITE_FIRST_PORTION (4) +#define eSPI_STATE_WRITE_EOT (5) +#define eSPI_STATE_READ_IRQ (6) +#define eSPI_STATE_READ_FIRST_PORTION (7) +#define eSPI_STATE_READ_EOT (8) + +/* +these variables store the SPI configuration +so they can be modified and restored +this is so that we can have multiple SPI devices +on the same bus, so they can operate at different speeds +and in different modes +*/ +#if defined(SPI2X) && defined(__AVR__) // most likely AVR8 +uint8_t ccspi_mySPCR, ccspi_mySPSR, ccspi_oldSPSR, ccspi_oldSPCR; +#define SpiConfigStoreOld() { \ + ccspi_oldSPCR = SPCR; \ + ccspi_oldSPSR = SPSR & _BV(SPI2X); } +#define SpiConfigStoreMy() { \ + ccspi_mySPCR = SPCR; \ + ccspi_mySPSR = SPSR & _BV(SPI2X); } +#define SpiConfigPush() { \ + ccspi_oldSPCR = SPCR; \ + ccspi_oldSPSR = SPSR & _BV(SPI2X); \ + SPCR = ccspi_mySPCR; \ + if(ccspi_mySPSR) SPSR |= _BV(SPI2X); \ + else SPSR &= ~_BV(SPI2X); } +#define SpiConfigPop() { \ + SPCR = ccspi_oldSPCR; \ + if(ccspi_oldSPSR) SPSR |= _BV(SPI2X); \ + else SPSR &= ~_BV(SPI2X); } + +#elif defined(__AVR_XMEGA__) // most likely XMEGA +uint8_t ccspi_mySPICTRL, ccspi_oldSPICTRL; +#define SpiConfigStoreOld() do { ccspi_oldSPICTRL = SPCR; } while (0) +#define SpiConfigStoreMy() do { ccspi_mySPICTRL = SPCR; } while (0) +#define SpiConfigPush() do { ccspi_oldSPICTRL = SPCR; SPCR = ccspi_mySPICTRL; } while (0) +#define SpiConfigPop() do { SPCR = ccspi_oldSPICTRL; } while (0) +#else +// TODO: ARM (Due, Teensy 3.0, etc) +// #error platform not yet supported by Adafruit_CC3000 +#define SpiConfigStoreOld() do { } while (0) +#define SpiConfigStoreMy() do { } while (0) +#define SpiConfigPush() do { } while (0) +#define SpiConfigPop() do { } while (0) +#endif + +#ifdef SPI_HAS_TRANSACTION +// CC3000 SPI config + begin SPI usage + chip select +#define CC3000_ASSERT_CS { \ + SpiConfigPush(); \ + SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE1)); \ + digitalWrite(g_csPin, LOW); } +// CC3000 chip deselect + end SPI usage + SPI restore +#define CC3000_DEASSERT_CS { \ + digitalWrite(g_csPin, HIGH); \ + SPI.endTransaction(); \ + SpiConfigPop(); } +#else +// CC3000 chip select + SPI config +#define CC3000_ASSERT_CS { \ + digitalWrite(g_csPin, LOW); \ + SpiConfigPush(); } +// CC3000 chip deselect + SPI restore +#define CC3000_DEASSERT_CS { \ + digitalWrite(g_csPin, HIGH); \ + SpiConfigPop(); } +#endif + + +/* smartconfig flags (defined in Adafruit_CC3000.cpp) */ +// extern unsigned long ulSmartConfigFinished, ulCC3000DHCP; + +typedef struct +{ + gcSpiHandleRx SPIRxHandler; + + unsigned short usTxPacketLength; + unsigned short usRxPacketLength; + unsigned long ulSpiState; + unsigned char *pTxPacket; + unsigned char *pRxPacket; + +} tSpiInformation; + +tSpiInformation sSpiInformation; + +/* Static buffer for 5 bytes of SPI HEADER */ +unsigned char tSpiReadHeader[] = {READ, 0, 0, 0, 0}; + +void SpiWriteDataSynchronous(unsigned char *data, unsigned short size); +void SpiWriteAsync(const unsigned char *data, unsigned short size); +void SpiPauseSpi(void); +void SpiResumeSpi(void); +void SSIContReadOperation(void); +void cc3k_int_poll(void); + +// The magic number that resides at the end of the TX/RX buffer (1 byte after the allocated size) +// for the purpose of detection of the overrun. The location of the memory where the magic number +// resides shall never be written. In case it is written - the overrun occured and either recevie function +// or send function will stuck forever. +#define CC3000_BUFFER_MAGIC_NUMBER (0xDE) + +char spi_buffer[CC3000_RX_BUFFER_SIZE]; +unsigned char wlan_tx_buffer[CC3000_TX_BUFFER_SIZE]; + +static volatile char ccspi_is_in_irq = 0; +static volatile char ccspi_int_enabled = 0; + +/* Mandatory functions are: + - SpiOpen + - SpiWrite + - SpiRead + - SpiClose + - SpiResumeSpi + - ReadWlanInterruptPin + - WlanInterruptEnable + - WlanInterruptDisable + - WriteWlanPin + */ + + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SpiClose(void) +{ + DEBUGPRINT_F("\tCC3000: SpiClose"); + + if (sSpiInformation.pRxPacket) + { + sSpiInformation.pRxPacket = 0; + } + + /* Disable Interrupt in GPIOA module... */ + tSLInformation.WlanInterruptDisable(); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SpiOpen(gcSpiHandleRx pfRxHandler) +{ + DEBUGPRINT_F("\tCC3000: SpiOpen"); + + sSpiInformation.ulSpiState = eSPI_STATE_POWERUP; + + memset(spi_buffer, 0, sizeof(spi_buffer)); + memset(wlan_tx_buffer, 0, sizeof(spi_buffer)); + + sSpiInformation.SPIRxHandler = pfRxHandler; + sSpiInformation.usTxPacketLength = 0; + sSpiInformation.pTxPacket = NULL; + sSpiInformation.pRxPacket = (unsigned char *)spi_buffer; + sSpiInformation.usRxPacketLength = 0; + + spi_buffer[CC3000_RX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER; + wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER; + + /* Enable interrupt on the GPIO pin of WLAN IRQ */ + tSLInformation.WlanInterruptEnable(); + + DEBUGPRINT_F("\tCC3000: Finished SpiOpen\n\r"); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +int init_spi(void) +{ + + DEBUGPRINT_F("\tCC3000: init_spi\n\r"); + + /* Set POWER_EN pin to output and disable the CC3000 by default */ + pinMode(g_vbatPin, OUTPUT); + digitalWrite(g_vbatPin, 0); + delay(500); + + /* Set CS pin to output (don't de-assert yet) */ + pinMode(g_csPin, OUTPUT); + + /* Set interrupt/gpio pin to input */ +#if defined(INPUT_PULLUP) + pinMode(g_irqPin, INPUT_PULLUP); +#else + pinMode(g_irqPin, INPUT); + digitalWrite(g_irqPin, HIGH); // w/weak pullup +#endif + + SpiConfigStoreOld(); // prime ccspi_old* values for DEASSERT + + /* Initialise SPI (Mode 1) */ + SPI.begin(); + SPI.setDataMode(SPI_MODE1); + SPI.setBitOrder(MSBFIRST); + SPI.setClockDivider(g_SPIspeed); + + SpiConfigStoreMy(); // prime ccspi_my* values for ASSERT + + // Newly-initialized SPI is in the same state that ASSERT_CS will set it + // to. Invoke DEASSERT (which also restores SPI registers) so the next + // ASSERT call won't clobber the ccspi_old* values -- we need those! +#ifdef SPI_HAS_TRANSACTION + SPI.usingInterrupt(g_IRQnum); + digitalWrite(g_csPin, HIGH); // same as CC3000_DEASSERT_CS, but not + SpiConfigPop(); // SPI.endTransaction, because none began +#else + CC3000_DEASSERT_CS; +#endif + + /* ToDo: Configure IRQ interrupt! */ + + DEBUGPRINT_F("\tCC3000: Finished init_spi\n\r"); + + return(ESUCCESS); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +long SpiFirstWrite(unsigned char *ucBuf, unsigned short usLength) +{ + DEBUGPRINT_F("\tCC3000: SpiWriteFirst\n\r"); + + /* Workaround for the first transaction */ + CC3000_ASSERT_CS; + + /* delay (stay low) for ~50us */ + delay(1); + + /* SPI writes first 4 bytes of data */ + SpiWriteDataSynchronous(ucBuf, 4); + + delay(1); + + SpiWriteDataSynchronous(ucBuf + 4, usLength - 4); + + /* From this point on - operate in a regular manner */ + sSpiInformation.ulSpiState = eSPI_STATE_IDLE; + + CC3000_DEASSERT_CS; + + return(0); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength) +{ + unsigned char ucPad = 0; + + DEBUGPRINT_F("\tCC3000: SpiWrite\n\r"); + + /* Figure out the total length of the packet in order to figure out if there is padding or not */ + if(!(usLength & 0x0001)) + { + ucPad++; + } + + pUserBuffer[0] = WRITE; + pUserBuffer[1] = HI(usLength + ucPad); + pUserBuffer[2] = LO(usLength + ucPad); + pUserBuffer[3] = 0; + pUserBuffer[4] = 0; + + usLength += (SPI_HEADER_SIZE + ucPad); + + /* The magic number that resides at the end of the TX/RX buffer (1 byte after the allocated size) + * for the purpose of overrun detection. If the magic number is overwritten - buffer overrun + * occurred - and we will be stuck here forever! */ + if (wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER) + { + DEBUGPRINT_F("\tCC3000: Error - No magic number found in SpiWrite\n\r"); + while (1); + } + + if (sSpiInformation.ulSpiState == eSPI_STATE_POWERUP) + { + while (sSpiInformation.ulSpiState != eSPI_STATE_INITIALIZED); + } + + if (sSpiInformation.ulSpiState == eSPI_STATE_INITIALIZED) + { + /* This is time for first TX/RX transactions over SPI: the IRQ is down - so need to send read buffer size command */ + SpiFirstWrite(pUserBuffer, usLength); + } + else + { + /* We need to prevent here race that can occur in case two back to back packets are sent to the + * device, so the state will move to IDLE and once again to not IDLE due to IRQ */ + tSLInformation.WlanInterruptDisable(); + + while (sSpiInformation.ulSpiState != eSPI_STATE_IDLE); + + sSpiInformation.ulSpiState = eSPI_STATE_WRITE_IRQ; + sSpiInformation.pTxPacket = pUserBuffer; + sSpiInformation.usTxPacketLength = usLength; + + /* Assert the CS line and wait till SSI IRQ line is active and then initialize write operation */ + CC3000_ASSERT_CS; + + /* Re-enable IRQ - if it was not disabled - this is not a problem... */ + tSLInformation.WlanInterruptEnable(); + + /* Check for a missing interrupt between the CS assertion and enabling back the interrupts */ + if (tSLInformation.ReadWlanInterruptPin() == 0) + { + SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength); + + sSpiInformation.ulSpiState = eSPI_STATE_IDLE; + + CC3000_DEASSERT_CS; +#ifdef SPI_HAS_TRANSACTION + WlanInterruptEnable(); +#endif + } + } + + /* Due to the fact that we are currently implementing a blocking situation + * here we will wait till end of transaction */ + while (eSPI_STATE_IDLE != sSpiInformation.ulSpiState); + + return(0); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SpiWriteDataSynchronous(unsigned char *data, unsigned short size) +{ + DEBUGPRINT_F("\tCC3000: SpiWriteDataSynchronous Start\n\r"); + + unsigned short loc; + for (loc = 0; loc < size; loc ++) + { + SPI.transfer(data[loc]); +#if (DEBUG_MODE == 1) + if (!(loc==size-1)) + { + DEBUGPRINT_F(" "); + DEBUGPRINT_HEX(data[loc]); + } + else + { + DEBUGPRINT_F(" "); + DEBUGPRINT_HEX(data[loc]); + } +#endif + } + + DEBUGPRINT_F("\n\r\tCC3000: SpiWriteDataSynchronous End\n\r"); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SpiReadDataSynchronous(unsigned char *data, unsigned short size) +{ + unsigned short i = 0; + + DEBUGPRINT_F("\tCC3000: SpiReadDataSynchronous\n\r"); + SPI.setDataMode(SPI_MODE1); + for (i = 0; i < size; i ++) + { + data[i] = SPI.transfer(0x03); + DEBUGPRINT_F(" "); + DEBUGPRINT_HEX(data[i]); + } + DEBUGPRINT_F("\n\r"); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SpiReadHeader(void) +{ + DEBUGPRINT_F("\tCC3000: SpiReadHeader\n\r"); + + SpiReadDataSynchronous(sSpiInformation.pRxPacket, HEADERS_SIZE_EVNT); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +long SpiReadDataCont(void) +{ + long data_to_recv; + unsigned char *evnt_buff, type; + + DEBUGPRINT_F("\tCC3000: SpiReadDataCont\n\r"); + + /* Determine what type of packet we have */ + evnt_buff = sSpiInformation.pRxPacket; + data_to_recv = 0; + STREAM_TO_UINT8((uint8_t *)(evnt_buff + SPI_HEADER_SIZE), HCI_PACKET_TYPE_OFFSET, type); + + switch(type) + { + case HCI_TYPE_DATA: + { + /* We need to read the rest of data.. */ + STREAM_TO_UINT16((char *)(evnt_buff + SPI_HEADER_SIZE), HCI_DATA_LENGTH_OFFSET, data_to_recv); + if (!((HEADERS_SIZE_EVNT + data_to_recv) & 1)) + { + data_to_recv++; + } + + if (data_to_recv) + { + SpiReadDataSynchronous(evnt_buff + HEADERS_SIZE_EVNT, data_to_recv); + } + break; + } + case HCI_TYPE_EVNT: + { + /* Calculate the rest length of the data */ + STREAM_TO_UINT8((char *)(evnt_buff + SPI_HEADER_SIZE), HCI_EVENT_LENGTH_OFFSET, data_to_recv); + data_to_recv -= 1; + + /* Add padding byte if needed */ + if ((HEADERS_SIZE_EVNT + data_to_recv) & 1) + { + data_to_recv++; + } + + if (data_to_recv) + { + SpiReadDataSynchronous(evnt_buff + HEADERS_SIZE_EVNT, data_to_recv); + } + + sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT; + break; + } + } + + return (0); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SpiPauseSpi(void) +{ + DEBUGPRINT_F("\tCC3000: SpiPauseSpi\n\r"); + + ccspi_int_enabled = 0; + detachInterrupt(g_IRQnum); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SpiResumeSpi(void) +{ + DEBUGPRINT_F("\tCC3000: SpiResumeSpi\n\r"); + + ccspi_int_enabled = 1; + attachInterrupt(g_IRQnum, SPI_IRQ, FALLING); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SpiTriggerRxProcessing(void) +{ + DEBUGPRINT_F("\tCC3000: SpiTriggerRxProcessing\n\r"); + + /* Trigger Rx processing */ + SpiPauseSpi(); + CC3000_DEASSERT_CS; + + //DEBUGPRINT_F("Magic?\n\r"); + /* The magic number that resides at the end of the TX/RX buffer (1 byte after the allocated size) + * for the purpose of detection of the overrun. If the magic number is overriten - buffer overrun + * occurred - and we will stuck here forever! */ + if (sSpiInformation.pRxPacket[CC3000_RX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER) + { + /* You've got problems if you're here! */ + DEBUGPRINT_F("\tCC3000: ERROR - magic number missing!\n\r"); + while (1); + } + + //DEBUGPRINT_F("OK!\n\r"); + sSpiInformation.ulSpiState = eSPI_STATE_IDLE; + sSpiInformation.SPIRxHandler(sSpiInformation.pRxPacket + SPI_HEADER_SIZE); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void SSIContReadOperation(void) +{ + DEBUGPRINT_F("\tCC3000: SpiContReadOperation\n\r"); + + /* The header was read - continue with the payload read */ + if (!SpiReadDataCont()) + { + /* All the data was read - finalize handling by switching to teh task + * and calling from task Event Handler */ + //DEBUGPRINT_F("SPItrig\n\r"); + SpiTriggerRxProcessing(); + } +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void WriteWlanPin( unsigned char val ) +{ + if (DEBUG_MODE) + { + DEBUGPRINT_F("\tCC3000: WriteWlanPin - "); + DEBUGPRINT_DEC(val); + DEBUGPRINT_F("\n\r"); + delay(1); + } + if (val) + { + digitalWrite(g_vbatPin, HIGH); + } + else + { + digitalWrite(g_vbatPin, LOW); + } +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +long ReadWlanInterruptPin(void) +{ + DEBUGPRINT_F("\tCC3000: ReadWlanInterruptPin - "); + DEBUGPRINT_DEC(digitalRead(g_irqPin)); + DEBUGPRINT_F("\n\r"); + + return(digitalRead(g_irqPin)); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void WlanInterruptEnable() +{ + DEBUGPRINT_F("\tCC3000: WlanInterruptEnable.\n\r"); + // delay(100); + ccspi_int_enabled = 1; + attachInterrupt(g_IRQnum, SPI_IRQ, FALLING); +} + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ +void WlanInterruptDisable() +{ + DEBUGPRINT_F("\tCC3000: WlanInterruptDisable\n\r"); + ccspi_int_enabled = 0; + detachInterrupt(g_IRQnum); +} + +//***************************************************************************** +// +//! sendDriverPatch +//! +//! @param pointer to the length +//! +//! @return none +//! +//! @brief The function returns a pointer to the driver patch: +//! since there is no patch in the host - it returns 0 +// +//***************************************************************************** +char *sendDriverPatch(unsigned long *Length) { + *Length = 0; + return NULL; +} + +//***************************************************************************** +// +//! sendBootLoaderPatch +//! +//! @param pointer to the length +//! +//! @return none +//! +//! @brief The function returns a pointer to the boot loader patch: +//! since there is no patch in the host - it returns 0 +// +//***************************************************************************** +char *sendBootLoaderPatch(unsigned long *Length) { + *Length = 0; + return NULL; +} + +//***************************************************************************** +// +//! sendWLFWPatch +//! +//! @param pointer to the length +//! +//! @return none +//! +//! @brief The function returns a pointer to the FW patch: +//! since there is no patch in the host - it returns 0 +// +//***************************************************************************** +char *sendWLFWPatch(unsigned long *Length) { + *Length = 0; + return NULL; +} + + +/**************************************************************************/ +/*! + + */ +/**************************************************************************/ + +void SPI_IRQ(void) +{ + ccspi_is_in_irq = 1; + + DEBUGPRINT_F("\tCC3000: Entering SPI_IRQ\n\r"); + + if (sSpiInformation.ulSpiState == eSPI_STATE_POWERUP) + { + /* IRQ line was low ... perform a callback on the HCI Layer */ + sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED; + } + else if (sSpiInformation.ulSpiState == eSPI_STATE_IDLE) + { + //DEBUGPRINT_F("IDLE\n\r"); + sSpiInformation.ulSpiState = eSPI_STATE_READ_IRQ; + /* IRQ line goes down - start reception */ + + CC3000_ASSERT_CS; + + // Wait for TX/RX Compete which will come as DMA interrupt + SpiReadHeader(); + sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT; + //DEBUGPRINT_F("SSICont\n\r"); + SSIContReadOperation(); + } + else if (sSpiInformation.ulSpiState == eSPI_STATE_WRITE_IRQ) + { + SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength); + sSpiInformation.ulSpiState = eSPI_STATE_IDLE; + CC3000_DEASSERT_CS; + } + + DEBUGPRINT_F("\tCC3000: Leaving SPI_IRQ\n\r"); + + ccspi_is_in_irq = 0; + return; +} + +//***************************************************************************** +// +//! cc3k_int_poll +//! +//! \brief checks if the interrupt pin is low +//! just in case the hardware missed a falling edge +//! function is in ccspi.cpp +// +//***************************************************************************** + +void cc3k_int_poll() +{ + if (digitalRead(g_irqPin) == LOW && ccspi_is_in_irq == 0 && ccspi_int_enabled != 0) { + SPI_IRQ(); + } +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/ccspi.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/ccspi.h new file mode 100755 index 0000000000..095c4f68cb --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/ccspi.h @@ -0,0 +1,90 @@ +/***************************************************************************** +* +* spi.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ + + +#ifndef __SPI_H__ +#define __SPI_H__ + +#if ARDUINO >= 100 + #include "Arduino.h" +#else + #include "WProgram.h" +#endif + +#include +#include +#include +#include + +#include "utility/wlan.h" + +typedef void (*gcSpiHandleRx)(void *p); +typedef void (*gcSpiHandleTx)(void); + +extern unsigned char wlan_tx_buffer[]; + +//***************************************************************************** +// +// Prototypes for the APIs. +// +//***************************************************************************** +extern void SpiOpen(gcSpiHandleRx pfRxHandler); +extern void SpiClose(void); +extern long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength); +extern void SpiResumeSpi(void); +extern void SpiCleanGPIOISR(void); +extern int init_spi(void); +extern long TXBufferIsEmpty(void); +extern long RXBufferIsEmpty(void); +extern void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length); +extern void WriteWlanPin( unsigned char val ); +extern long ReadWlanInterruptPin(void); +extern void WlanInterruptEnable(); +extern void WlanInterruptDisable(); +extern char *sendDriverPatch(unsigned long *Length); +extern char *sendBootLoaderPatch(unsigned long *Length); +extern char *sendWLFWPatch(unsigned long *Length); +extern void SPI_IRQ(void); + +#endif + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/ChatServer/ChatServer.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/ChatServer/ChatServer.ino new file mode 100755 index 0000000000..467120cdeb --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/ChatServer/ChatServer.ino @@ -0,0 +1,179 @@ + +/*************************************************** + Adafruit CC3000 Breakout/Shield TCP Chat Server + + This is a simple chat server which allows clients to connect + with telnet and exchange messages. Anything sent by one + client will be written out to all connected clients. + + See the CC3000 tutorial on Adafruit's learning system + for more information on setting up and using the + CC3000: + http://learn.adafruit.com/adafruit-cc3000-wifi + + Requirements: + + This sketch requires the Adafruit CC3000 library. You can + download the library from: + https://github.com/adafruit/Adafruit_CC3000_Library + + For information on installing libraries in the Arduino IDE + see this page: + http://arduino.cc/en/Guide/Libraries + + Usage: + + Update the SSID and, if necessary, the CC3000 hardware pin + information below, then run the sketch and check the + output of the serial port. After connecting to the + wireless network successfully the sketch will output + the IP address of the server and start listening for + connections. Once listening for connections, connect + to the server from your computer using a telnet client + on port 23. + + For example on Linux or Mac OSX, if your CC3000 has an + IP address 192.168.1.100 you would execute in a command + window: + + telnet 192.168.1.100 23 + + Connect multiple clients and notice that whatever one client + sends will be echoed to all other clients. Press ctrl-] and + type quit at the prompt to close the telnet session. + + On Windows you'll need to download a telnet client. PuTTY + is a good, free GUI client: + http://www.chiark.greenend.org.uk/~sgtatham/putty/ + + License: + + This example is copyright (c) 2013 Tony DiCola (tony@tonydicola.com) + and is released under an open source MIT license. See details at: + http://opensource.org/licenses/MIT + + This code was adapted from Adafruit CC3000 library example + code which has the following license: + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried & Kevin Townsend for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ +#include +#include +#include "utility/debug.h" +#include "utility/socket.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); // you can change this clock speed + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + +#define LISTEN_PORT 23 // What TCP port to listen on for connections. + +Adafruit_CC3000_Server chatServer(LISTEN_PORT); + +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); + + /* Initialise the module */ + Serial.println(F("\nInitializing...")); + if (!cc3000.begin()) + { + Serial.println(F("Couldn't begin()! Check your wiring?")); + while(1); + } + + Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID); + if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + while(1); + } + + Serial.println(F("Connected!")); + + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) + { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (! displayConnectionDetails()) { + delay(1000); + } + + /*********************************************************/ + /* You can safely remove this to save some flash memory! */ + /*********************************************************/ + Serial.println(F("\r\nNOTE: This sketch may cause problems with other sketches")); + Serial.println(F("since the .disconnect() function is never called, so the")); + Serial.println(F("AP may refuse connection requests from the CC3000 until a")); + Serial.println(F("timeout period passes. This is normal behaviour since")); + Serial.println(F("there isn't an obvious moment to disconnect with a server.\r\n")); + + // Start listening for connections + chatServer.begin(); + + Serial.println(F("Listening for connections...")); +} + +void loop(void) +{ + // Try to get a client which is connected. + Adafruit_CC3000_ClientRef client = chatServer.available(); + if (client) { + // Check if there is data available to read. + if (client.available() > 0) { + // Read a byte and write it to all clients. + uint8_t ch = client.read(); + chatServer.write(ch); + } + } +} + +/**************************************************************************/ +/*! + @brief Tries to read the IP address and other connection details +*/ +/**************************************************************************/ +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/EchoServer/EchoServer.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/EchoServer/EchoServer.ino new file mode 100755 index 0000000000..e747cd85f6 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/EchoServer/EchoServer.ino @@ -0,0 +1,185 @@ + +/*************************************************** + Adafruit CC3000 Breakout/Shield TCP Echo Server + + This is a simple implementation of the echo + protocol, RFC 862 http://tools.ietf.org/html/rfc862 , + for the Arduino platform and Adafruit CC3000 breakout + or shield. This sketch will create a TCP server that + listens by default on port 7 and echos back any data + received. Up to 3 clients can be connected concurrently + to the server. This sketch is meant as an example of how + to write a simple server with the Arduino and CC3000. + + See the CC3000 tutorial on Adafruit's learning system + for more information on setting up and using the + CC3000: + http://learn.adafruit.com/adafruit-cc3000-wifi + + Requirements: + + This sketch requires the Adafruit CC3000 library. You can + download the library from: + https://github.com/adafruit/Adafruit_CC3000_Library + + For information on installing libraries in the Arduino IDE + see this page: + http://arduino.cc/en/Guide/Libraries + + Usage: + + Update the SSID and, if necessary, the CC3000 hardware pin + information below, then run the sketch and check the + output of the serial port. After connecting to the + wireless network successfully the sketch will output + the IP address of the server and start listening for + connections. Once listening for connections, connect + to the server from your computer using a telnet client + on port 7. + + For example on Linux or Mac OSX, if your CC3000 has an + IP address 192.168.1.100 you would execute in a command + window: + + telnet 192.168.1.100 7 + + After connecting, notice that as you type input and + press enter to send it the CC3000 will echo back exactly + what you typed. Press ctrl-] and type quit at the prompt + to close the telnet session. + + On Windows you'll need to download a telnet client. PuTTY + is a good, free GUI client: + http://www.chiark.greenend.org.uk/~sgtatham/putty/ + + License: + + This example is copyright (c) 2013 Tony DiCola (tony@tonydicola.com) + and is released under an open source MIT license. See details at: + http://opensource.org/licenses/MIT + + This code was adapted from Adafruit CC3000 library example + code which has the following license: + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried & Kevin Townsend for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ +#include +#include +#include "utility/debug.h" +#include "utility/socket.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); // you can change this clock speed + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + +#define LISTEN_PORT 7 // What TCP port to listen on for connections. The echo protocol uses port 7. + +Adafruit_CC3000_Server echoServer(LISTEN_PORT); + +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); + + /* Initialise the module */ + Serial.println(F("\nInitializing...")); + if (!cc3000.begin()) + { + Serial.println(F("Couldn't begin()! Check your wiring?")); + while(1); + } + + Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID); + if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + while(1); + } + + Serial.println(F("Connected!")); + + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) + { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (! displayConnectionDetails()) { + delay(1000); + } + + /*********************************************************/ + /* You can safely remove this to save some flash memory! */ + /*********************************************************/ + Serial.println(F("\r\nNOTE: This sketch may cause problems with other sketches")); + Serial.println(F("since the .disconnect() function is never called, so the")); + Serial.println(F("AP may refuse connection requests from the CC3000 until a")); + Serial.println(F("timeout period passes. This is normal behaviour since")); + Serial.println(F("there isn't an obvious moment to disconnect with a server.\r\n")); + + // Start listening for connections + echoServer.begin(); + + Serial.println(F("Listening for connections...")); +} + +void loop(void) +{ + // Try to get a client which is connected. + Adafruit_CC3000_ClientRef client = echoServer.available(); + if (client) { + // Check if there is data available to read. + if (client.available() > 0) { + // Read a byte and write it to all clients. + uint8_t ch = client.read(); + client.write(ch); + } + } +} + +/**************************************************************************/ +/*! + @brief Tries to read the IP address and other connection details +*/ +/**************************************************************************/ +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/GeoLocation/GeoLocation.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/GeoLocation/GeoLocation.ino new file mode 100755 index 0000000000..45b984e6e2 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/GeoLocation/GeoLocation.ino @@ -0,0 +1,296 @@ +/*************************************************** + This is an example for the Adafruit CC3000 Wifi Breakout & Shield + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried, Kevin Townsend and Phil Burgess for + Adafruit Industries. BSD license, all text above must be included + in any redistribution + ****************************************************/ + +/* +This example queries the freegeoip.net service to get the local +approximate geographic location based on IP address. Combined with +code in the InternetTime sketch, this can give absolute position and +time, extremely useful for seasonal calculations like sun position, +insolation, day length, etc. Sure, could always add a GPS module or +just plug in values from one's GPS or phone, but this has the dual +luxuries of coming 'free' with the existing WiFi hardware, and being +automatic (albeit a bit less accurate...but totally sufficient for +the applications mentioned). + +Positional accuracy depends on the freegeoip.net database, in turn +based on data collected by maxmind.com. No guarantees this will work +for every location. + +Position should be polled only once, at startup, or very infrequently +if making a mobile network-hopping thing, so as not to overwhelm the +kindly-provided free geolocation service. +*/ + +#include +#include +#include +#include +#include "utility/debug.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, + ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); // you can change this clock speed + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + +Adafruit_CC3000_Client client; + +const unsigned long + dhcpTimeout = 60L * 1000L, // Max time to wait for address from DHCP + connectTimeout = 15L * 1000L, // Max time to wait for server connection + responseTimeout = 15L * 1000L; // Max time to wait for data from server + +// This program prints a few tidbits of information about the current location +// (Country, region (state), city, longitude and latitude). Additional info is +// available but just isn't recorded by this code -- can look at jsonParse() +// function to see how it's done and add what you need (or remove what you don't). +// The total list of available attributes includes: ip, country_code, +// country_name, region_code, region_name, city, zipcode, latitude, longitude, +// metro_code and areacode. +char + country[20], + region[20], + city[20], + name[13], // Temp space for name:value parsing + value[64]; // Temp space for name:value parsing +float + longitude, latitude; + +void setup(void) { + uint32_t ip = 0L, t; + + Serial.begin(115200); + Serial.println(F("Hello, CC3000!")); + + Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); + + Serial.print(F("Initializing...")); + if(!cc3000.begin()) { + Serial.println(F("failed. Check your wiring?")); + return; + } + + Serial.print(F("OK.\r\nConnecting to network...")); + if(!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + return; + } + Serial.println(F("connected!")); + + Serial.print(F("Requesting address from DHCP server...")); + for(t=millis(); !cc3000.checkDHCP() && ((millis() - t) < dhcpTimeout); delay(1000)); + if(cc3000.checkDHCP()) { + Serial.println(F("OK")); + } else { + Serial.println(F("failed")); + return; + } + + while(!displayConnectionDetails()) delay(1000); + + // Look up server's IP address + Serial.print(F("\r\nGetting server IP address...")); + t = millis(); + while((0L == ip) && ((millis() - t) < connectTimeout)) { + if(cc3000.getHostByName("freegeoip.net", &ip)) break; + delay(1000); + } + if(0L == ip) { + Serial.println(F("failed")); + return; + } + cc3000.printIPdotsRev(ip); + Serial.println(); + + // Request JSON-formatted data from server (port 80) + Serial.print(F("Connecting to geo server...")); + client = cc3000.connectTCP(ip, 80); + if(client.connected()) { + Serial.print(F("connected.\r\nRequesting data...")); + client.print(F("GET /json/ HTTP/1.0\r\nConnection: close\r\n\r\n")); + } else { + Serial.println(F("failed")); + return; + } + + Serial.print("\r\nReading response..."); + country[0] = region[0] = city[0] = 0; // Clear data + jsonParse(0, 0); + client.close(); + Serial.println(F("OK")); + + /* You need to make sure to clean up after yourself or the CC3000 can freak out */ + /* the next time your try to connect ... */ + Serial.println(F("\nDisconnecting")); + cc3000.disconnect(); + + Serial.print(F("\r\nRESULTS:\r\n Country: ")); + Serial.println(country); + Serial.print(F(" Region: ")); + Serial.println(region); + Serial.print(F(" City: ")); + Serial.println(city); + Serial.print(F(" Longitude: ")); + Serial.println(longitude); + Serial.print(F(" Latitude: ")); + Serial.println(latitude); +} + +void loop(void) { } // Not used by this code + + +bool displayConnectionDetails(void) { + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } else { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} + + +// Helper functions swiped from Adafruit 'Gutenbird' code (with changes) + +boolean jsonParse(int depth, byte endChar) { + int c, i; + boolean readName = true; + for(;;) { + while(isspace(c = timedRead())); // Scan past whitespace + if(c < 0) return false; // Timeout + if(c == endChar) return true; // EOD + + if(c == '{') { // Object follows + if(!jsonParse(depth + 1, '}')) return false; + if(!depth) return true; // End of file + } else if(c == '[') { // Array follows + if(!jsonParse(depth + 1,']')) return false; + } else if((c == '"') || (c == '\'')) { // String follows + if(readName) { // Name-reading mode + if(!readString(name, sizeof(name)-1, c)) return false; + } else { // Value-reading mode + if(!readString(value, sizeof(value)-1, c)) return false; + // Process name and value strings: + if (!strcasecmp(name, "country_name")) { + strncpy(country, value, sizeof(country)-1); + } else if(!strcasecmp(name, "region_name")) { + strncpy(region, value, sizeof(region)-1); + } else if(!strcasecmp(name, "city")) { + strncpy(city, value, sizeof(city)-1); + } + } + } else if(c == ':') { // Separator between name:value + readName = false; // Now in value-reading mode + value[0] = 0; // Clear existing value data + } else if(c == ',') { // Separator between name/value pairs + readName = true; // Now in name-reading mode + name[0] = 0; // Clear existing name data + } else { + // Else true/false/null or a number follows. + value[0] = c; + if(!strcasecmp(name, "longitude")) { + if(!readString(value+1, sizeof(value)-1, ',')) return false; + longitude = atof(value); + } else if(!strcasecmp(name, "latitude")) { + if(!readString(value+1, sizeof(value)-1, ',')) return false; + latitude = atof(value); + } + readName = true; // Now in name-reading mode + name[0] = 0; // Clear existing name data + } + } +} + +// Read string from client stream into destination buffer, up to a maximum +// requested length. Buffer should be at least 1 byte larger than this to +// accommodate NUL terminator. Opening quote is assumed already read, +// closing quote will be discarded, and stream will be positioned +// immediately following the closing quote (regardless whether max length +// is reached -- excess chars are discarded). Returns true on success +// (including zero-length string), false on timeout/read error. +boolean readString(char *dest, int maxLen, char quote) { + int c, len = 0; + + while((c = timedRead()) != quote) { // Read until closing quote + if(c == '\\') { // Escaped char follows + c = timedRead(); // Read it + // Certain escaped values are for cursor control -- + // there might be more suitable printer codes for each. + if (c == 'b') c = '\b'; // Backspace + else if(c == 'f') c = '\f'; // Form feed + else if(c == 'n') c = '\n'; // Newline + else if(c == 'r') c = '\r'; // Carriage return + else if(c == 't') c = '\t'; // Tab + else if(c == 'u') c = unidecode(4); + else if(c == 'U') c = unidecode(8); + // else c is unaltered -- an escaped char such as \ or " + } // else c is a normal unescaped char + + if(c < 0) return false; // Timeout + + // In order to properly position the client stream at the end of + // the string, characters are read to the end quote, even if the max + // string length is reached...the extra chars are simply discarded. + if(len < maxLen) dest[len++] = c; + } + + dest[len] = 0; + return true; // Success (even if empty string) +} + +// Read a given number of hexadecimal characters from client stream, +// representing a Unicode symbol. Return -1 on error, else return nearest +// equivalent glyph in printer's charset. (See notes below -- for now, +// always returns '-' or -1.) +int unidecode(byte len) { + int c, v, result = 0; + while(len--) { + if((c = timedRead()) < 0) return -1; // Stream timeout + if ((c >= '0') && (c <= '9')) v = c - '0'; + else if((c >= 'A') && (c <= 'F')) v = 10 + c - 'A'; + else if((c >= 'a') && (c <= 'f')) v = 10 + c - 'a'; + else return '-'; // garbage + result = (result << 4) | v; + } + + return '?'; +} + +// Read from client stream with a 5 second timeout. Although an +// essentially identical method already exists in the Stream() class, +// it's declared private there...so this is a local copy. +int timedRead(void) { + unsigned long start = millis(); + while((!client.available()) && ((millis() - start) < 5000L)); + return client.read(); // -1 on timeout +} + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/InternetTime/InternetTime.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/InternetTime/InternetTime.ino new file mode 100755 index 0000000000..f6d1ebfe99 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/InternetTime/InternetTime.ino @@ -0,0 +1,278 @@ +/*************************************************** + This is an example for the Adafruit CC3000 Wifi Breakout & Shield + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried, Kevin Townsend and Phil Burgess for + Adafruit Industries. BSD license, all text above must be included + in any redistribution + ****************************************************/ + +/* +This example queries an NTP time server to get the current "UNIX time" +(seconds since 1/1/1970, UTC (GMT)), then uses the Arduino's internal +timer to keep relative time. The clock is re-synchronized roughly +once per day. This minimizes NTP server misuse/abuse. + +The RTClib library (a separate download, and not used here) contains +functions to convert UNIX time to other formats if needed. +*/ + +#include +#include +#include + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); // you can change this clock speed but DI + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + +Adafruit_CC3000_Client client; + +const unsigned long + connectTimeout = 15L * 1000L, // Max time to wait for server connection + responseTimeout = 15L * 1000L; // Max time to wait for data from server +int + countdown = 0; // loop() iterations until next time server query +unsigned long + lastPolledTime = 0L, // Last value retrieved from time server + sketchTime = 0L; // CPU milliseconds since last server query + + +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + displayDriverMode(); + + Serial.println(F("\nInitialising the CC3000 ...")); + if (!cc3000.begin()) { + Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + for(;;); + } + + uint16_t firmware = checkFirmwareVersion(); + if (firmware < 0x113) { + Serial.println(F("Wrong firmware version!")); + for(;;); + } + + displayMACAddress(); + + Serial.println(F("\nDeleting old connection profiles")); + if (!cc3000.deleteProfiles()) { + Serial.println(F("Failed!")); + while(1); + } + + /* Attempt to connect to an access point */ + char *ssid = WLAN_SSID; /* Max 32 chars */ + Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid); + + /* NOTE: Secure connections are not available in 'Tiny' mode! */ + if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + while(1); + } + + Serial.println(F("Connected!")); + + /* Wait for DHCP to complete */ + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (!displayConnectionDetails()) { + delay(1000); + } +} + + +// To reduce load on NTP servers, time is polled once per roughly 24 hour period. +// Otherwise use millis() to estimate time since last query. Plenty accurate. +void loop(void) { + + if(countdown == 0) { // Time's up? + unsigned long t = getTime(); // Query time server + if(t) { // Success? + lastPolledTime = t; // Save time + sketchTime = millis(); // Save sketch time of last valid time query + countdown = 24*60*4-1; // Reset counter: 24 hours * 15-second intervals + } + } else { + countdown--; // Don't poll; use math to figure current time + } + + unsigned long currentTime = lastPolledTime + (millis() - sketchTime) / 1000; + + Serial.print(F("Current UNIX time: ")); + Serial.print(currentTime); + Serial.println(F(" (seconds since 1/1/1970 UTC)")); + + delay(15000L); // Pause 15 seconds +} + + +/**************************************************************************/ +/*! + @brief Displays the driver mode (tiny of normal), and the buffer + size if tiny mode is not being used + + @note The buffer size and driver mode are defined in cc3000_common.h +*/ +/**************************************************************************/ +void displayDriverMode(void) +{ + #ifdef CC3000_TINY_DRIVER + Serial.println(F("CC3000 is configure in 'Tiny' mode")); + #else + Serial.print(F("RX Buffer : ")); + Serial.print(CC3000_RX_BUFFER_SIZE); + Serial.println(F(" bytes")); + Serial.print(F("TX Buffer : ")); + Serial.print(CC3000_TX_BUFFER_SIZE); + Serial.println(F(" bytes")); + #endif +} + +/**************************************************************************/ +/*! + @brief Tries to read the CC3000's internal firmware patch ID +*/ +/**************************************************************************/ +uint16_t checkFirmwareVersion(void) +{ + uint8_t major, minor; + uint16_t version; + +#ifndef CC3000_TINY_DRIVER + if(!cc3000.getFirmwareVersion(&major, &minor)) + { + Serial.println(F("Unable to retrieve the firmware version!\r\n")); + version = 0; + } + else + { + Serial.print(F("Firmware V. : ")); + Serial.print(major); Serial.print(F(".")); Serial.println(minor); + version = major; version <<= 8; version |= minor; + } +#endif + return version; +} + +/**************************************************************************/ +/*! + @brief Tries to read the 6-byte MAC address of the CC3000 module +*/ +/**************************************************************************/ +void displayMACAddress(void) +{ + uint8_t macAddress[6]; + + if(!cc3000.getMacAddress(macAddress)) + { + Serial.println(F("Unable to retrieve MAC Address!\r\n")); + } + else + { + Serial.print(F("MAC Address : ")); + cc3000.printHex((byte*)&macAddress, 6); + } +} + + +/**************************************************************************/ +/*! + @brief Tries to read the IP address and other connection details +*/ +/**************************************************************************/ +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} + +// Minimalist time server query; adapted from Adafruit Gutenbird sketch, +// which in turn has roots in Arduino UdpNTPClient tutorial. +unsigned long getTime(void) { + + uint8_t buf[48]; + unsigned long ip, startTime, t = 0L; + + Serial.print(F("Locating time server...")); + + // Hostname to IP lookup; use NTP pool (rotates through servers) + if(cc3000.getHostByName("pool.ntp.org", &ip)) { + static const char PROGMEM + timeReqA[] = { 227, 0, 6, 236 }, + timeReqB[] = { 49, 78, 49, 52 }; + + Serial.println(F("\r\nAttempting connection...")); + startTime = millis(); + do { + client = cc3000.connectUDP(ip, 123); + } while((!client.connected()) && + ((millis() - startTime) < connectTimeout)); + + if(client.connected()) { + Serial.print(F("connected!\r\nIssuing request...")); + + // Assemble and issue request packet + memset(buf, 0, sizeof(buf)); + memcpy_P( buf , timeReqA, sizeof(timeReqA)); + memcpy_P(&buf[12], timeReqB, sizeof(timeReqB)); + client.write(buf, sizeof(buf)); + + Serial.print(F("\r\nAwaiting response...")); + memset(buf, 0, sizeof(buf)); + startTime = millis(); + while((!client.available()) && + ((millis() - startTime) < responseTimeout)); + if(client.available()) { + client.read(buf, sizeof(buf)); + t = (((unsigned long)buf[40] << 24) | + ((unsigned long)buf[41] << 16) | + ((unsigned long)buf[42] << 8) | + (unsigned long)buf[43]) - 2208988800UL; + Serial.print(F("OK\r\n")); + } + client.close(); + } + } + if(!t) Serial.println(F("error")); + return t; +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SendTweet/SendTweet.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SendTweet/SendTweet.ino new file mode 100755 index 0000000000..841c62a392 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SendTweet/SendTweet.ino @@ -0,0 +1,447 @@ +/* +IMPORTANT: THIS SOFTWARE CURRENTLY DOES NOT WORK, and future +status is uncertain. Twitter has changed their API to require +SSL (Secure Sockets Layer) on -all- connections, a complex +operation beyond the Arduino's ability to handle. The code is +being kept around on the chance that a suitable proxy service +becomes available...but at present we have no such service, no +code for such, nor a schedule or even a firm commitment to +pursue it. For projects requiring Twitter we now recommend +using an SSL-capable system such as Raspberry Pi. +*/ + + +/* +Send tweets wirelessly from Arduino using the new Twitter 1.1 API. +Self-contained, operates directly -- no proxy server required! + +Designed for IoTA -- Internet of Things by Adafruit -- a series of Arduino- +compatible WiFi products based on the TI CC3000 module, to be available in +shield, breakout and standalone development board form-factors. + +Written by Adafruit Industries, distributed under BSD License. + +MUST BE CONFIGURED FOR TWITTER 1.1 API BEFORE USE. See notes below. + +REQUIRES ARDUINO IDE 1.0 OR LATER -- Back-porting is not likely to occur, +as the code is deeply dependent on the Stream class, etc. + +Requires Adafruit fork of Peter Knight's Cryptosuite library for Arduino: +https://github.com/adafruit/Cryptosuite + +Required hardware includes an 802.11 wireless access point, any of the +Adafruit IoTa WiFi devices, a compatible Arduino board (for shield and +breakout form-factors) and, optionally, sensors to be read and reported +via Twitter. + +Resources: +http://www.adafruit.com/products/1469 IoTa breakout board +http://www.adafruit.com/products/201 Arduino Uno +[ additional links will go here ] + +Uses Twitter 1.1 API. This REQUIRES a Twitter account and some account +configuration. Start at dev.twitter.com, sign in with your Twitter +credentials, select "My Applications" from the avatar drop-down menu at the +top right, then "Create a new application." Provide a name, description, +placeholder URL and complete the captcha, after which you'll be provided a +"consumer key" and "consumer secret" for your app. Select "Create access +token" to also generate an "access token" and "access token secret." +ALL FOUR STRINGS must be copied to the correct positions in the globals below, +and configure the search string to your liking. DO NOT SHARE your keys or +secrets! If you put code on Github or other public repository, replace them +with dummy strings. Next, from the Twitter "Settings" tab, change the +Application Type to "Read and Write" -- MANDATORY or the sketch won't work! + + +Copyright (c) 2013 Adafruit Industries. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include + +// -------------------------------------------------------------------------- +// This is a relatively complex sketch, not recommended as a first +// introduction to IoTa. Try running some of the other, simpler sketches +// first before attempting to adapt this code. Additionally, some of the +// CC3000 helper and status functions have been pared back in this code. +// See other example sketches for more complete and verbose debugging info +// during your initial IoTa experiments. + +// Configurable globals and defines. Edit to your needs. ------------------- + +// CC3000 interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +#define ADAFRUIT_CC3000_VBAT 5 // These can be +#define ADAFRUIT_CC3000_CS 10 // any two pins +// Hardware SPI required for remaining pins. +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000( + ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); + +// WiFi access point credentials +#define WLAN_SSID "myNetwork" // 32 characters max +#define WLAN_PASS "myPassword" +#define WLAN_SECURITY WLAN_SEC_WPA2 // WLAN_SEC_UNSEC/WLAN_SEC_WEP/WLAN_SEC_WPA/WLAN_SEC_WPA2 + +const char PROGMEM + // Twitter application credentials -- see notes above -- DO NOT SHARE. + consumer_key[] = "PUT_YOUR_CONSUMER_KEY_HERE", + access_token[] = "PUT_YOUR_ACCESS_TOKEN_HERE", + signingKey[] = "PUT_YOUR_CONSUMER_SECRET_HERE" // Consumer secret + "&" "PUT_YOUR_ACCESS_TOKEN_SECRET_HERE", // Access token secret + // The ampersand is intentional -- do not delete! + + // Other globals. You probably won't need to change these. --------------- + endpoint[] = "/1.1/statuses/update.json", + agent[] = "Arduino-Tweet-Test v1.0"; +const char + host[] = "api.twitter.com"; +const unsigned long + dhcpTimeout = 60L * 1000L, // Max time to wait for address from DHCP + connectTimeout = 15L * 1000L, // Max time to wait for server connection + responseTimeout = 15L * 1000L; // Max time to wait for data from server +unsigned long + currentTime = 0L; +Adafruit_CC3000_Client + client; // For WiFi connections + +// Similar to F(), but for PROGMEM string pointers rather than literals +#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr + +// -------------------------------------------------------------------------- + +void setup(void) { + + uint32_t ip = 0L, t; + + Serial.begin(115200); + + Serial.print(F("Hello! Initializing CC3000...")); + if(!cc3000.begin()) hang(F("failed. Check your wiring?")); + + uint16_t firmware = checkFirmwareVersion(); + if ((firmware != 0x113) && (firmware != 0x118)) { + hang(F("Wrong firmware version!")); + } + + Serial.print(F("OK\r\nDeleting old connection profiles...")); + if(!cc3000.deleteProfiles()) hang(F("failed.")); + + Serial.print(F("OK\r\nConnecting to network...")); + /* NOTE: Secure connections are not available in 'Tiny' mode! */ + if(!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) hang(F("Failed!")); + + Serial.print(F("OK\r\nRequesting address from DHCP server...")); + for(t=millis(); !cc3000.checkDHCP() && ((millis() - t) < dhcpTimeout); delay(100)); + if(!cc3000.checkDHCP()) hang(F("failed")); + Serial.println(F("OK")); + + while(!displayConnectionDetails()); + + // Get initial time from time server (make a few tries if needed) + for(uint8_t i=0; (i<5) && !(currentTime = getTime()); delay(5000L), i++); + + // Initialize crypto library + Sha1.initHmac_P((uint8_t *)signingKey, sizeof(signingKey) - 1); +} + +// On error, print PROGMEM string to serial monitor and stop +void hang(const __FlashStringHelper *str) { + Serial.println(str); + for(;;); +} + +uint8_t countdown = 23; // Countdown to next time server query (once per ~24hr) + +void loop() { + + unsigned long t = millis(); + + // For now this just issues a fixed tweet. In reality, you might want to + // read from some sensors or that sort of thing, then nicely format the + // results into a buffer to be passed to the sendTweet() function. + sendTweet("Adafruit IoTa test. Tweet directly from Arduino...no proxy, no wires! http://www.adafruit.com/products/1469"); + + // Delay remainder of 1 hour (takes tweeting time into account) + Serial.println("Waiting ~1 hour..."); + delay((60L * 60L * 1000L) - (millis() - t)); + currentTime += 60L * 60L * 1000L; + + if(!countdown) { // 24 hours elapsed? + if((t = getTime())) { // Synchronize time if server contacted + currentTime = t; + countdown = 23; // and reset counter + } + } else countdown--; +} + +// Returns true on success, false on error +boolean sendTweet(char *msg) { // 140 chars max! No checks made here. + uint8_t *in, out, i; + char nonce[9], // 8 random digits + NUL + searchTime[11], // 32-bit int + NUL + b64[29]; + unsigned long startTime, t, ip; + static const char PROGMEM b64chars[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + startTime = millis(); + + sprintf(nonce, "%04x%04x", random() ^ currentTime, startTime ^ currentTime); + sprintf(searchTime, "%ld", currentTime); + + // A dirty hack makes the Oauth song and dance MUCH simpler within the + // Arduino's limited RAM and CPU. A proper general-purpose implementation + // would be expected to URL-encode keys and values (from the complete list + // of POST parameters and authentication values), sort by encoded key, + // concatenate and URL-encode the combined result. Sorting is avoided + // because every POST this program performs has exactly the same set of + // parameters, so we've pre-sorted the list as it appears here. Keys + // (and many values) are pre-encoded because they never change; many are + // passed through verbatim because the format is known to not require + // encoding. Most reside in PROGMEM, not RAM. This is bending a LOT of + // rules of Good and Proper Authentication and would land you an 'F' in + // Comp Sci class, but it handles the required task and is VERY compact. + Sha1.print(F("POST&http%3A%2F%2F")); + Sha1.print(host); + urlEncode(Sha1, endpoint, true, false); + Sha1.print(F("&oauth_consumer_key%3D")); + Sha1.print(F2(consumer_key)); + Sha1.print(F("%26oauth_nonce%3D")); + Sha1.print(nonce); + Sha1.print(F("%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D")); + Sha1.print(searchTime); + Sha1.print(F("%26oauth_token%3D")); + Sha1.print(F2(access_token)); + Sha1.print(F("%26oauth_version%3D1.0%26status%3D")); + urlEncode(Sha1, msg, false, true); + + // base64-encode SHA-1 hash output. This is NOT a general-purpose base64 + // encoder! It's stripped down for the fixed-length hash -- always 20 + // bytes input, always 27 chars output + '='. + for(in = Sha1.resultHmac(), out=0; ; in += 3) { // octets to sextets + b64[out++] = in[0] >> 2; + b64[out++] = ((in[0] & 0x03) << 4) | (in[1] >> 4); + if(out >= 26) break; + b64[out++] = ((in[1] & 0x0f) << 2) | (in[2] >> 6); + b64[out++] = in[2] & 0x3f; + } + b64[out] = (in[1] & 0x0f) << 2; + // Remap sextets to base64 ASCII chars + for(i=0; i<=out; i++) b64[i] = pgm_read_byte(&b64chars[b64[i]]); + b64[i++] = '='; + b64[i++] = 0; + + // Hostname lookup + Serial.print(F("Locating Twitter server...")); + cc3000.getHostByName((char *)host, &ip); + + // Connect to numeric IP + Serial.print(F("OK\r\nConnecting to server...")); + t = millis(); + do { + client = cc3000.connectTCP(ip, 80); + } while((!client.connected()) && + ((millis() - t) < connectTimeout)); + + if(client.connected()) { // Success! + Serial.print(F("OK\r\nIssuing HTTP request...")); + + // Unlike the hash prep, parameters in the HTTP request don't require sorting. + client.fastrprint(F("POST ")); + client.fastrprint(F2(endpoint)); + client.fastrprint(F(" HTTP/1.1\r\nHost: ")); + client.fastrprint(host); + client.fastrprint(F("\r\nUser-Agent: ")); + client.fastrprint(F2(agent)); + client.fastrprint(F("\r\nConnection: close\r\n" + "Content-Type: application/x-www-form-urlencoded;charset=UTF-8\r\n" + "Content-Length: ")); + client.print(7 + encodedLength(msg)); + client.fastrprint(F("\r\nAuthorization: Oauth oauth_consumer_key=\"")); + client.fastrprint(F2(consumer_key)); + client.fastrprint(F("\", oauth_nonce=\"")); + client.fastrprint(nonce); + client.fastrprint(F("\", oauth_signature=\"")); + urlEncode(client, b64, false, false); + client.fastrprint(F("\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"")); + client.fastrprint(searchTime); + client.fastrprint(F("\", oauth_token=\"")); + client.fastrprint(F2(access_token)); + client.fastrprint(F("\", oauth_version=\"1.0\"\r\n\r\nstatus=")); + urlEncode(client, msg, false, false); + + Serial.print(F("OK\r\nAwaiting response...")); + int c = 0; + // Dirty trick: instead of parsing results, just look for opening + // curly brace indicating the start of a successful JSON response. + while(((c = timedRead()) > 0) && (c != '{')); + if(c == '{') Serial.println(F("success!")); + else if(c < 0) Serial.println(F("timeout")); + else Serial.println(F("error (invalid Twitter credentials?)")); + client.close(); + return (c == '{'); + } else { // Couldn't contact server + Serial.println(F("failed")); + return false; + } +} + +// Helper functions. -------------------------------------------------------- + +uint16_t checkFirmwareVersion(void) { + uint8_t major, minor; + uint16_t version = 0; + +#ifndef CC3000_TINY_DRIVER + if(!cc3000.getFirmwareVersion(&major, &minor)) { + Serial.println(F("Unable to retrieve the firmware version!\r\n")); + } else { + Serial.print(F("Firmware V. : ")); + Serial.print(major); Serial.print(F(".")); Serial.println(minor); + version = ((uint16_t)major << 8) | minor; + } +#endif + return version; +} + +bool displayConnectionDetails(void) { + uint32_t addr, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&addr, &netmask, &gateway, &dhcpserv, &dnsserv)) + return false; + + Serial.print(F("IP Addr: ")); cc3000.printIPdotsRev(addr); + Serial.print(F("\r\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\r\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\r\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\r\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; +} + +// Read from client stream with a 5 second timeout. Although an +// essentially identical method already exists in the Stream() class, +// it's declared private there...so this is a local copy. +int timedRead(void) { + unsigned long start = millis(); + while((!client.available()) && ((millis() - start) < responseTimeout)); + return client.read(); // -1 on timeout +} + +// For URL-encoding functions below +static const char PROGMEM hexChar[] = "0123456789ABCDEF"; + +// URL-encoding output function for Print class. +// Input from RAM or PROGMEM (flash). Double-encoding is a weird special +// case for Oauth (encoded strings get encoded a second time). +void urlEncode( + Print &p, // EthernetClient, Sha1, etc. + const char *src, // String to be encoded + boolean progmem, // If true, string is in PROGMEM (else RAM) + boolean x2) // If true, "double encode" parenthesis +{ + uint8_t c; + + while((c = (progmem ? pgm_read_byte(src) : *src))) { + if(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || + ((c >= '0') && (c <= '9')) || strchr_P(PSTR("-_.~"), c)) { + p.write(c); + } else { + if(x2) p.print("%25"); + else p.write('%'); + p.write(pgm_read_byte(&hexChar[c >> 4])); + p.write(pgm_read_byte(&hexChar[c & 15])); + } + src++; + } +} + +// Returns would-be length of encoded string, without actually encoding +int encodedLength(char *src) { + uint8_t c; + int len = 0; + + while((c = *src++)) { + len += (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || + ((c >= '0') && (c <= '9')) || strchr_P(PSTR("-_.~"), c)) ? 1 : 3; + } + + return len; +} + +// Minimalist time server query; adapted from Adafruit Gutenbird sketch, +// which in turn has roots in Arduino UdpNTPClient tutorial. +unsigned long getTime(void) { + + uint8_t buf[48]; + unsigned long ip, startTime, t = 0L; + + Serial.print(F("Locating time server...")); + + // Hostname to IP lookup; use NTP pool (rotates through servers) + if(cc3000.getHostByName("pool.ntp.org", &ip)) { + static const char PROGMEM + timeReqA[] = { 227, 0, 6, 236 }, + timeReqB[] = { 49, 78, 49, 52 }; + + Serial.println(F("found\r\nConnecting to time server...")); + startTime = millis(); + do { + client = cc3000.connectUDP(ip, 123); + } while((!client.connected()) && + ((millis() - startTime) < connectTimeout)); + + if(client.connected()) { + Serial.print(F("connected!\r\nIssuing request...")); + + // Assemble and issue request packet + memset(buf, 0, sizeof(buf)); + memcpy_P( buf , timeReqA, sizeof(timeReqA)); + memcpy_P(&buf[12], timeReqB, sizeof(timeReqB)); + client.write(buf, sizeof(buf)); + + Serial.print(F("OK\r\nAwaiting response...")); + memset(buf, 0, sizeof(buf)); + startTime = millis(); + while((!client.available()) && + ((millis() - startTime) < responseTimeout)); + if(client.available()) { + client.read(buf, sizeof(buf)); + t = (((unsigned long)buf[40] << 24) | + ((unsigned long)buf[41] << 16) | + ((unsigned long)buf[42] << 8) | + (unsigned long)buf[43]) - 2208988800UL; + Serial.println(F("success!")); + } + client.close(); + } + } + if(!t) Serial.println(F("error")); + return t; +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SmartConfigCreate/SmartConfigCreate.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SmartConfigCreate/SmartConfigCreate.ino new file mode 100755 index 0000000000..1c84a33ed4 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SmartConfigCreate/SmartConfigCreate.ino @@ -0,0 +1,225 @@ +/*************************************************** + This is an example for the Adafruit CC3000 Wifi Breakout & Shield + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried & Kevin Townsend for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +/* This sketch will attempt to establish an AP connection + using the SmartConfig tool, and save the connection + details for later use (with SmartConfigReconnect, etc.). + + If a connection is successfully established, the data + will be stored as a connection profile in non-volatile + memory on the CC3000, and the device will be configured + to automatically connect to this profile on startup. + + To see how to safely use the CC3000 without erasing + this SmartConfig data please consult the + SmartConfigReconnect sketch, which uses an optional flag + in Adafruit_CC3000.begin() to avoid erasing the + connection profiles from memory, as well as a new + .reconnect function. + + Using other non SmartConfig example sketches will + erase the connection profile data on startup, but + this sketch combined with SmartConfigReconnect hopefully + illustrate how to use SmartConfig when hard-coded + connection details aren't appropriate. + + SmartConfig is still beta and kind of works but is not fully + vetted! It might not work on all networks! +*/ + +#include +#include +#include +#include +#include "utility/debug.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 + +#define DEVICE_NAME "CC3000" + +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, + ADAFRUIT_CC3000_IRQ, + ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); + +// The SSID & Password are retrieved via the Smartconfig app + +/**************************************************************************/ +/*! + @brief Sets up the HW and the CC3000 module (called automatically + on startup) +*/ +/**************************************************************************/ +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + displayDriverMode(); + Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); + + /* Initialise the module, deleting any existing profile data (which */ + /* is the default behaviour) */ + Serial.println(F("\nInitialising the CC3000 ...")); + if (!cc3000.begin(false)) + { + Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + while(1); + } + + uint16_t firmware = checkFirmwareVersion(); + if ((firmware != 0x113) && (firmware != 0x118)) { + Serial.println(F("Wrong firmware version!")); + for(;;); + } + displayMACAddress(); + + /* Try to use the smart config app (no AES encryption), saving */ + /* the connection details if we succeed */ + Serial.println(F("Waiting for a SmartConfig connection (~60s) ...")); + if (!cc3000.startSmartConfig(DEVICE_NAME)) + { + Serial.println(F("SmartConfig failed")); + while(1); + } + + Serial.println(F("Saved connection details and connected to AP!")); + + /* Wait for DHCP to complete */ + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) + { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (! displayConnectionDetails()) { + delay(1000); + } + + Serial.println(F("\nTo use these connection details be sure to use")); + Serial.println(F("'.begin(false, true, DEVICE_NAME)' with your Adafruit_CC3000")); + Serial.println(F("code instead of the default '.begin()' values!")); + + /* You need to make sure to clean up after yourself or the CC3000 can freak out */ + /* the next time your try to connect ... */ + Serial.println(F("\nClosing the connection")); + cc3000.disconnect(); +} + +void loop(void) +{ + delay(1000); +} + + +/**************************************************************************/ +/*! + @brief Displays the driver mode (tiny of normal), and the buffer + size if tiny mode is not being used + + @note The buffer size and driver mode are defined in cc3000_common.h +*/ +/**************************************************************************/ +void displayDriverMode(void) +{ + #ifdef CC3000_TINY_DRIVER + Serial.println(F("CC3000 is configure in 'Tiny' mode")); + #else + Serial.print(F("RX Buffer : ")); + Serial.print(CC3000_RX_BUFFER_SIZE); + Serial.println(F(" bytes")); + Serial.print(F("TX Buffer : ")); + Serial.print(CC3000_TX_BUFFER_SIZE); + Serial.println(F(" bytes")); + #endif +} + +/**************************************************************************/ +/*! + @brief Tries to read the CC3000's internal firmware patch ID +*/ +/**************************************************************************/ +uint16_t checkFirmwareVersion(void) +{ + uint8_t major, minor; + uint16_t version; + +#ifndef CC3000_TINY_DRIVER + if(!cc3000.getFirmwareVersion(&major, &minor)) + { + Serial.println(F("Unable to retrieve the firmware version!\r\n")); + version = 0; + } + else + { + Serial.print(F("Firmware V. : ")); + Serial.print(major); Serial.print(F(".")); Serial.println(minor); + version = major; version <<= 8; version |= minor; + } +#endif + return version; +} + +/**************************************************************************/ +/*! + @brief Tries to read the 6-byte MAC address of the CC3000 module +*/ +/**************************************************************************/ +void displayMACAddress(void) +{ + uint8_t macAddress[6]; + + if(!cc3000.getMacAddress(macAddress)) + { + Serial.println(F("Unable to retrieve MAC Address!\r\n")); + } + else + { + Serial.print(F("MAC Address : ")); + cc3000.printHex((byte*)&macAddress, 6); + } +} + +/**************************************************************************/ +/*! + @brief Tries to read the IP address and other connection details +*/ +/**************************************************************************/ +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SmartConfigReconnect/SmartConfigReconnect.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SmartConfigReconnect/SmartConfigReconnect.ino new file mode 100755 index 0000000000..18e311b7bc --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/SmartConfigReconnect/SmartConfigReconnect.ino @@ -0,0 +1,146 @@ +/*************************************************** + This is an example for the Adafruit CC3000 Wifi Breakout & Shield + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried & Kevin Townsend for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +/* This sketch attempts to re-connect to an AP using + data from a previous SmartConfig session (i.e. from + the SmartConfigCreate sketch!). + + It will attempt to do the following: + + * Initialization the CC3000 + * Re-connect using previous SmartConfig data (see SmartConfigCreate) + * DHCP printout + * Disconnect + + If the connection fails, there are two likely + explanations: + + 1.) You haven't run the SmartConfigCreate sketch and + successfully connected to a network, since this + is the process that 'saves' the AP details to the + device + 2.) You've used one of the other non SmartConfig + sketches, which erase all stored profiles from + the CC3000 memory in order to manually establish + a connection using hard coded values. (This sketch + uses an optional flag in the Adafruit_CC3000.begin + function to avoid this erasure process!). + + SmartConfig is still beta and kind of works but is not fully + vetted! It might not work on all networks! +*/ + +#include +#include +#include +#include +#include "utility/debug.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 + +#define DEVICE_NAME "CC3000" + +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, + ADAFRUIT_CC3000_IRQ, + ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); + +// We get the SSID & Password from memory thanks to SmartConfigCreate! + +/**************************************************************************/ +/*! + @brief Sets up the HW and the CC3000 module (called automatically + on startup) +*/ +/**************************************************************************/ +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + /* Try to reconnect using the details from SmartConfig */ + /* This basically just resets the CC3000, and the auto connect */ + /* tries to do it's magic if connections details are found */ + Serial.println(F("Trying to reconnect using SmartConfig values ...")); + + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + /* !!! Note the additional arguments in .begin that tell the !!! */ + /* !!! app NOT to deleted previously stored connection details !!! */ + /* !!! and reconnected using the connection details in memory! !!! */ + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + if (!cc3000.begin(false, true, DEVICE_NAME)) + { + Serial.println(F("Unable to re-connect!? Did you run the SmartConfigCreate")); + Serial.println(F("sketch to store your connection details?")); + while(1); + } + + /* Round of applause! */ + Serial.println(F("Reconnected!")); + + /* Wait for DHCP to complete */ + Serial.println(F("\nRequesting DHCP")); + while (!cc3000.checkDHCP()) { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (! displayConnectionDetails()) { + delay(1000); + } + + /* This is where you'd do your own thing! */ + + /* You need to make sure to clean up after yourself or the CC3000 can freak out */ + /* the next time your try to connect ... */ + Serial.println(F("\nClosing the connection")); + cc3000.disconnect(); +} + +void loop(void) +{ + delay(1000); +} + +/**************************************************************************/ +/*! + @brief Tries to read the IP address and other connection details +*/ +/**************************************************************************/ +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/WebClient/WebClient.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/WebClient/WebClient.ino new file mode 100755 index 0000000000..ae7d596540 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/WebClient/WebClient.ino @@ -0,0 +1,224 @@ +/*************************************************** + This is an example for the Adafruit CC3000 Wifi Breakout & Shield + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried & Kevin Townsend for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + + /* +This example does a test of the TCP client capability: + * Initialization + * Optional: SSID scan + * AP connection + * DHCP printout + * DNS lookup + * Optional: Ping + * Connect to website and print out webpage contents + * Disconnect +SmartConfig is still beta and kind of works but is not fully vetted! +It might not work on all networks! +*/ +#include +#include +#include +#include +#include "utility/debug.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); // you can change this clock speed + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + +#define IDLE_TIMEOUT_MS 3000 // Amount of time to wait (in milliseconds) with no data + // received before closing the connection. If you know the server + // you're accessing is quick to respond, you can reduce this value. + +// What page to grab! +#define WEBSITE "www.adafruit.com" +#define WEBPAGE "/testwifi/index.html" + + +/**************************************************************************/ +/*! + @brief Sets up the HW and the CC3000 module (called automatically + on startup) +*/ +/**************************************************************************/ + +uint32_t ip; + +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); + + /* Initialise the module */ + Serial.println(F("\nInitializing...")); + if (!cc3000.begin()) + { + Serial.println(F("Couldn't begin()! Check your wiring?")); + while(1); + } + + // Optional SSID scan + // listSSIDResults(); + + Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID); + if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + while(1); + } + + Serial.println(F("Connected!")); + + /* Wait for DHCP to complete */ + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) + { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (! displayConnectionDetails()) { + delay(1000); + } + + ip = 0; + // Try looking up the website's IP address + Serial.print(WEBSITE); Serial.print(F(" -> ")); + while (ip == 0) { + if (! cc3000.getHostByName(WEBSITE, &ip)) { + Serial.println(F("Couldn't resolve!")); + } + delay(500); + } + + cc3000.printIPdotsRev(ip); + + // Optional: Do a ping test on the website + /* + Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("..."); + replies = cc3000.ping(ip, 5); + Serial.print(replies); Serial.println(F(" replies")); + */ + + /* Try connecting to the website. + Note: HTTP/1.1 protocol is used to keep the server from closing the connection before all data is read. + */ + Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80); + if (www.connected()) { + www.fastrprint(F("GET ")); + www.fastrprint(WEBPAGE); + www.fastrprint(F(" HTTP/1.1\r\n")); + www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n")); + www.fastrprint(F("\r\n")); + www.println(); + } else { + Serial.println(F("Connection failed")); + return; + } + + Serial.println(F("-------------------------------------")); + + /* Read data until either the connection is closed, or the idle timeout is reached. */ + unsigned long lastRead = millis(); + while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) { + while (www.available()) { + char c = www.read(); + Serial.print(c); + lastRead = millis(); + } + } + www.close(); + Serial.println(F("-------------------------------------")); + + /* You need to make sure to clean up after yourself or the CC3000 can freak out */ + /* the next time your try to connect ... */ + Serial.println(F("\n\nDisconnecting")); + cc3000.disconnect(); + +} + +void loop(void) +{ + delay(1000); +} + +/**************************************************************************/ +/*! + @brief Begins an SSID scan and prints out all the visible networks +*/ +/**************************************************************************/ + +void listSSIDResults(void) +{ + uint8_t valid, rssi, sec, index; + char ssidname[33]; + + index = cc3000.startSSIDscan(); + + Serial.print(F("Networks found: ")); Serial.println(index); + Serial.println(F("================================================")); + + while (index) { + index--; + + valid = cc3000.getNextSSID(&rssi, &sec, ssidname); + + Serial.print(F("SSID Name : ")); Serial.print(ssidname); + Serial.println(); + Serial.print(F("RSSI : ")); + Serial.println(rssi); + Serial.print(F("Security Mode: ")); + Serial.println(sec); + Serial.println(); + } + Serial.println(F("================================================")); + + cc3000.stopSSIDscan(); +} + +/**************************************************************************/ +/*! + @brief Tries to read the IP address and other connection details +*/ +/**************************************************************************/ +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/buildtest/buildtest.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/buildtest/buildtest.ino new file mode 100755 index 0000000000..e530a02ace --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/buildtest/buildtest.ino @@ -0,0 +1,320 @@ +/*************************************************** + This is an example for the Adafruit CC3000 Wifi Breakout & Shield + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Kevin Townsend & Limor Fried for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +/* + +This example does a full test of core connectivity: +* Initialization +* SSID Scan +* AP connection +* DHCP printout +* DNS lookup +* Ping +* Disconnect +It's a good idea to run this sketch when first setting up the +module. + +*/ + +#include +#include +#include +#include +#include "utility/debug.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); // you can change this clock speed but DI + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + + + +/**************************************************************************/ +/*! + @brief Sets up the HW and the CC3000 module (called automatically + on startup) +*/ +/**************************************************************************/ +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + displayDriverMode(); + Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); + + /* Initialise the module */ + Serial.println(F("\nInitialising the CC3000 ...")); + if (!cc3000.begin()) + { + Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + while(1); + } + + /* Optional: Update the Mac Address to a known value */ +/* + uint8_t macAddress[6] = { 0x08, 0x00, 0x28, 0x01, 0x79, 0xB7 }; + if (!cc3000.setMacAddress(macAddress)) + { + Serial.println(F("Failed trying to update the MAC address")); + while(1); + } +*/ + + uint16_t firmware = checkFirmwareVersion(); + if (firmware < 0x113) { + Serial.println(F("Wrong firmware version!")); + for(;;); + } + + displayMACAddress(); + + /* Optional: Get the SSID list (not available in 'tiny' mode) */ +#ifndef CC3000_TINY_DRIVER + listSSIDResults(); +#endif + + /* Delete any old connection data on the module */ + Serial.println(F("\nDeleting old connection profiles")); + if (!cc3000.deleteProfiles()) { + Serial.println(F("Failed!")); + while(1); + } + + /* Optional: Set a static IP address instead of using DHCP. + Note that the setStaticIPAddress function will save its state + in the CC3000's internal non-volatile memory and the details + will be used the next time the CC3000 connects to a network. + This means you only need to call the function once and the + CC3000 will remember the connection details. To switch back + to using DHCP, call the setDHCP() function (again only needs + to be called once). + */ + /* + uint32_t ipAddress = cc3000.IP2U32(192, 168, 1, 19); + uint32_t netMask = cc3000.IP2U32(255, 255, 255, 0); + uint32_t defaultGateway = cc3000.IP2U32(192, 168, 1, 1); + uint32_t dns = cc3000.IP2U32(8, 8, 4, 4); + if (!cc3000.setStaticIPAddress(ipAddress, netMask, defaultGateway, dns)) { + Serial.println(F("Failed to set static IP!")); + while(1); + } + */ + /* Optional: Revert back from static IP addres to use DHCP. + See note for setStaticIPAddress above, this only needs to be + called once and will be remembered afterwards by the CC3000. + */ + /* + if (!cc3000.setDHCP()) { + Serial.println(F("Failed to set DHCP!")); + while(1); + } + */ + + /* Attempt to connect to an access point */ + char *ssid = WLAN_SSID; /* Max 32 chars */ + Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid); + + /* NOTE: Secure connections are not available in 'Tiny' mode! + By default connectToAP will retry indefinitely, however you can pass an + optional maximum number of retries (greater than zero) as the fourth parameter. + */ + if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + while(1); + } + + Serial.println(F("Connected!")); + + /* Wait for DHCP to complete */ + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) + { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (! displayConnectionDetails()) { + delay(1000); + } + +#ifndef CC3000_TINY_DRIVER + /* Try looking up www.adafruit.com */ + uint32_t ip = 0; + Serial.print(F("www.adafruit.com -> ")); + while (ip == 0) { + if (! cc3000.getHostByName("www.adafruit.com", &ip)) { + Serial.println(F("Couldn't resolve!")); + } + delay(500); + } + cc3000.printIPdotsRev(ip); + + /* Do a quick ping test on adafruit.com */ + Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("..."); + uint8_t replies = cc3000.ping(ip, 5); + Serial.print(replies); Serial.println(F(" replies")); + if (replies) + Serial.println(F("Ping successful!")); +#endif + + /* You need to make sure to clean up after yourself or the CC3000 can freak out */ + /* the next time you try to connect ... */ + Serial.println(F("\n\nClosing the connection")); + cc3000.disconnect(); +} + +void loop(void) +{ + delay(1000); +} + +/**************************************************************************/ +/*! + @brief Displays the driver mode (tiny of normal), and the buffer + size if tiny mode is not being used + + @note The buffer size and driver mode are defined in cc3000_common.h +*/ +/**************************************************************************/ +void displayDriverMode(void) +{ + #ifdef CC3000_TINY_DRIVER + Serial.println(F("CC3000 is configure in 'Tiny' mode")); + #else + Serial.print(F("RX Buffer : ")); + Serial.print(CC3000_RX_BUFFER_SIZE); + Serial.println(F(" bytes")); + Serial.print(F("TX Buffer : ")); + Serial.print(CC3000_TX_BUFFER_SIZE); + Serial.println(F(" bytes")); + #endif +} + +/**************************************************************************/ +/*! + @brief Tries to read the CC3000's internal firmware patch ID +*/ +/**************************************************************************/ +uint16_t checkFirmwareVersion(void) +{ + uint8_t major, minor; + uint16_t version; + +#ifndef CC3000_TINY_DRIVER + if(!cc3000.getFirmwareVersion(&major, &minor)) + { + Serial.println(F("Unable to retrieve the firmware version!\r\n")); + version = 0; + } + else + { + Serial.print(F("Firmware V. : ")); + Serial.print(major); Serial.print(F(".")); Serial.println(minor); + version = major; version <<= 8; version |= minor; + } +#endif + return version; +} + +/**************************************************************************/ +/*! + @brief Tries to read the 6-byte MAC address of the CC3000 module +*/ +/**************************************************************************/ +void displayMACAddress(void) +{ + uint8_t macAddress[6]; + + if(!cc3000.getMacAddress(macAddress)) + { + Serial.println(F("Unable to retrieve MAC Address!\r\n")); + } + else + { + Serial.print(F("MAC Address : ")); + cc3000.printHex((byte*)&macAddress, 6); + } +} + + +/**************************************************************************/ +/*! + @brief Tries to read the IP address and other connection details +*/ +/**************************************************************************/ +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} + +/**************************************************************************/ +/*! + @brief Begins an SSID scan and prints out all the visible networks +*/ +/**************************************************************************/ + +void listSSIDResults(void) +{ + uint8_t valid, rssi, sec, index; + char ssidname[33]; + + index = cc3000.startSSIDscan(); + + Serial.print(F("Networks found: ")); Serial.println(index); + Serial.println(F("================================================")); + + while (index) { + index--; + + valid = cc3000.getNextSSID(&rssi, &sec, ssidname); + + Serial.print(F("SSID Name : ")); Serial.print(ssidname); + Serial.println(); + Serial.print(F("RSSI : ")); + Serial.println(rssi); + Serial.print(F("Security Mode: ")); + Serial.println(sec); + Serial.println(); + } + Serial.println(F("================================================")); + + cc3000.stopSSIDscan(); +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_12/driverpatch_1_12.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_12/driverpatch_1_12.ino new file mode 100755 index 0000000000..293bbbfecf --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_12/driverpatch_1_12.ino @@ -0,0 +1,347 @@ +// This driver patcher will take 1.11.1 firmware modules up to 1.12 +// It seems to work, but it is 100% not guaranteed! Based on the TI driver patch +// code for MSP430 - ladyada + +// If you fail halfway thru update, you may have to restart and you may have lost +// the MAC address in EEPROM so before you begin, write down your mac address! +// You can re-burn the mac address in the buildtest example + +#include +#include +#include +#include +#include + +#include "utility/debug.h" +#include "utility/nvmem.h" +#include "driverpatchinc.h" + +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +#define ADAFRUIT_CC3000_CS 10 +#define ADAFRUIT_CC3000_VBAT 5 + +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT); + +/**************************************************************************/ +/*! + @brief Displays the driver mode (tiny of normal), and the buffer + size if tiny mode is not being used + + @note The buffer size and driver mode are defined in cc3000_common.h +*/ +/**************************************************************************/ +void displayDriverMode(void) +{ + #ifdef CC3000_TINY_DRIVER + Serial.println(F("CC3000 is configure in 'Tiny' mode")); + #else + Serial.print(F("RX Buffer : ")); + Serial.print(CC3000_RX_BUFFER_SIZE); + Serial.println(F(" bytes")); + Serial.print(F("TX Buffer : ")); + Serial.print(CC3000_TX_BUFFER_SIZE); + Serial.println(F(" bytes")); + #endif +} + +/**************************************************************************/ +/*! + @brief Tries to read the CC3000's internal firmware patch ID +*/ +/**************************************************************************/ +void displayFirmwareVersion(void) +{ + #ifndef CC3000_TINY_DRIVER + uint8_t major, minor; + + if(!cc3000.getFirmwareVersion(&major, &minor)) + { + Serial.println(F("Unable to retrieve the firmware version!\r\n")); + } + else + { + Serial.print(F("Firmware V. : ")); + Serial.print(major); Serial.print(F(".")); Serial.println(minor); + } + #endif +} + +/**************************************************************************/ +/*! + @brief Tries to read the 6-byte MAC address of the CC3000 module +*/ +/**************************************************************************/ +boolean MACvalid = false; +// array to store MAC address from EEPROM +uint8_t cMacFromEeprom[MAC_ADDR_LEN]; +void displayMACAddress(void) +{ + if(!cc3000.getMacAddress(cMacFromEeprom)) + { + Serial.println(F("Unable to retrieve MAC Address!\r\n")); + MACvalid = false; + } + else + { + Serial.print(F("MAC Address : ")); + cc3000.printHex((byte*)&cMacFromEeprom, 6); + MACvalid = true; + } +} + + + +/**************************************************************************/ +/*! + @brief Sets up the HW and the CC3000 module (called automatically + on startup) +*/ +/**************************************************************************/ + +uint8_t ucStatus_Dr, return_status = 0xFF; +uint8_t counter = 0; + +// array to store RM parameters from EEPROM +unsigned char cRMParamsFromEeprom[128]; + + +// 2 dim array to store address and length of new FAT +uint16_t aFATEntries[2][NVMEM_RM_FILEID + 1] = +/* address */ {{0x50, 0x1f0, 0x1390, 0x0390, 0x2390, 0x4390, 0x6390, 0x63a0, 0x63b0, 0x63f0, 0x6430, 0x6830}, +/* length */ {0x1a0, 0x1a0, 0x1000, 0x1000, 0x2000, 0x2000, 0x10, 0x10, 0x40, 0x40, 0x400, 0x200 }}; +/* 0. NVS */ +/* 1. NVS Shadow */ +/* 2. Wireless Conf */ +/* 3. Wireless Conf Shadow */ +/* 4. BT (WLAN driver) Patches */ +/* 5. WiLink (Firmware) Patches */ +/* 6. MAC addr */ +/* 7. Frontend Vars */ +/* 8. IP config */ +/* 9. IP config Shadow */ +/* 10. Bootloader Patches */ +/* 11. Radio Module params */ +/* 12. AES128 for smart config */ +/* 13. user file */ +/* 14. user file */ +/* 15. user file */ + + +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + Serial.println(F("Hit any key & return to start")); + while (!Serial.available()); + + pinMode(9, OUTPUT); + pinMode(8, OUTPUT); + pinMode(7, OUTPUT); + pinMode(6, OUTPUT); + digitalWrite(9, LOW); + digitalWrite(8, LOW); + digitalWrite(7, LOW); + digitalWrite(6, LOW); + + displayDriverMode(); + displayFreeRam(); + + /* Initialise the module */ + Serial.println(F("\nInitialising the CC3000 ...")); + if (!cc3000.begin(2)) // init with NO patches! + { + Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + while(1); + } + + //displayFirmwareVersion(); + displayMACAddress(); + + return_status = 1; + uint8_t index; + uint8_t *pRMParams; + + while ((return_status) && (counter < 3)) { + // read RM parameters + // read in 16 parts to work with tiny driver + + return_status = 0; + pRMParams = cRMParamsFromEeprom; + + for (index = 0; index < 16; index++) { + return_status |= nvmem_read(NVMEM_RM_FILEID, 8, 8*index, pRMParams); + Serial.print(F("\n\rRead NVRAM $")); Serial.print(8*index); Serial.print("\t"); + for(uint8_t x=0; x<8; x++) { + Serial.print("0x"); Serial.print(pRMParams[x], HEX); Serial.print(", "); + } + pRMParams += 8; + } + counter++; + } + // if RM file is not valid, load the default one + if (counter == 3) { + Serial.println(F("\n\rLoad default params")); + pRMParams = (uint8_t *)cRMdefaultParams; + } else { + Serial.println(F("\n\rLoad EEPROM params")); + pRMParams = cRMParamsFromEeprom; + if (EEPROM.read(0) == 0xFF) { + for (uint8_t e=0; e<128; e++) { + EEPROM.write(e, cRMParamsFromEeprom[e]); + } + Serial.println(F("Backed up to eeprom!")); + } + } + + + return_status = 1; + + while (return_status) { + // write new FAT + return_status = fat_write_content(aFATEntries[0], aFATEntries[1]); + Serial.print(F("Wrote FAT entries: ")); Serial.println(return_status, DEC); + } + + //Serial.println(F("Stopping...")); + //cc3000.stop(); + + //Serial.println(F("\nInitialising the CC3000 ...")); + + //if (!cc3000.begin(2)) // no patches! + //{ + // Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + // while(1); + //} + + return_status = 1; + + Serial.println(F("Write params")); + + while (return_status) { + // write RM parameters + // write in 4 parts to work with tiny driver + + return_status = 0; + + for (index = 0; index < 4; index++) { + return_status |= nvmem_write(NVMEM_RM_FILEID, 32, 32*index, (pRMParams + 32*index)); + Serial.println(F("Wrote 32 bytes to NVRAM")); + } + } + Serial.println(F("Wrote params")); + + return_status = 1; + + // write back the MAC address, only if exist + if (MACvalid) { + // zero out MCAST bit if set + cMacFromEeprom[0] &= 0xfe; + while (return_status) { + return_status = nvmem_set_mac_address(cMacFromEeprom); + } + } + + ucStatus_Dr = 1; + Serial.println(F("Writing driver patch")); + + while (ucStatus_Dr) { + //writing driver patch to EEPRROM - PROTABLE CODE + // Note that the array itself is changing between the different Service Packs + ucStatus_Dr = nvmem_write_patch(NVMEM_WLAN_DRIVER_SP_FILEID, drv_length, wlan_drv_patch); + } + + + Serial.println(F("Wrote driver patch")); + + Serial.println(F("Starting w/o patches")); + + //if (!cc3000.begin(2)) + //{ + // Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + // while(1); + //} + + Serial.println(F("Writing firmware")); + + unsigned char ucStatus_FW = 1; + + while (ucStatus_FW) { + //writing FW patch to EAPRROM - PROTABLE CODE + //Note that the array itself is changing between the different Service Packs + ucStatus_FW = nvmem_write_patch(NVMEM_WLAN_FW_SP_FILEID, fw_length, fw_patch); + } + + Serial.println(F("Starting w/patches")); + + cc3000.reboot(); + /* + if (!) + { + Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + while(1); + } + */ + Serial.println(F("Patched!")); + displayFirmwareVersion(); + displayMACAddress(); +} + + +//***************************************************************************** +// +//! fat_write_content +//! +//! \param[in] file_address array of file address in FAT table:\n +//! this is the absolute address of the file in the EEPROM. +//! \param[in] file_length array of file length in FAT table:\n +//! this is the upper limit of the file size in the EEPROM. +//! +//! \return on succes 0, error otherwise +//! +//! \brief parse the FAT table from eeprom +// +//***************************************************************************** +uint8_t fat_write_content(uint16_t *file_address, uint16_t *file_length) +{ + uint16_t index = 0; + uint8_t ucStatus; + uint8_t fatTable[48]; + uint8_t* fatTablePtr = fatTable; + uint8_t LS[3] = "LS"; + + // first, write the magic number + ucStatus = nvmem_write(16, 2, 0, LS); + + for (; index <= NVMEM_RM_FILEID; index++) + { + // write address low char and mark as allocated + *fatTablePtr++ = (uint8_t)(file_address[index] & 0xff) | _BV(0); + + // write address high char + *fatTablePtr++ = (uint8_t)((file_address[index]>>8) & 0xff); + + // write length low char + *fatTablePtr++ = (uint8_t)(file_length[index] & 0xff); + + // write length high char + *fatTablePtr++ = (uint8_t)((file_length[index]>>8) & 0xff); + } + + // second, write the FAT + // write in two parts to work with tiny driver + ucStatus = nvmem_write(16, 24, 4, fatTable); + ucStatus = nvmem_write(16, 24, 24+4, &fatTable[24]); + + // third, we want to erase any user files + memset(fatTable, 0, sizeof(fatTable)); + ucStatus = nvmem_write(16, 16, 52, fatTable); + + return ucStatus; +} + + +void loop(void) +{ + delay(1000); +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_12/driverpatchinc.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_12/driverpatchinc.h new file mode 100755 index 0000000000..a1a982645e --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_12/driverpatchinc.h @@ -0,0 +1,104 @@ +//Service Pack version P1.12.7.15.26 - Driver patches + +uint8_t cRMdefaultParams[128] = { 0x03, 0x00, 0x01, 0x01, 0x14, 0x14, 0x00, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x23, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x23, 0x23, 0x23, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x01, 0x77, 0x80, 0x1D, 0x1F, 0x22, 0x26, 0x28, 0x29, 0x1A, 0x1F, 0x22, 0x24, 0x26, 0x28, 0x16, 0x1D, 0x1E, 0x20, 0x24, 0x25, 0x1E, 0x2D, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x15, 0x15, 0x15, 0x11, 0x15, 0x15, 0x0E, 0x00}; + +unsigned char PROGMEM wlan_drv_patch[8076] = { 0x00, 0x01, 0x00, 0x00, 0x84, 0x1F, 0x00, 0x00, 0xF0, 0x03, 0x18, 0x00, 0xE4, 0x62, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7A, 0x63, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x10, 0x64, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x20, 0x0C, 0x49, 0x08, 0x60, 0x0C, 0x48, 0x19, 0x30, 0xF7, 0x46, 0x30, 0xB5, 0x05, 0x1C, 0xAC, 0x69, 0x68, 0x68, 0x5F, 0x30, 0x09, 0xD1, 0x60, 0x6B, 0x0C, 0x38, 0x01, 0x21, 0x8E, 0x46, 0x06, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x00, 0x20, 0x60, 0x63, 0xAC, 0x69, 0x6C, 0x60, 0x04, 0x48, 0x5B, 0x30, 0x30, 0xBD, 0x40, 0x3B, 0x08, 0x00, 0x49, 0xD0, 0x01, 0x00, 0x09, 0xEA, 0x02, 0x00, 0x91, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xA6, 0x64, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x3C, 0x65, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xB5, 0x85, 0xB0, 0x05, 0x1C, 0xA8, 0x88, 0x00, 0x90, 0x28, 0x89, 0x01, 0x90, 0xE9, 0x68, 0x02, 0x91, 0x28, 0x7C, 0x03, 0x90, 0x2A, 0x6A, 0x00, 0x20, 0x17, 0x56, 0x68, 0x60, 0x00, 0x29, 0x4C, 0xD0, 0x00, 0x2F, 0x4A, 0xDC , +0xCA, 0x49, 0x0C, 0x1C, 0x08, 0x26, 0x04, 0x90, 0x21, 0x88, 0x00, 0x98, 0x81, 0x42, 0x0C, 0xD1, 0x62, 0x88, 0x01, 0x98, 0x82, 0x42, 0x08, 0xD1, 0x46, 0x20, 0x02, 0x5D, 0x03, 0x98, 0x82, 0x42, 0x03, 0xD1, 0x0E, 0x20, 0x00, 0x57, 0xB8, 0x42, 0x0A, 0xD0, 0x46, 0x20, 0x00, 0x5D, 0x11, 0x28, 0x22, 0xD1, 0x00, 0x98, 0x81, 0x42, 0x1F, 0xD1, 0x0E, 0x20, 0x00, 0x57, 0xFF, 0xFF, 0xD2, 0x65, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xB8, 0x42, 0x1B, 0xD1, 0x04, 0x20, 0x02, 0x1C, 0x02, 0x98, 0xB9, 0x49, 0x01, 0x23, 0x9E, 0x46, 0xEA, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x17, 0xD0, 0x20, 0x1D, 0x02, 0x99, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0xE5, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x0D, 0xD0, 0x46, 0x20, 0x00, 0x5D, 0x11, 0x28, 0x09, 0xD0, 0xA0, 0x6D, 0x00, 0x28, 0x06, 0xD0, 0xAC, 0x34, 0x04, 0x98, 0x01, 0x30, 0x04, 0x90, 0x01, 0x3E, 0xC1, 0xD1, 0x07, 0xE0, 0x04, 0x98, 0x00, 0x06, 0x00, 0x0E , +0xAC, 0x21, 0x41, 0x43, 0xA6, 0x48, 0x40, 0x18, 0x68, 0x60, 0xA6, 0x48, 0xAD, 0x30, 0x05, 0xB0, 0xF0, 0xBD, 0x00, 0xB5, 0xC2, 0x68, 0x90, 0x69, 0x02, 0x21, 0x01, 0x23, 0x9E, 0x46, 0xA2, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xA2, 0x48, 0x61, 0x30, 0x00, 0xBD, 0x01, 0x79, 0x0B, 0x29, 0x03, 0xD0, 0x89, 0x00, 0x9F, 0x4A, 0x51, 0x5A, 0x01, 0xE0, 0x01, 0x21, 0x49, 0x02, 0x41, 0x60, 0x9D, 0x48, 0x0D, 0x30, 0xF7, 0x46, 0x01, 0x1C, 0xFF, 0xFF, 0x68, 0x66, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x9C, 0x48, 0x02, 0x68, 0x9C, 0x48, 0x01, 0x2A, 0x01, 0xD1, 0x25, 0x30, 0xF7, 0x46, 0x9B, 0x4A, 0x12, 0x68, 0x4A, 0x60, 0x19, 0x30, 0xF7, 0x46, 0x00, 0x21, 0x41, 0x60, 0x99, 0x48, 0x98, 0x49, 0x08, 0x18, 0xF7, 0x46, 0x00, 0x21, 0x41, 0x60, 0x97, 0x48, 0xE5, 0x49, 0x08, 0x18, 0xF7, 0x46, 0xFF, 0xB5, 0x46, 0x69, 0x40, 0x68, 0x01, 0x90, 0x94, 0x49, 0x0A, 0x7C, 0x9A, 0x4F, 0x01, 0x2A, 0x63, 0xD0, 0x09, 0x7C, 0x03, 0x29 , +0x60, 0xD0, 0x91, 0x4A, 0x92, 0x4B, 0x00, 0x21, 0x02, 0x91, 0x59, 0x56, 0x24, 0x23, 0x59, 0x43, 0x53, 0x18, 0x03, 0x93, 0x01, 0x28, 0x17, 0xD1, 0x8A, 0x18, 0x04, 0x23, 0x6C, 0x46, 0x8C, 0x49, 0x15, 0x79, 0x08, 0x78, 0xC0, 0x43, 0x28, 0x43, 0x20, 0x70, 0x01, 0x32, 0x01, 0x31, 0x01, 0x34, 0x01, 0x3B, 0xF5, 0xD1, 0x31, 0x1D, 0x68, 0x46, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0xA7, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x40, 0xD0, 0x35, 0x1D, 0x82, 0x48, 0x00, 0x78, 0xFF, 0x28, 0xFF, 0xFF, 0xFE, 0x66, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x11, 0xD0, 0x00, 0x28, 0x0F, 0xD0, 0x03, 0x98, 0x01, 0x1D, 0x28, 0x1C, 0x01, 0x24, 0xA6, 0x46, 0x7E, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x00, 0x28, 0x05, 0xD1, 0x7A, 0x48, 0xA6, 0x46, 0x7B, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x05, 0xE0, 0x28, 0x1C, 0x01, 0x21, 0x8E, 0x46, 0x78, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x01, 0x99, 0x01, 0x29, 0x01, 0xD1, 0x00, 0x28, 0x1E, 0xD1 , +0x01, 0x99, 0x5F, 0x31, 0x01, 0xD0, 0x00, 0x28, 0x0F, 0xD1, 0xA8, 0x20, 0x81, 0x5D, 0x00, 0x29, 0x08, 0xD0, 0x49, 0x1E, 0x81, 0x55, 0x80, 0x5D, 0x00, 0x28, 0x09, 0xD1, 0x38, 0x1C, 0xFF, 0x30, 0x08, 0x30, 0x11, 0xE0, 0x03, 0x21, 0x02, 0x91, 0x00, 0xE0, 0xA8, 0x20, 0x02, 0x99, 0x81, 0x55, 0x38, 0x1C, 0xFF, 0x30, 0x16, 0x30, 0x07, 0xE0, 0x01, 0x98, 0x01, 0x28, 0x02, 0xD1, 0x38, 0x1C, 0xA3, 0x30, 0x01, 0xE0, 0x38, 0x1C, 0x9F, 0x30, 0x00, 0x90, 0xFF, 0xBD, 0x00, 0xB5, 0x02, 0x1C, 0x10, 0x6A, 0xD1, 0x69, 0x52, 0x69, 0xC3, 0x69, 0x5A, 0x60, 0xFF, 0xFF, 0x94, 0x67, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x01, 0x22, 0x96, 0x46, 0x5E, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x5E, 0x48, 0xFF, 0x30, 0x6E, 0x30, 0x00, 0xBD, 0x10, 0xB5, 0x0A, 0x1C, 0x41, 0x69, 0x00, 0x6A, 0x93, 0x69, 0xDB, 0x69, 0x58, 0x60, 0x90, 0x69, 0x01, 0x24, 0xA6, 0x46, 0x56, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0xA6, 0x46, 0x56, 0x48, 0xFE, 0x44 , +0x00, 0x47, 0x55, 0x48, 0xFF, 0x30, 0xB6, 0x30, 0x10, 0xBD, 0x70, 0xB5, 0x05, 0x1C, 0x6E, 0x69, 0x53, 0x48, 0x02, 0x68, 0x5C, 0x21, 0x88, 0x5D, 0x04, 0x28, 0x15, 0xD1, 0x07, 0x20, 0x88, 0x55, 0x10, 0x0B, 0x11, 0xD2, 0x01, 0x24, 0xA6, 0x46, 0x4E, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x00, 0x28, 0x0A, 0xD0, 0x47, 0x21, 0x89, 0x57, 0xC1, 0x60, 0x11, 0x21, 0xC9, 0x02, 0x00, 0x22, 0x04, 0x23, 0xA6, 0x46, 0x48, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x01, 0x20, 0x68, 0x60, 0x43, 0x48, 0x46, 0x49, 0x08, 0x18, 0x70, 0xBD, 0x70, 0xB5, 0x05, 0x1C, 0xAE, 0x69, 0x9C, 0x20, 0x80, 0x19, 0x4B, 0x21, 0x89, 0x00, 0x01, 0x24, 0xFF, 0xFF, 0x2A, 0x68, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xA6, 0x46, 0x41, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x5C, 0x21, 0x88, 0x5D, 0x07, 0x28, 0x01, 0xD1, 0x09, 0x20, 0x00, 0xE0, 0x05, 0x20, 0xAA, 0x69, 0x88, 0x54, 0x30, 0x1C, 0xA6, 0x46, 0xEA, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x68, 0x60, 0xE9, 0x48 , +0x4D, 0x30, 0x70, 0xBD, 0xF0, 0xB5, 0x41, 0x68, 0x82, 0x68, 0x88, 0x23, 0x5E, 0x18, 0x37, 0x88, 0x0B, 0x6F, 0x00, 0x2B, 0x01, 0xD1, 0x00, 0x2F, 0x10, 0xD1, 0x06, 0x2F, 0x02, 0xDD, 0x00, 0x21, 0xC9, 0x43, 0x07, 0xE0, 0x33, 0x88, 0x9B, 0x00, 0xC9, 0x18, 0x0A, 0x67, 0x31, 0x88, 0x01, 0x31, 0x31, 0x80, 0x01, 0x21, 0x81, 0x60, 0xEA, 0x48, 0x1D, 0x30, 0xF0, 0xBD, 0x0B, 0x1C, 0x01, 0x24, 0x5D, 0x6F, 0x1D, 0x67, 0x04, 0x33, 0x01, 0x34, 0x06, 0x2C, 0xE1, 0xDA, 0xF8, 0xE7, 0x00, 0xB5, 0x00, 0x21, 0xC1, 0x60, 0xEB, 0x48, 0x01, 0x68, 0x10, 0x31, 0xE8, 0x48, 0x20, 0x22, 0x01, 0x23, 0x9E, 0x46, 0xE9, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xE7, 0x48, 0xFB, 0x30, 0x00, 0xBD, 0xFF, 0xFF, 0xC0, 0x68, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x14, 0x0D, 0x1B, 0x00, 0x54, 0x19, 0x1B, 0x00, 0x91, 0x1A, 0x01, 0x00, 0x4B, 0xAD, 0x03, 0x00, 0x61, 0x4E, 0x01, 0x00, 0x06, 0x32, 0x08, 0x00, 0x1F, 0x0B, 0x02, 0x00, 0x54, 0x3F , +0x08, 0x00, 0x45, 0xC1, 0x00, 0x00, 0x84, 0x3C, 0x08, 0x00, 0x1B, 0x02, 0x00, 0x00, 0xED, 0x17, 0x00, 0x00, 0xF3, 0xC1, 0x01, 0x00, 0x34, 0x19, 0x1B, 0x00, 0x08, 0x19, 0x1B, 0x00, 0xA6, 0x44, 0x08, 0x00, 0x1C, 0x17, 0x1B, 0x00, 0x18, 0x17, 0x1B, 0x00, 0xCB, 0x67, 0x03, 0x00, 0x0D, 0x47, 0x02, 0x00, 0x39, 0x42, 0x03, 0x00, 0xBD, 0xE7, 0x02, 0x00, 0xB1, 0x40, 0x03, 0x00, 0xB9, 0xEA, 0x01, 0x00, 0x45, 0xDA, 0x00, 0x00, 0x24, 0x41, 0x08, 0x00, 0x71, 0xC0, 0x02, 0x00, 0x7B, 0xC0, 0x02, 0x00, 0x9F, 0x03, 0x00, 0x00, 0x7D, 0xB8, 0x03, 0x00, 0xF0, 0xB5, 0x88, 0xB0, 0x06, 0x91, 0x07, 0x90, 0x86, 0x69, 0xF0, 0x1C, 0xE5, 0xA1, 0x04, 0x22, 0x01, 0x24, 0xA6, 0x46, 0x0F, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x40, 0xD1, 0xFF, 0xFF, 0x56, 0x69, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xF3, 0x79, 0xE3, 0x48, 0x1A, 0x1C, 0x03, 0x70, 0x30, 0x7A, 0x00, 0x90, 0x70, 0x7A, 0x01, 0x90, 0x03, 0x20, 0x2F, 0x49 , +0xF0, 0x31, 0xA6, 0x46, 0xDF, 0x4D, 0xFE, 0x44, 0x28, 0x47, 0xF2, 0x79, 0x35, 0x7A, 0x77, 0x7A, 0x78, 0x1B, 0x43, 0x1C, 0x93, 0x42, 0x1E, 0xD0, 0x16, 0x2A, 0x0F, 0xDB, 0x00, 0x2D, 0x0D, 0xD1, 0x01, 0xE0, 0x8F, 0xC6, 0x03, 0x00, 0xDB, 0x48, 0x04, 0x70, 0x0A, 0x20, 0x81, 0x19, 0xD5, 0x48, 0x1A, 0x1C, 0xA6, 0x46, 0xAF, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x82, 0xE0, 0xD7, 0x48, 0x04, 0x70, 0xD1, 0x48, 0x40, 0x19, 0x0A, 0x21, 0x89, 0x19, 0x7A, 0x1B, 0x52, 0x1C, 0xA6, 0x46, 0xA8, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x75, 0xE0, 0xCF, 0x48, 0x04, 0x70, 0xCF, 0x48, 0x04, 0x70, 0x0A, 0x20, 0x81, 0x19, 0xC8, 0x48, 0xA6, 0x46, 0xA2, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x69, 0xE0, 0xF0, 0x1C, 0x03, 0x27, 0xC1, 0xA1, 0x3A, 0x1C, 0xA6, 0x46, 0xCC, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x5F, 0xD1, 0xFF, 0xFF, 0xEC, 0x69, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xFF, 0xE7, 0xF1, 0x79, 0xC0, 0x48, 0x01, 0x70, 0xC0, 0x4D , +0xB2, 0x79, 0x2A, 0x70, 0x38, 0x1C, 0x0A, 0x49, 0xF4, 0x31, 0xA6, 0x46, 0xBE, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x28, 0x78, 0x00, 0x28, 0x0E, 0xD1, 0xBE, 0x48, 0x04, 0x70, 0xBE, 0x48, 0x04, 0x70, 0x38, 0x1C, 0x03, 0x49, 0xF5, 0x31, 0xA6, 0x46, 0xBC, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x02, 0xE0, 0xC0, 0x46, 0xC7, 0x04, 0x00, 0x00, 0x30, 0x7A, 0x00, 0x90, 0x70, 0x7A, 0x01, 0x90, 0xAF, 0x48, 0x02, 0x78, 0xF3, 0x79, 0x38, 0x1C, 0xB6, 0x49, 0xF6, 0x31, 0xA6, 0x46, 0xAA, 0x4D, 0xFE, 0x44, 0x28, 0x47, 0x23, 0x1C, 0xF2, 0x79, 0x37, 0x7A, 0x70, 0x7A, 0xC1, 0x1B, 0x4D, 0x1C, 0x95, 0x42, 0x1E, 0xD0, 0xA6, 0x49, 0x09, 0x78, 0x16, 0x29, 0x0C, 0xDB, 0x00, 0x2F, 0x0A, 0xD1, 0xA8, 0x48, 0x03, 0x70, 0x0A, 0x20, 0x81, 0x19, 0xE7, 0x48, 0x2A, 0x1C, 0xA6, 0x46, 0x7A, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x18, 0xE0, 0xA4, 0x49, 0x0B, 0x70, 0xE3, 0x49, 0xCB, 0x19, 0xFF, 0xFF, 0x82, 0x6A, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00 , +0x0A, 0x21, 0x89, 0x19, 0xC0, 0x1B, 0x42, 0x1C, 0x18, 0x1C, 0xA6, 0x46, 0x73, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x0A, 0xE0, 0x9C, 0x48, 0x03, 0x70, 0x9C, 0x48, 0x03, 0x70, 0x0A, 0x20, 0x81, 0x19, 0xDA, 0x48, 0xA6, 0x46, 0x6D, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x94, 0x48, 0x00, 0x78, 0x00, 0x28, 0x0A, 0xD0, 0x93, 0x48, 0x00, 0x78, 0x00, 0x28, 0x06, 0xD0, 0x92, 0x48, 0x00, 0x78, 0x00, 0x28, 0x02, 0xD0, 0x91, 0x48, 0x00, 0x78, 0x00, 0x28, 0x00, 0xD1, 0x8C, 0xE0, 0x03, 0x20, 0x17, 0x21, 0x89, 0x01, 0xA6, 0x46, 0x8E, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x85, 0x48, 0x01, 0x78, 0x85, 0x48, 0x07, 0x78, 0x82, 0x4E, 0x80, 0x4D, 0xDF, 0x48, 0x00, 0x68, 0x00, 0x28, 0x2E, 0xD1, 0x07, 0x98, 0x41, 0x61, 0x06, 0x62, 0xC5, 0x48, 0x06, 0x9A, 0x10, 0x64, 0x02, 0x2F, 0x01, 0xD0, 0x03, 0x2F, 0x01, 0xD1, 0x03, 0x22, 0x00, 0xE0, 0x3A, 0x1C, 0x06, 0x9B, 0xDA, 0x63, 0x2A, 0x78, 0x9A, 0x63, 0x01, 0x2F, 0x03, 0xD1, 0x05, 0x29 , +0xFF, 0xFF, 0x18, 0x6B, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x04, 0xD0, 0x0D, 0x29, 0x02, 0xD0, 0xEB, 0x48, 0xDB, 0x30, 0x64, 0xE0, 0x00, 0x25, 0x00, 0x95, 0x01, 0x91, 0x02, 0x96, 0x03, 0x95, 0x04, 0x90, 0x2B, 0x1C, 0x20, 0x1C, 0x01, 0x1C, 0x8E, 0x46, 0xE5, 0x4E, 0xFE, 0x44, 0x30, 0x47, 0xE5, 0x48, 0x04, 0x60, 0x28, 0x1C, 0xA6, 0x46, 0xE4, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x4C, 0xE0, 0x0D, 0x27, 0x00, 0x20, 0x39, 0x1C, 0x05, 0xAA, 0xA6, 0x46, 0xE1, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x68, 0x46, 0x80, 0x8A, 0x40, 0x08, 0x05, 0xD2, 0x38, 0x1C, 0x50, 0x21, 0xA6, 0x46, 0xDB, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x38, 0x1C, 0x23, 0x1C, 0x29, 0x1C, 0x00, 0x22, 0x9E, 0x46, 0xEE, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0x2B, 0x78, 0x0D, 0x20, 0x31, 0x1C, 0x22, 0x1C, 0x96, 0x46, 0xEA, 0x4E, 0xFE, 0x44, 0x30, 0x47, 0x28, 0x78, 0x01, 0x30, 0x02, 0x1C, 0x0D, 0x20, 0x56, 0x49, 0x23, 0x1C, 0x9E, 0x46, 0xE5, 0x4E, 0xFE, 0x44 , +0x30, 0x47, 0x54, 0x4E, 0x28, 0x78, 0x02, 0x30, 0x02, 0x1C, 0xFF, 0xFF, 0xAE, 0x6B, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x0D, 0x20, 0x31, 0x1C, 0x23, 0x1C, 0x9E, 0x46, 0xE0, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0x30, 0x78, 0x00, 0x28, 0x0A, 0xD0, 0x28, 0x78, 0x03, 0x30, 0x02, 0x1C, 0x4A, 0x48, 0x03, 0x78, 0x0D, 0x20, 0x8F, 0x49, 0xA6, 0x46, 0xD9, 0x4D, 0xFE, 0x44, 0x28, 0x47, 0xBE, 0x48, 0x21, 0x1C, 0x01, 0x60, 0x00, 0x20, 0x8E, 0x46, 0xBD, 0x49, 0xFE, 0x44, 0x08, 0x47, 0xB8, 0x48, 0xEB, 0x49, 0x08, 0x18, 0x08, 0xB0, 0xF0, 0xBD, 0xC0, 0x46, 0xC9, 0x21, 0x01, 0x00, 0x91, 0xE1, 0x00, 0x00, 0x01, 0x1C, 0xE7, 0x48, 0x02, 0x68, 0xE7, 0x48, 0x00, 0x2A, 0x04, 0xD0, 0x00, 0x22, 0x0A, 0x62, 0x8A, 0x61, 0x1D, 0x30, 0xF7, 0x46, 0xD7, 0x30, 0xF7, 0x46, 0x01, 0x1C, 0xE2, 0x48, 0x02, 0x68, 0xE2, 0x48, 0x00, 0x2A, 0x02, 0xD0, 0xFF, 0x30, 0xB4, 0x30, 0xF7, 0x46, 0x00, 0x22, 0xCA, 0x61, 0x8A, 0x61, 0x4F, 0x30 , +0xF7, 0x46, 0xC0, 0x46, 0x89, 0x17, 0x02, 0x00, 0xDC, 0x48, 0x01, 0x68, 0x8A, 0x69, 0x01, 0x20, 0xC0, 0x03, 0x10, 0x43, 0xFF, 0xFF, 0x44, 0x6C, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x88, 0x61, 0x00, 0x20, 0x08, 0x61, 0xD9, 0x48, 0x23, 0x30, 0xF7, 0x46, 0x46, 0x17, 0x1B, 0x00, 0x30, 0x3F, 0x08, 0x00, 0x41, 0xEB, 0x00, 0x00, 0x09, 0xB4, 0x03, 0x00, 0x70, 0xB5, 0x05, 0x1C, 0xD3, 0x4E, 0x29, 0x6A, 0xEA, 0x69, 0x30, 0x1C, 0x01, 0x24, 0xA6, 0x46, 0xD4, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x68, 0x69, 0xA6, 0x46, 0xCF, 0x49, 0xFE, 0x44, 0x08, 0x47, 0xA8, 0x69, 0x06, 0x30, 0xA8, 0x60, 0xCD, 0x48, 0x00, 0x68, 0x68, 0x60, 0xEE, 0x60, 0xCC, 0x48, 0x6D, 0x30, 0x70, 0xBD, 0x30, 0xB5, 0xF1, 0x48, 0x01, 0x6D, 0x80, 0x6C, 0x08, 0x43, 0x18, 0xD0, 0xEF, 0x49, 0x08, 0x1C, 0x07, 0x22, 0xFF, 0x23, 0x09, 0x33, 0x1B, 0x58, 0x00, 0x2B, 0x04, 0xD0, 0xFF, 0x30, 0x1D, 0x30, 0x01, 0x3A, 0xF6, 0xD1, 0x0B, 0xE0, 0x02, 0x20 , +0xF0, 0x4A, 0xF1, 0x4B, 0x01, 0x24, 0xA6, 0x46, 0xF0, 0x4D, 0xFE, 0x44, 0x28, 0x47, 0xA6, 0x46, 0xEF, 0x48, 0xFE, 0x44, 0x00, 0x47, 0xEF, 0x48, 0xFF, 0x30, 0x5C, 0x30, 0x30, 0xBD, 0xFF, 0xFF, 0xDA, 0x6C, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xC0, 0x46, 0x53, 0x53, 0x49, 0x44, 0x00, 0xC0, 0x46, 0xC0, 0x4B, 0x45, 0x59, 0x00, 0xEE, 0x62, 0x08, 0x00, 0x13, 0x7F, 0x03, 0x00, 0xF0, 0x62, 0x08, 0x00, 0xEC, 0x62, 0x08, 0x00, 0xED, 0x62, 0x08, 0x00, 0xE7, 0x7E, 0x03, 0x00, 0xE8, 0x62, 0x08, 0x00, 0xE9, 0x62, 0x08, 0x00, 0xEA, 0x62, 0x08, 0x00, 0xEB, 0x62, 0x08, 0x00, 0xDD, 0x7E, 0x03, 0x00, 0x8F, 0xC6, 0x03, 0x00, 0xC7, 0x04, 0x00, 0x00, 0xF0, 0xB5, 0x87, 0xB0, 0x00, 0x91, 0x01, 0x90, 0x6B, 0x48, 0x01, 0x68, 0xCD, 0x4A, 0x14, 0x1C, 0x02, 0x94, 0x07, 0x26, 0x00, 0x25, 0x03, 0x95, 0x04, 0x94, 0x05, 0x95, 0xDD, 0x48, 0x00, 0x68, 0x08, 0x43, 0x27, 0xD0, 0xE0, 0x68, 0x03, 0x99, 0x88, 0x42, 0x0A, 0xDD , +0x03, 0x90, 0x40, 0x1C, 0x00, 0x99, 0x88, 0x60, 0xC3, 0x49, 0xFF, 0x20, 0x1D, 0x30, 0x68, 0x43, 0x0C, 0x18, 0xE0, 0x68, 0x04, 0x91, 0x02, 0x99, 0xC9, 0x68, 0x88, 0x42, 0x10, 0xDB, 0x88, 0x42, 0x10, 0xD1, 0x02, 0x98, 0x01, 0x27, 0xBE, 0x46, 0xFF, 0xFF, 0x70, 0x6D, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xCC, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x06, 0x90, 0x20, 0x1C, 0xBE, 0x46, 0xC9, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x06, 0x99, 0x88, 0x42, 0x01, 0xDA, 0x05, 0x95, 0x02, 0x94, 0x51, 0x48, 0x01, 0x68, 0xFF, 0x27, 0x09, 0x37, 0x38, 0x59, 0x00, 0x28, 0x06, 0xD0, 0xC5, 0x48, 0x00, 0x68, 0x07, 0x2E, 0x00, 0xD1, 0x2E, 0x1C, 0x08, 0x43, 0x04, 0xD0, 0xFF, 0x34, 0x1D, 0x34, 0x01, 0x35, 0x07, 0x2D, 0xC2, 0xDB, 0x07, 0x2E, 0x0A, 0xD1, 0xBE, 0x48, 0x00, 0x68, 0x08, 0x43, 0x06, 0xD0, 0x05, 0x9E, 0x30, 0x1C, 0x01, 0x21, 0x8E, 0x46, 0xB8, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x01, 0x98, 0x47, 0x61, 0x00, 0x21, 0x81, 0x61 , +0xFF, 0x22, 0x1D, 0x32, 0x72, 0x43, 0x04, 0x99, 0x89, 0x18, 0xC1, 0x61, 0x06, 0x62, 0xB2, 0x48, 0x39, 0x30, 0x07, 0xB0, 0xF0, 0xBD, 0x10, 0xB5, 0x04, 0x1C, 0x00, 0x20, 0x01, 0x21, 0x8E, 0x46, 0xAF, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x40, 0x1E, 0x00, 0xD5, 0x00, 0x20, 0x60, 0x60, 0xE0, 0x61, 0xAC, 0x48, 0xFF, 0xFF, 0x06, 0x6E, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x21, 0x30, 0x10, 0xBD, 0xC0, 0x46, 0x10, 0x63, 0x08, 0x00, 0x70, 0xB5, 0x04, 0x1C, 0xE5, 0x69, 0x66, 0x69, 0x00, 0x20, 0x01, 0x21, 0x8E, 0x46, 0xA5, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x60, 0x60, 0xAB, 0x19, 0xA4, 0x4A, 0xA3, 0x49, 0x93, 0x42, 0x02, 0xD3, 0x9A, 0x1A, 0x82, 0x42, 0x02, 0xD9, 0x08, 0x1C, 0x99, 0x30, 0x70, 0xBD, 0x08, 0x1C, 0xAB, 0x30, 0x70, 0xBD, 0x08, 0x6B, 0x41, 0x7D, 0x02, 0x88, 0x92, 0x00, 0x51, 0x1A, 0x3C, 0x39, 0xFF, 0x22, 0x5F, 0x32, 0x91, 0x42, 0x03, 0xD9, 0x65, 0x21, 0x01, 0x80, 0x02, 0x21, 0x81, 0x73, 0x99, 0x48 , +0x97, 0x49, 0x08, 0x18, 0xF7, 0x46, 0xC0, 0x46, 0x30, 0x63, 0x08, 0x00, 0xF8, 0xB5, 0x40, 0x68, 0x24, 0x21, 0x41, 0x43, 0x95, 0x48, 0x45, 0x18, 0x28, 0x1D, 0x0C, 0x21, 0x49, 0x19, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0x92, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x8F, 0x4C, 0x00, 0x28, 0x1B, 0xD0, 0x2B, 0x1C, 0x04, 0x22, 0x6E, 0x46, 0x8F, 0x49, 0x1F, 0x7B, 0x08, 0x78, 0xFF, 0xFF, 0x9C, 0x6E, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xC0, 0x43, 0x38, 0x43, 0x30, 0x70, 0x01, 0x33, 0x01, 0x31, 0x01, 0x36, 0x01, 0x3A, 0xF5, 0xD1, 0x0C, 0x20, 0x41, 0x19, 0x68, 0x46, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0x85, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x02, 0xD0, 0x20, 0x1C, 0x4A, 0x30, 0xF8, 0xBD, 0x20, 0x1C, 0xF8, 0xBD, 0xB1, 0xBD, 0x00, 0x00, 0x15, 0x95, 0x00, 0x00, 0x58, 0x3F, 0x08, 0x00, 0xF3, 0xF8, 0x00, 0x00, 0xE9, 0x09, 0x02, 0x00, 0xDD, 0x0A, 0x02, 0x00, 0xF8, 0xB5, 0x05, 0x1C, 0xAA, 0x69, 0x7C, 0x49 , +0x00, 0x20, 0x08, 0x56, 0x24, 0x21, 0x41, 0x43, 0x75, 0x48, 0x43, 0x18, 0x04, 0x24, 0x6E, 0x46, 0x75, 0x49, 0x1F, 0x79, 0x08, 0x78, 0xC0, 0x43, 0x38, 0x43, 0x30, 0x70, 0x01, 0x33, 0x01, 0x31, 0x01, 0x36, 0x01, 0x3C, 0xF5, 0xD1, 0x11, 0x1D, 0x68, 0x46, 0x04, 0x22, 0x01, 0x24, 0xA6, 0x46, 0x6C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x01, 0x1C, 0x6C, 0x48, 0x04, 0xD0, 0x6D, 0x49, 0x09, 0x78, 0x69, 0x60, 0x45, 0x30, 0xF8, 0xBD, 0xFF, 0xFF, 0x32, 0x6F, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xEC, 0x61, 0xAF, 0x30, 0xF8, 0xBD, 0x2B, 0x09, 0x02, 0x00, 0x70, 0xB5, 0xC5, 0x68, 0x81, 0x68, 0x0A, 0x89, 0x6B, 0x4E, 0x00, 0x2A, 0x22, 0xD0, 0x01, 0x24, 0xC2, 0x6D, 0xA2, 0x18, 0xC2, 0x65, 0x08, 0x89, 0x0D, 0x28, 0x1B, 0xD1, 0x68, 0x6B, 0x21, 0x1C, 0xA6, 0x46, 0x61, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x22, 0x1C, 0x28, 0x1C, 0x00, 0x21, 0xA6, 0x46, 0x5E, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x2C, 0x60, 0xE9, 0x6B, 0x28, 0x1C , +0xA6, 0x46, 0x5C, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x28, 0x1C, 0xA6, 0x46, 0x5A, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x30, 0x1C, 0x3D, 0x30, 0x70, 0xBD, 0x30, 0x1C, 0x23, 0x30, 0x70, 0xBD, 0xC0, 0x46, 0xB1, 0x02, 0x00, 0x00, 0x74, 0x3F, 0x08, 0x00, 0x19, 0xC6, 0x00, 0x00, 0x5C, 0x3F, 0x08, 0x00, 0x1D, 0xC2, 0x00, 0x00, 0x68, 0x44, 0x08, 0x00, 0x43, 0x12, 0x03, 0x00, 0x34, 0x63, 0x08, 0x00, 0x2F, 0x7A, 0x02, 0x00, 0xB4, 0x36, 0x08, 0x00, 0x8F, 0xF4, 0x01, 0x00, 0x09, 0xB4, 0x03, 0x00, 0xFF, 0xFF, 0xC8, 0x6F, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xF0, 0xB5, 0x05, 0x1C, 0xAB, 0x69, 0xEC, 0x69, 0x60, 0x68, 0x00, 0x68, 0x2A, 0x30, 0x01, 0x78, 0x0A, 0x06, 0x41, 0x78, 0x09, 0x04, 0x8A, 0x18, 0x81, 0x78, 0x09, 0x02, 0x8A, 0x18, 0xC1, 0x78, 0x8A, 0x18, 0x8E, 0x26, 0xF1, 0x5A, 0x09, 0x0A, 0x01, 0x70, 0xF0, 0x5C, 0x61, 0x68, 0x09, 0x68, 0x2B, 0x26, 0x70, 0x54, 0x8C, 0x20, 0xC0, 0x18, 0x61, 0x68, 0x0E, 0x68 , +0x01, 0x88, 0x09, 0x0A, 0x2C, 0x27, 0xB9, 0x55, 0x61, 0x68, 0x09, 0x68, 0x2D, 0x26, 0x00, 0x78, 0x70, 0x54, 0x60, 0x68, 0x01, 0x68, 0x32, 0x31, 0x08, 0x78, 0x00, 0x02, 0x49, 0x78, 0x08, 0x18, 0x00, 0x04, 0x00, 0x0C, 0x8C, 0x21, 0xCB, 0x58, 0x32, 0x49, 0x41, 0x40, 0x08, 0x04, 0x00, 0x0C, 0xC0, 0x18, 0x80, 0x1A, 0x01, 0x21, 0x8E, 0x46, 0x2F, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x61, 0x68, 0x0A, 0x68, 0x32, 0x23, 0x01, 0x0A, 0x99, 0x54, 0x61, 0x68, 0x09, 0x68, 0x33, 0x22, 0x50, 0x54, 0x60, 0x68, 0x68, 0x60, 0x29, 0x48, 0xF0, 0xBD, 0x00, 0x00, 0xFF, 0xFF, 0x5E, 0x70, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x34, 0x04, 0x1B, 0x00, 0x02, 0x6A, 0x8B, 0x69, 0xDB, 0x69, 0x1B, 0x68, 0x83, 0x60, 0x88, 0x69, 0xC0, 0x69, 0x41, 0x68, 0x8A, 0x42, 0x00, 0xDA, 0x42, 0x60, 0x22, 0x48, 0x79, 0x30, 0xF7, 0x46, 0x32, 0x04, 0x00, 0x00, 0xC4, 0x07, 0x00, 0x00, 0x15, 0x09, 0x02, 0x00, 0xC5, 0x93, 0x00, 0x00 , +0x0D, 0x91, 0x00, 0x00, 0x40, 0x1E, 0x80, 0x00, 0x1C, 0x4B, 0x19, 0x50, 0x1A, 0x49, 0x0A, 0x50, 0xF7, 0x46, 0xC0, 0x46, 0xBD, 0xB5, 0x00, 0x00, 0x95, 0x92, 0x00, 0x00, 0xFD, 0x93, 0x00, 0x00, 0x54, 0x3F, 0x08, 0x00, 0x29, 0x4F, 0x03, 0x00, 0xDF, 0xE8, 0x02, 0x00, 0x36, 0x89, 0x41, 0x00, 0x81, 0x06, 0x00, 0x00, 0xB1, 0x78, 0x00, 0x00, 0x94, 0xEC, 0x01, 0x00, 0x08, 0x19, 0x1B, 0x00, 0x8F, 0xC6, 0x03, 0x00, 0x1C, 0x17, 0x1B, 0x00, 0x67, 0x66, 0x03, 0x00, 0xA6, 0x44, 0x08, 0x00, 0x18, 0x17, 0x1B, 0x00, 0xA7, 0x2F, 0x02, 0x00, 0x91, 0x44, 0x03, 0x00, 0x91, 0x63, 0x03, 0x00, 0x5B, 0x44, 0x03, 0x00, 0xFF, 0xFF, 0xF4, 0x70, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xE7, 0x44, 0x03, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x61, 0xA2, 0x03, 0x00, 0x6A, 0x1E, 0x01, 0x00, 0x45, 0xDA, 0x00, 0x00, 0x04, 0xF3, 0x1A, 0x00, 0x80, 0x7B, 0x08, 0x00, 0xFC, 0xB5, 0x04, 0x1C, 0xA5, 0x69, 0x60, 0x6A, 0x01, 0x90, 0x20, 0x69 , +0x00, 0x28, 0x35, 0xD4, 0x08, 0x28, 0x33, 0xDA, 0xE1, 0x69, 0x09, 0x68, 0x10, 0x29, 0x2F, 0xD1, 0xAC, 0x21, 0x41, 0x43, 0x9E, 0x4A, 0x51, 0x5C, 0x49, 0x08, 0x27, 0xD3, 0x00, 0x06, 0x00, 0x16, 0xA2, 0x68, 0x69, 0x46, 0x01, 0x23, 0x9E, 0x46, 0x9A, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x06, 0x1C, 0x39, 0x30, 0x1F, 0xD0, 0x00, 0x2E, 0x1D, 0xD0, 0x00, 0x98, 0x07, 0x68, 0x00, 0x99, 0x0C, 0x39, 0x01, 0x98, 0x01, 0x60, 0x28, 0x1D, 0x10, 0x21, 0x79, 0x1A, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0x91, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x02, 0x22, 0x2A, 0x80, 0xA8, 0x1C, 0x08, 0x21, 0x79, 0x1A, 0x01, 0x23, 0x9E, 0x46, 0x8C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x03, 0xE0, 0x38, 0x20, 0xFF, 0xFF, 0x8A, 0x71, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x20, 0xC6, 0x43, 0x26, 0x60, 0x89, 0x48, 0x7C, 0x30, 0x20, 0x62, 0xFC, 0xBD, 0x30, 0xB5, 0x05, 0x1C, 0x28, 0x69, 0xA9, 0x69, 0x90, 0x29, 0x1D, 0xD1, 0x69, 0x69 , +0x09, 0x78, 0x04, 0x29, 0x19, 0xD0, 0x05, 0x29, 0x17, 0xD0, 0x0A, 0x29, 0x15, 0xD0, 0x06, 0x29, 0x13, 0xD0, 0x0C, 0x29, 0x01, 0xDB, 0x10, 0x29, 0x0F, 0xD1, 0x01, 0x24, 0xA6, 0x46, 0x7D, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x7C, 0x48, 0x7D, 0x49, 0x00, 0x22, 0xA6, 0x46, 0x7C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x7C, 0x48, 0xFF, 0x30, 0x5F, 0x30, 0x28, 0x62, 0x30, 0xBD, 0xF0, 0xB5, 0x89, 0xB0, 0x05, 0x90, 0x41, 0x69, 0x02, 0x69, 0x75, 0x48, 0x79, 0x4E, 0x82, 0x42, 0x3A, 0xD0, 0x04, 0x30, 0x82, 0x42, 0x25, 0xD0, 0x74, 0x4D, 0xAA, 0x42, 0x00, 0xD0, 0xCC, 0xE0, 0x08, 0x68, 0x06, 0x1C, 0x0C, 0x22, 0x8F, 0x1A, 0x4A, 0x68, 0x89, 0x18, 0x09, 0x1D, 0x10, 0x22, 0x01, 0x24, 0xA6, 0x46, 0x6E, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x01, 0x1C, 0xFF, 0xFF, 0x20, 0x72, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x09, 0xD1, 0xAC, 0x22, 0x72, 0x43, 0xCB, 0x48, 0x80, 0x18, 0x46, 0x22, 0x12, 0x5C, 0x11, 0x2A, 0x01, 0xD1, 0x44, 0x22 , +0x14, 0x54, 0x28, 0x1C, 0x3A, 0x1C, 0xA6, 0x46, 0x62, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x69, 0x48, 0xEC, 0x30, 0xAB, 0xE0, 0x08, 0x68, 0xC0, 0x00, 0x30, 0x18, 0x8A, 0x68, 0x02, 0x2A, 0x02, 0xD0, 0xE7, 0x20, 0x80, 0x00, 0xA2, 0xE0, 0xCA, 0x68, 0x89, 0x18, 0x09, 0x7B, 0x41, 0x60, 0x80, 0x21, 0x01, 0x60, 0x3B, 0x20, 0x00, 0x01, 0x99, 0xE0, 0x08, 0x68, 0x06, 0x90, 0xC0, 0x00, 0x34, 0x58, 0x10, 0x20, 0x04, 0x90, 0x01, 0x25, 0xAE, 0x46, 0x57, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x07, 0x90, 0x00, 0x28, 0x00, 0xD1, 0x89, 0xE0, 0x0C, 0x21, 0x07, 0x98, 0x0F, 0x18, 0xB0, 0x49, 0xAC, 0x20, 0x06, 0x9A, 0x50, 0x43, 0x08, 0x18, 0x48, 0x22, 0x13, 0x5C, 0x5B, 0x06, 0x5B, 0x0E, 0x13, 0x54, 0x06, 0x9A, 0xD2, 0x00, 0xB6, 0x18, 0x71, 0x68, 0x00, 0x29, 0x47, 0xD1, 0x00, 0x2C, 0x01, 0xDD, 0x08, 0x2C, 0xFF, 0xFF, 0xB6, 0x72, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x21, 0xDB, 0x00, 0x22, 0x69, 0x46, 0x0A, 0x70, 0x01, 0x92 , +0x0A, 0x81, 0x8A, 0x72, 0xCD, 0x72, 0x0D, 0x73, 0x4D, 0x73, 0x01, 0x88, 0x44, 0x48, 0x06, 0x23, 0xAE, 0x46, 0x44, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x04, 0x1C, 0x02, 0xDC, 0x00, 0x20, 0xC0, 0x43, 0x36, 0xE0, 0x34, 0x60, 0xAC, 0x20, 0x60, 0x43, 0x9A, 0x49, 0x09, 0x18, 0x5C, 0x22, 0x28, 0x1C, 0x50, 0x54, 0x48, 0x20, 0x42, 0x5C, 0x52, 0x06, 0x52, 0x0E, 0x42, 0x54, 0xAC, 0x20, 0x60, 0x43, 0x94, 0x49, 0x08, 0x18, 0x5C, 0x21, 0x09, 0x5C, 0x49, 0x1E, 0x02, 0x29, 0x16, 0xD9, 0x03, 0x39, 0x08, 0xD0, 0x00, 0x20, 0x30, 0x56, 0xAE, 0x46, 0xEA, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x80, 0x20, 0x30, 0x60, 0xDB, 0xE7, 0x08, 0x94, 0x80, 0x21, 0x31, 0x60, 0x48, 0x22, 0x13, 0x5C, 0x19, 0x43, 0x11, 0x54, 0xAE, 0x46, 0xE4, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x0A, 0xE0, 0x01, 0x20, 0xCE, 0xE7, 0x06, 0x98, 0x39, 0x1C, 0x04, 0xAA, 0xAE, 0x46, 0xE0, 0x4B, 0xFE, 0x44, 0xFF, 0xFF, 0x4C, 0x73, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00 , +0x18, 0x47, 0x04, 0x1C, 0x08, 0x90, 0x06, 0x98, 0x38, 0x60, 0x08, 0x98, 0x78, 0x60, 0x00, 0x28, 0x15, 0xD0, 0xAC, 0x20, 0x60, 0x43, 0x7C, 0x49, 0x09, 0x18, 0x48, 0x88, 0x02, 0x04, 0x02, 0x20, 0x10, 0x43, 0xB8, 0x60, 0x48, 0x68, 0x02, 0x0E, 0x01, 0x02, 0x09, 0x0E, 0x09, 0x02, 0x11, 0x43, 0x02, 0x04, 0x12, 0x0E, 0x12, 0x04, 0x0A, 0x43, 0x00, 0x06, 0x10, 0x43, 0xF8, 0x60, 0x07, 0x98, 0x0D, 0x49, 0x00, 0x22, 0x10, 0x23, 0xAE, 0x46, 0xCE, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x13, 0x48, 0x00, 0xE0, 0x16, 0x20, 0xCC, 0x49, 0x09, 0x18, 0x05, 0x98, 0x01, 0x62, 0x09, 0xB0, 0xF0, 0xBD, 0x5D, 0x0D, 0x1B, 0x00, 0x81, 0xE7, 0x02, 0x00, 0x09, 0xB4, 0x03, 0x00, 0x27, 0x1A, 0x02, 0x00, 0x2F, 0x7A, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x05, 0x10, 0x00, 0x00, 0xCF, 0xF6, 0x00, 0x00, 0xD5, 0xF4, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x91, 0x19, 0x02, 0x00, 0x50, 0x65, 0x08, 0x00, 0x71, 0xC0, 0x02, 0x00, 0x50, 0x19 , +0xFF, 0xFF, 0xE2, 0x73, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x29, 0x16, 0x01, 0x00, 0x2A, 0x03, 0x00, 0x00, 0xF0, 0xB5, 0x8B, 0xB0, 0x07, 0x90, 0x05, 0x69, 0x47, 0x69, 0x0C, 0x20, 0x38, 0x1A, 0x08, 0x90, 0xB6, 0x49, 0x8D, 0x42, 0x16, 0xD1, 0x78, 0x68, 0x0F, 0x30, 0x00, 0x11, 0x00, 0x01, 0x78, 0x60, 0x38, 0x68, 0x0B, 0x28, 0x0E, 0xD8, 0x00, 0x23, 0x68, 0x46, 0x03, 0x70, 0x08, 0x98, 0x05, 0x22, 0x01, 0x24, 0xA6, 0x46, 0xAE, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0xAE, 0x48, 0xFF, 0x30, 0x95, 0x30, 0x07, 0x99, 0x08, 0x62, 0xAC, 0x48, 0x85, 0x42, 0x23, 0xD1, 0xAC, 0x48, 0x02, 0x78, 0x6C, 0x46, 0x22, 0x72, 0x43, 0x78, 0x63, 0x72, 0x81, 0x78, 0xA1, 0x72, 0xC0, 0x78, 0xE0, 0x72, 0x00, 0x91, 0x01, 0x90, 0x03, 0x20, 0xA6, 0x49, 0x01, 0x39, 0x01, 0x26, 0xB6, 0x46, 0xF3, 0x4E, 0xFE, 0x44, 0x30, 0x47, 0x04, 0x20, 0x20, 0x70, 0x08, 0x98, 0x9F, 0x49, 0x00, 0x22, 0x02, 0xAB, 0x01, 0x24, 0xA6, 0x46 , +0x9B, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x9A, 0x48, 0xFF, 0x30, 0xFF, 0xFF, 0x78, 0x74, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x95, 0x30, 0x07, 0x99, 0x08, 0x62, 0xEB, 0x49, 0x8D, 0x42, 0x14, 0xD1, 0x02, 0x22, 0x68, 0x46, 0x02, 0x70, 0x3A, 0x68, 0xAC, 0x20, 0x42, 0x43, 0x30, 0x48, 0x68, 0x30, 0x83, 0x18, 0x08, 0x98, 0x00, 0x22, 0x01, 0x24, 0xA6, 0x46, 0x8F, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x8E, 0x48, 0xFF, 0x30, 0x95, 0x30, 0x07, 0x99, 0x08, 0x62, 0xEF, 0x48, 0x85, 0x42, 0x00, 0xD0, 0x04, 0xE1, 0x03, 0x20, 0x8C, 0x49, 0x01, 0x22, 0x96, 0x46, 0xEC, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x86, 0x48, 0xFF, 0x30, 0x95, 0x30, 0x09, 0x90, 0x38, 0x68, 0xEA, 0x4D, 0x00, 0x28, 0x00, 0xD1, 0xE2, 0xE0, 0x01, 0x24, 0xA6, 0x46, 0xE6, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x00, 0x28, 0x00, 0xD1, 0xD6, 0xE0, 0xE4, 0x48, 0x02, 0x68, 0x03, 0x20, 0x7F, 0x49, 0x01, 0x31, 0xA6, 0x46, 0xE2, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xDF, 0x48 , +0x00, 0x68, 0x00, 0x28, 0x5A, 0xD1, 0xDF, 0x4D, 0x2E, 0x20, 0x41, 0x19, 0xB8, 0x68, 0x03, 0x30, 0x08, 0x70, 0x38, 0x7A, 0xFF, 0xFF, 0x0E, 0x75, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x48, 0x70, 0x2E, 0x1C, 0x30, 0x36, 0xB8, 0x68, 0x28, 0x18, 0x30, 0x30, 0xDA, 0x49, 0x0A, 0x68, 0x30, 0x3A, 0x31, 0x1C, 0xA6, 0x46, 0xD8, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x78, 0x68, 0x38, 0x18, 0x01, 0x1D, 0xBA, 0x68, 0x30, 0x1C, 0xA6, 0x46, 0xD9, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xB8, 0x68, 0x41, 0x19, 0x97, 0x22, 0x09, 0x30, 0x50, 0x54, 0xB8, 0x68, 0x46, 0x19, 0x9E, 0x36, 0x30, 0x70, 0x01, 0x36, 0xB8, 0x68, 0x01, 0xE0, 0x14, 0x0D, 0x1B, 0x00, 0x30, 0x18, 0xCA, 0x49, 0x0A, 0x68, 0x9E, 0x3A, 0x31, 0x1C, 0xA6, 0x46, 0xC8, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x78, 0x68, 0x38, 0x18, 0x01, 0x1D, 0xBA, 0x68, 0x30, 0x1C, 0xA6, 0x46, 0xC9, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xB8, 0x68, 0x40, 0x00, 0xC0, 0x49, 0x09, 0x68, 0x08, 0x18 , +0x28, 0x18, 0xC0, 0x49, 0x0A, 0x79, 0x02, 0x70, 0x4A, 0x79, 0x42, 0x70, 0x8A, 0x79, 0x82, 0x70, 0xC9, 0x79, 0xC1, 0x70, 0x04, 0x30, 0x0F, 0x21, 0x41, 0x1A, 0x0A, 0x78, 0xBB, 0x68, 0xFF, 0xFF, 0xA4, 0x75, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x9A, 0x18, 0x0A, 0x70, 0x40, 0x1B, 0x00, 0x04, 0x00, 0x0C, 0xB5, 0x49, 0x08, 0x60, 0xB1, 0x48, 0x04, 0x60, 0x02, 0x20, 0x01, 0x1C, 0x11, 0x22, 0xA6, 0x46, 0xB4, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x06, 0x1C, 0x63, 0xD4, 0x03, 0x20, 0xA6, 0x46, 0xB1, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x0A, 0x90, 0x00, 0x25, 0x01, 0x1C, 0x8D, 0x42, 0x50, 0xD0, 0x29, 0x1C, 0x2B, 0x22, 0xA6, 0x46, 0xAD, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x0C, 0x20, 0x0A, 0x99, 0x40, 0x18, 0xAC, 0x22, 0x72, 0x43, 0xAB, 0x49, 0x8F, 0x18, 0x78, 0x63, 0x29, 0x1C, 0x18, 0x22, 0xA6, 0x46, 0xA6, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x9F, 0x48, 0x02, 0x68, 0x79, 0x6B, 0x4A, 0x60, 0x0A, 0x98, 0xAC, 0x30, 0x08, 0x60 , +0x08, 0x68, 0x9A, 0x49, 0xA6, 0x46, 0xA0, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x29, 0x1C, 0x03, 0xA8, 0x10, 0x22, 0xA6, 0x46, 0x9C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xE0, 0x21, 0x68, 0x46, 0x01, 0x74, 0x45, 0x74, 0x85, 0x74, 0xFB, 0x21, 0xC1, 0x74, 0xFF, 0xFF, 0x3A, 0x76, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xEE, 0x49, 0xC1, 0x81, 0x02, 0x21, 0x81, 0x81, 0x79, 0x6B, 0xCA, 0x68, 0x01, 0x20, 0xC0, 0x03, 0x10, 0x43, 0xC8, 0x60, 0x48, 0x68, 0x00, 0x90, 0x2A, 0x1C, 0x30, 0x1C, 0x0A, 0x9D, 0x29, 0x1C, 0x03, 0xAB, 0xA6, 0x46, 0xE6, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0x07, 0x1C, 0x30, 0x06, 0x00, 0x16, 0xA6, 0x46, 0xEF, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x28, 0x1C, 0xA6, 0x46, 0xEE, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x11, 0xE0, 0x30, 0x06, 0x00, 0x16, 0xA6, 0x46, 0xE9, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x01, 0x20, 0xC7, 0x43, 0x08, 0xE0, 0x07, 0x1C, 0x06, 0xE0, 0x00, 0x20, 0x00, 0x21, 0xCF, 0x43, 0x01, 0xE0, 0x00, 0x20 , +0x07, 0x1C, 0x28, 0x60, 0x00, 0x23, 0x68, 0x46, 0x03, 0x70, 0x3A, 0x06, 0x12, 0x0E, 0x08, 0x98, 0x6F, 0x49, 0x01, 0x24, 0xA6, 0x46, 0x09, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x07, 0x98, 0x09, 0x99, 0x01, 0x62, 0x0B, 0xB0, 0xF0, 0xBD, 0xC1, 0x18, 0x01, 0x00, 0xF1, 0x1B, 0x01, 0x00, 0xF3, 0x1C, 0x02, 0x00, 0xFF, 0xFF, 0xD0, 0x76, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x7B, 0xC0, 0x02, 0x00, 0x91, 0xF0, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0xA3, 0xC0, 0x02, 0x00, 0xA9, 0xE9, 0x00, 0x00, 0x07, 0x02, 0x00, 0x00, 0xE4, 0x62, 0x08, 0x00, 0xAC, 0x05, 0x00, 0x00, 0xFE, 0xB5, 0x07, 0x1C, 0x7D, 0x69, 0xBE, 0x69, 0x0C, 0x20, 0x30, 0x1A, 0x01, 0x90, 0xDF, 0x4C, 0x0A, 0x2D, 0x13, 0xD1, 0x30, 0x68, 0xDB, 0x49, 0x08, 0x60, 0x01, 0x20, 0x86, 0x46, 0xDA, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x0A, 0x20, 0x00, 0x21, 0x01, 0x9A, 0x01, 0x23, 0x9E, 0x46, 0xE6, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xF5, 0x20, 0x80, 0x00, 0x00, 0x19 , +0x38, 0x62, 0x03, 0x2D, 0x79, 0xD1, 0xF5, 0x20, 0x80, 0x00, 0x00, 0x19, 0x02, 0x90, 0x70, 0x68, 0x00, 0x28, 0x0C, 0xD1, 0x00, 0x21, 0xCF, 0x48, 0x01, 0x60, 0xCF, 0x48, 0x00, 0x68, 0x00, 0x28, 0x61, 0xD0, 0x01, 0x21, 0x8E, 0x46, 0xCD, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x5B, 0xE0, 0xCC, 0x48, 0xB1, 0x68, 0x01, 0x60, 0xF1, 0x68, 0x41, 0x60, 0x31, 0x69, 0x81, 0x60, 0xFF, 0xFF, 0x66, 0x77, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x71, 0x69, 0xC1, 0x60, 0xB1, 0x69, 0xC1, 0x63, 0xF1, 0x69, 0x01, 0x64, 0x31, 0x6A, 0xC1, 0x64, 0x01, 0x24, 0xA6, 0x46, 0xC5, 0x48, 0xFE, 0x44, 0x00, 0x47, 0xA6, 0x46, 0xC4, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x70, 0x68, 0x7D, 0x25, 0xED, 0x00, 0xA8, 0x42, 0x21, 0xD8, 0x01, 0x28, 0x18, 0xD0, 0x02, 0x28, 0x05, 0xD0, 0x28, 0x1C, 0xA6, 0x46, 0xBE, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x1C, 0xE0, 0xB9, 0x48, 0x00, 0x23, 0x19, 0x1C, 0x59, 0x43, 0x3E, 0x22, 0x4A, 0x43, 0x82, 0x83, 0x02, 0x30 , +0x01, 0x33, 0x10, 0x2B, 0xF6, 0xDB, 0xA6, 0x46, 0xB4, 0x48, 0xFE, 0x44, 0x00, 0x47, 0xB5, 0x48, 0x0D, 0xE0, 0xB5, 0x4D, 0x28, 0x1C, 0xA6, 0x46, 0xB2, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x04, 0xE0, 0xA6, 0x46, 0xAF, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x75, 0x68, 0xAE, 0x48, 0x05, 0x60, 0x05, 0x1C, 0xA7, 0x4E, 0x30, 0x68, 0x00, 0x28, 0x06, 0xD1, 0xAD, 0x48, 0x00, 0x68, 0xA6, 0x46, 0xAC, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x30, 0x60, 0xFF, 0xFF, 0xFC, 0x77, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x94, 0x2B, 0x68, 0xAA, 0x49, 0xAB, 0x4A, 0xA6, 0x46, 0xAB, 0x4D, 0xFE, 0x44, 0x28, 0x47, 0x9C, 0x48, 0x04, 0x60, 0x03, 0x20, 0x00, 0x21, 0x01, 0x9A, 0x01, 0x23, 0x9E, 0x46, 0xA7, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x02, 0x98, 0x38, 0x62, 0xFE, 0xBD, 0xC0, 0x46, 0x13, 0x7F, 0x03, 0x00, 0x12, 0x10, 0x00, 0x00, 0x30, 0xB5, 0x05, 0x1C, 0x00, 0x20, 0x01, 0x24, 0xA6, 0x46, 0xA0, 0x49, 0xFE, 0x44, 0x08, 0x47, 0xA6, 0x46 , +0x9F, 0x49, 0xFE, 0x44, 0x08, 0x47, 0xA6, 0x46, 0x9E, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x7D, 0x21, 0xC9, 0x00, 0xA6, 0x46, 0x9E, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x9B, 0x49, 0x08, 0x18, 0x99, 0x49, 0x08, 0x80, 0x9B, 0x48, 0x0A, 0x30, 0x28, 0x62, 0x30, 0xBD, 0x11, 0x10, 0x00, 0x00, 0xDD, 0x7E, 0x03, 0x00, 0xB9, 0x90, 0x00, 0x00, 0x6C, 0x64, 0x08, 0x00, 0xE7, 0x7E, 0x03, 0x00, 0x74, 0x64, 0x08, 0x00, 0x70, 0x64, 0x08, 0x00, 0x6D, 0xC6, 0x03, 0x00, 0x08, 0x19, 0x1B, 0x00, 0x11, 0x18, 0xFF, 0xFF, 0x92, 0x78, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x02, 0x00, 0xD1, 0x78, 0x02, 0x00, 0xC9, 0xBA, 0x03, 0x00, 0x09, 0xB4, 0x03, 0x00, 0x14, 0x0D, 0x1B, 0x00, 0xFE, 0xB5, 0x02, 0x90, 0x45, 0x69, 0x68, 0x46, 0x01, 0x21, 0x8E, 0x46, 0x89, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x89, 0x48, 0x04, 0x1C, 0x68, 0x68, 0x01, 0x69, 0x4A, 0x78, 0x00, 0x27, 0x3E, 0x1C, 0x20, 0x88, 0x40, 0x08, 0x22, 0xD3, 0x20, 0x1D, 0x89, 0x1C , +0x01, 0x23, 0x9E, 0x46, 0x83, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x07, 0xD1, 0x68, 0x68, 0x00, 0x69, 0x40, 0x78, 0x21, 0x88, 0x09, 0x04, 0x89, 0x16, 0x81, 0x42, 0x3D, 0xD0, 0x02, 0x20, 0x00, 0x5F, 0x00, 0x99, 0x08, 0x1A, 0x00, 0x04, 0x00, 0x14, 0x3C, 0x28, 0x03, 0xDD, 0x20, 0x88, 0x40, 0x10, 0x40, 0x00, 0x20, 0x80, 0x78, 0x1C, 0x07, 0x06, 0x3F, 0x0E, 0x68, 0x68, 0x01, 0x69, 0x4A, 0x78, 0x2A, 0x34, 0x01, 0x36, 0x14, 0x2E, 0xD5, 0xDB, 0x00, 0x2A, 0x02, 0xD1, 0xAB, 0x20, 0x40, 0x00, 0x50, 0xE0, 0x00, 0x9B, 0x6D, 0x48, 0x14, 0x21, 0xFF, 0xFF, 0x28, 0x79, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x22, 0x04, 0x88, 0x64, 0x08, 0x03, 0xD3, 0x2A, 0x30, 0x01, 0x32, 0x01, 0x39, 0xF8, 0xD1, 0x12, 0x06, 0x12, 0x0E, 0x14, 0x2F, 0x16, 0xD1, 0x66, 0x48, 0x00, 0x88, 0x00, 0x06, 0x44, 0x16, 0x64, 0x49, 0x00, 0x22, 0x01, 0x20, 0x4E, 0x8D, 0x36, 0x06, 0x76, 0x16, 0xA6, 0x42, 0x02, 0xDD, 0x34, 0x1C , +0x02, 0x06, 0x12, 0x0E, 0x2A, 0x31, 0x01, 0x30, 0x14, 0x28, 0xF3, 0xDB, 0x02, 0xE0, 0x32, 0x06, 0x12, 0x0E, 0x00, 0x9B, 0x2A, 0x20, 0x42, 0x43, 0x5A, 0x48, 0x11, 0x18, 0x0C, 0x88, 0x01, 0x20, 0x20, 0x43, 0x00, 0x04, 0x00, 0x0C, 0x08, 0x80, 0xFE, 0x24, 0xA0, 0x43, 0x14, 0x24, 0x64, 0x57, 0x64, 0x06, 0x24, 0x0E, 0x04, 0x43, 0x52, 0x48, 0x14, 0x52, 0x14, 0x18, 0x63, 0x80, 0x08, 0x88, 0x80, 0x05, 0x82, 0x0D, 0x68, 0x68, 0x00, 0x69, 0x40, 0x78, 0x80, 0x02, 0x10, 0x43, 0x08, 0x80, 0x68, 0x68, 0x02, 0x69, 0x20, 0x1D, 0x91, 0x1C, 0x52, 0x78, 0x01, 0x23, 0x9E, 0x46, 0x4B, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xFF, 0xFF, 0xBE, 0x79, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x02, 0x98, 0x04, 0x61, 0xFE, 0x20, 0x47, 0x49, 0x09, 0x18, 0x02, 0x98, 0x01, 0x62, 0xFE, 0xBD, 0x82, 0x69, 0x41, 0x69, 0x03, 0x69, 0x02, 0x2B, 0x0A, 0xD1, 0x01, 0x2A, 0x01, 0xD1, 0x00, 0x29, 0x05, 0xD0, 0x02, 0x2A, 0x04, 0xD1, 0x00, 0x29 , +0x02, 0xD1, 0x11, 0x21, 0x00, 0xE0, 0x06, 0x21, 0x41, 0x61, 0xF7, 0x46, 0xC0, 0x46, 0x14, 0xE9, 0x00, 0x00, 0xC9, 0x18, 0x02, 0x00, 0x30, 0xB5, 0x05, 0x1C, 0x3A, 0x48, 0x00, 0x78, 0x00, 0x28, 0x04, 0xD0, 0x01, 0x20, 0x86, 0x46, 0x38, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x01, 0x24, 0xA6, 0x46, 0x37, 0x48, 0xFE, 0x44, 0x00, 0x47, 0xA6, 0x46, 0x36, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x35, 0x48, 0x0E, 0x30, 0x28, 0x62, 0x30, 0xBD, 0x49, 0x19, 0x01, 0x00, 0x2F, 0x7A, 0x02, 0x00, 0x18, 0xB5, 0x43, 0x69, 0x81, 0x69, 0x31, 0x48, 0x81, 0x29, 0x00, 0xD1, 0x0B, 0x38, 0x00, 0x21, 0x00, 0x91, 0x1A, 0x68, 0x9B, 0x68, 0x01, 0x24, 0xA6, 0x46, 0x2D, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0xFF, 0xFF, 0x54, 0x7A, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x18, 0xBD, 0x18, 0xB5, 0x40, 0x69, 0x00, 0x21, 0x00, 0x91, 0x02, 0x68, 0x83, 0x68, 0x27, 0x48, 0x01, 0x30, 0x01, 0x24, 0xA6, 0x46, 0x26, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x18, 0xBD , +0xC0, 0x46, 0x30, 0x63, 0x08, 0x00, 0x19, 0x9E, 0x00, 0x00, 0xB9, 0xEC, 0x00, 0x00, 0x74, 0x3F, 0x08, 0x00, 0x80, 0x3F, 0x08, 0x00, 0xB7, 0x5D, 0x03, 0x00, 0x00, 0x00, 0x1B, 0x00, 0xD3, 0x8E, 0x00, 0x00, 0xF7, 0xC6, 0x00, 0x00, 0xE5, 0x90, 0x00, 0x00, 0x68, 0x64, 0x08, 0x00, 0xC0, 0x27, 0x09, 0x00, 0xA0, 0x3B, 0x08, 0x00, 0x3D, 0x5D, 0x03, 0x00, 0x19, 0xC6, 0x00, 0x00, 0xE8, 0x3A, 0x08, 0x00, 0x81, 0x5D, 0x03, 0x00, 0xCF, 0xF6, 0x00, 0x00, 0x4B, 0x4F, 0x03, 0x00, 0x6B, 0xC0, 0x03, 0x00, 0x95, 0x1E, 0x01, 0x00, 0xDA, 0x40, 0x08, 0x00, 0xDC, 0x05, 0x00, 0x00, 0x55, 0xAA, 0x03, 0x00, 0x0D, 0x91, 0x00, 0x00, 0xD7, 0x56, 0x03, 0x00, 0x08, 0x51, 0x08, 0x00, 0x8F, 0xC6, 0x03, 0x00, 0x65, 0xB8, 0x00, 0x00, 0x09, 0xB4, 0xFF, 0xFF, 0xEA, 0x7A, 0x08, 0x00, 0x8C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x84, 0x17, 0x1B, 0x00, 0xB5, 0x86, 0x01, 0x00, 0x3D, 0x47, 0x02, 0x00, 0x73, 0x49, 0x02, 0x00, 0x5F, 0x90 , +0x00, 0x00, 0x0E, 0x10, 0x00, 0x00, 0xF7, 0xF6, 0x00, 0x00, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x76, 0xFF, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x5A, 0xFF, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x99, 0xFF, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x83, 0xFF, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0xB6, 0xFE, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x55, 0xFC, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x27, 0xFB, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0xDD, 0xFA, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x68, 0xFE, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x3D, 0xFB, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0xBE, 0xFD, 0xFF, 0xBD, 0x78, 0x7B, 0x08, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0xB5, 0xF8, 0xF0, 0x43, 0xFA, 0x00, 0xBD, 0x35, 0x66, 0x08, 0x00, 0x67, 0x66, 0x08, 0x00, 0x71, 0x65, 0x08, 0x00, 0x4D, 0x66 , +0x08, 0x00, 0x25, 0x64, 0x08, 0x00, 0x81, 0x66, 0x08, 0x00, 0x8D, 0x66, 0x08, 0x00, 0x99, 0x66, 0x08, 0x00, 0x87, 0x67, 0x08, 0x00, 0xA7, 0x67, 0x08, 0x00, 0xD1, 0x67, 0x08, 0x00, 0x1B, 0x68, 0x08, 0x00, 0x57, 0x68, 0x08, 0x00, 0x39, 0x69, 0x08, 0x00, 0xFD, 0x6B, 0x08, 0x00, 0x17, 0x6C, 0x08, 0x00, 0x39, 0x6C, 0x08, 0x00, 0x61, 0x6C, 0x08, 0x00, 0xA1, 0x68, 0x08, 0x00, 0x95, 0x6C, 0x08, 0x00, 0xEB, 0x6D, 0x08, 0x00, 0x43, 0x6E, 0x08, 0x00, 0x6D, 0x6E, 0x08, 0x00, 0x3D, 0x6F, 0x08, 0x00, 0x1D, 0x6D, 0x08, 0x00, 0xE5, 0x6E, 0x08, 0x00, 0x11, 0x6E, 0x08, 0x00, 0xC9, 0x6F, 0x08, 0x00, 0x65, 0x70, 0x08, 0x00, 0x31, 0x64, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xF3, 0x1A, 0x00, 0x80, 0x00, 0x00, 0x00, 0xB2, 0x4E, 0x01, 0x00, 0x5A, 0xC1, 0x00, 0x00, 0x96, 0x1A, 0x01, 0x00, 0x22, 0x0B, 0x02, 0x00, 0x60, 0xD0, 0x01, 0x00, 0x06, 0x1A, 0x00, 0x00, 0xB8, 0xC6, 0x01, 0x00 , +0xD8, 0x42, 0x03, 0x00, 0x16, 0x42, 0x03, 0x00, 0xEE, 0xDB, 0x00, 0x00, 0x62, 0xDC, 0x00, 0x00, 0xC8, 0xE1, 0x00, 0x00, 0x8A, 0x17, 0x02, 0x00, 0x38, 0xBE, 0x00, 0x00, 0x26, 0xC6, 0x00, 0x00, 0x56, 0xC2, 0x00, 0x00, 0x62, 0x12, 0x03, 0x00, 0xE4, 0xF4, 0x01, 0x00, 0x3A, 0xEC, 0x00, 0x00, 0x5E, 0x92, 0x00, 0x00, 0xFE, 0xE8, 0x02, 0x00, 0x18, 0x7F, 0x00, 0x00, 0x64, 0xEC, 0x01, 0x00, 0xFE, 0x44, 0x03, 0x00, 0x1C, 0x94, 0x00, 0x00, 0xA8, 0x66, 0x03, 0x00, 0x74, 0xE9, 0x02, 0x00, 0x68, 0x1E, 0x01, 0x00, 0xBC, 0xDA, 0x00, 0x00, 0xEA, 0xE1, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 0x1A, 0xF0, 0xB5, 0x88, 0xB0, 0xCA, 0x4C, 0x03, 0x20, 0x22, 0x78, 0x63, 0x78, 0xCA, 0x4E, 0x31, 0x1C, 0x01, 0x39, 0x01, 0x25, 0xAE, 0x46, 0xC7, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0xA2, 0x78, 0xE3, 0x78, 0x03, 0x20, 0x31, 0x1C, 0xAE, 0x46 , +0xC3, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0x03, 0x20, 0x31, 0x1C, 0x01, 0x31, 0xAE, 0x46, 0xC1, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0xC1, 0x48, 0x21, 0x78, 0x01, 0x70, 0x61, 0x78, 0x41, 0x70, 0xE1, 0x78, 0xC1, 0x70, 0xA1, 0x78, 0x81, 0x70, 0xBF, 0x48, 0x04, 0x1C, 0x33, 0x3C, 0x20, 0x1C, 0x00, 0x21, 0xDC, 0x22, 0xAE, 0x46, 0xBA, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x84, 0x20, 0xA0, 0x70, 0x05, 0x27, 0xE7, 0x71, 0x0C, 0x26, 0x26, 0x73, 0x0D, 0x20, 0x00, 0x19, 0x98, 0xA1, 0x32, 0x1C, 0xAE, 0x46, 0xB4, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x04, 0x20, 0x60, 0x76, 0x1A, 0x20, 0x00, 0x19, 0x97, 0xA1, 0x06, 0x91, 0x04, 0x22, 0xAE, 0x46, 0xAE, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xFF, 0xFF, 0x96, 0x00, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0xA7, 0x77, 0x1F, 0x34, 0x95, 0xA1, 0x07, 0x91, 0x20, 0x1C, 0x3A, 0x1C, 0xAE, 0x46, 0xA9, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xE6, 0x71, 0x28, 0x1C, 0x60, 0x72, 0x11, 0x20, 0x20, 0x73, 0x94, 0x20 , +0x60, 0x73, 0xC0, 0x25, 0x65, 0x74, 0xA6, 0x74, 0x09, 0x22, 0xE2, 0x74, 0xA3, 0x4C, 0x20, 0x1C, 0x8C, 0xA1, 0x01, 0x23, 0x9E, 0x46, 0x9F, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x07, 0x22, 0x62, 0x72, 0x9E, 0x4C, 0x0A, 0x34, 0x20, 0x1C, 0x89, 0xA1, 0x01, 0x23, 0x9E, 0x46, 0x9A, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x04, 0x20, 0xE0, 0x71, 0x98, 0x4C, 0x12, 0x34, 0x20, 0x1C, 0x06, 0x99, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0x94, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x27, 0x71, 0x93, 0x4C, 0x17, 0x34, 0x20, 0x1C, 0x07, 0x99, 0x3A, 0x1C, 0x01, 0x23, 0x9E, 0x46, 0x8E, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xE6, 0x71, 0x01, 0x20, 0x60, 0x72, 0x11, 0x20, 0x20, 0x73, 0x94, 0x20, 0x60, 0x73, 0x02, 0x20, 0xE0, 0x73, 0x25, 0x74, 0x66, 0x74, 0xFF, 0xFF, 0x2C, 0x01, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0xA5, 0x74, 0x2F, 0x27, 0xE7, 0x74, 0x10, 0x20, 0x60, 0x75, 0x80, 0x26, 0xA6, 0x75, 0x01, 0x20, 0xE0, 0x75, 0x11, 0x20, 0xA0, 0x76 , +0x94, 0x20, 0xE0, 0x76, 0x24, 0x20, 0x60, 0x77, 0x0A, 0x22, 0xA2, 0x77, 0x80, 0x4C, 0x36, 0x34, 0x20, 0x1C, 0x6D, 0xA1, 0x01, 0x23, 0x9E, 0x46, 0x7C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x18, 0x22, 0xA2, 0x72, 0x7A, 0x4C, 0x41, 0x34, 0x20, 0x1C, 0x6B, 0xA1, 0x01, 0x23, 0x9E, 0x46, 0x76, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x25, 0x76, 0x67, 0x76, 0x21, 0x20, 0xE0, 0x76, 0x26, 0x77, 0x01, 0x20, 0x60, 0x77, 0x72, 0x48, 0x61, 0x30, 0x11, 0x21, 0x01, 0x70, 0x94, 0x21, 0x41, 0x70, 0x04, 0x21, 0x01, 0x72, 0xD2, 0x21, 0x41, 0x72, 0xC5, 0x72, 0x1E, 0x21, 0x01, 0x73, 0x45, 0x73, 0x9E, 0x21, 0x81, 0x73, 0x01, 0x21, 0x01, 0x74, 0x46, 0x74, 0x81, 0x74, 0x11, 0x21, 0x41, 0x75, 0x94, 0x21, 0x81, 0x75, 0x04, 0x21, 0x01, 0x76, 0xAD, 0x20, 0x66, 0x49, 0x08, 0x60, 0x00, 0x24, 0x0F, 0x25, 0xFF, 0xFF, 0xC2, 0x01, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0x29, 0x06, 0x09, 0x0E, 0x00, 0x20, 0x6A, 0x46, 0x01, 0x23, 0x9E, 0x46 , +0x62, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x6B, 0x46, 0x18, 0x88, 0x40, 0x08, 0x0E, 0xD3, 0xA0, 0x00, 0x0F, 0x21, 0xCA, 0x43, 0x69, 0x46, 0x0E, 0x88, 0x16, 0x40, 0x01, 0xAF, 0x3E, 0x52, 0x49, 0x88, 0x11, 0x40, 0x68, 0x44, 0xC1, 0x80, 0x60, 0x1C, 0x04, 0x04, 0x24, 0x0C, 0x01, 0x3D, 0x0B, 0x2D, 0xE0, 0xDA, 0x60, 0x1E, 0x00, 0x04, 0x00, 0x0C, 0x1D, 0xD0, 0x86, 0x46, 0x01, 0x1C, 0x01, 0xAD, 0x01, 0x22, 0xAE, 0x88, 0x90, 0x00, 0xC7, 0x5A, 0xB7, 0x42, 0x0A, 0xDA, 0xBC, 0x46, 0x07, 0x1C, 0x6F, 0x44, 0x7F, 0x88, 0x68, 0x44, 0x06, 0x80, 0xEE, 0x88, 0x46, 0x80, 0x60, 0x46, 0xA8, 0x80, 0xEF, 0x80, 0x04, 0x35, 0x50, 0x1C, 0x02, 0x04, 0x12, 0x0C, 0x01, 0x39, 0xE9, 0xD1, 0x70, 0x46, 0x01, 0x38, 0x86, 0x46, 0xE2, 0xD1, 0x99, 0x88, 0x68, 0x46, 0xC0, 0x88, 0x40, 0x18, 0x00, 0x04, 0x00, 0x0C, 0x42, 0x4B, 0x18, 0x80, 0x42, 0x49, 0x08, 0x1A, 0xFF, 0xFF, 0x58, 0x02, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0x58, 0x80 , +0x02, 0x2C, 0x1E, 0xDB, 0x65, 0x1E, 0x01, 0xAA, 0x01, 0x20, 0x01, 0x1C, 0x8C, 0x00, 0x6B, 0x46, 0xE6, 0x5A, 0x93, 0x88, 0xD4, 0x88, 0xE7, 0x18, 0xB7, 0x42, 0x0C, 0xDA, 0x06, 0x24, 0x44, 0x43, 0x38, 0x4B, 0x1B, 0x19, 0x1F, 0x80, 0x1C, 0x88, 0x34, 0x1B, 0x5C, 0x80, 0x01, 0x24, 0x1C, 0x71, 0x40, 0x1C, 0x00, 0x04, 0x00, 0x0C, 0x04, 0x32, 0x49, 0x1C, 0x09, 0x06, 0x09, 0x0E, 0x01, 0x3D, 0xE4, 0xD1, 0x00, 0x24, 0x31, 0x48, 0x04, 0x70, 0x31, 0x48, 0x04, 0x70, 0x31, 0x48, 0x04, 0x70, 0x31, 0x48, 0x04, 0x70, 0x01, 0x20, 0x86, 0x46, 0x30, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x2F, 0x49, 0x22, 0x1C, 0x08, 0x68, 0x00, 0x28, 0x02, 0xD0, 0x01, 0x20, 0x90, 0x40, 0x04, 0x43, 0x04, 0x31, 0x01, 0x32, 0x20, 0x2A, 0xF5, 0xD3, 0x2A, 0x48, 0x04, 0x60, 0x08, 0xB0, 0xF0, 0xBD, 0x5F, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2D, 0x69, 0x6E, 0x66, 0x6F, 0x00, 0xC0, 0x46, 0xC0, 0x5F, 0x75, 0x64, 0x70, 0x00, 0xC0, 0xFF, 0xFF , +0xEE, 0x02, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0x46, 0xC0, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0xC0, 0x46, 0x5F, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x00, 0xC0, 0x46, 0x5F, 0x64, 0x6E, 0x73, 0x2D, 0x73, 0x64, 0x00, 0x64, 0x65, 0x76, 0x3D, 0x43, 0x43, 0x33, 0x30, 0x30, 0x30, 0x00, 0xC0, 0x76, 0x65, 0x6E, 0x64, 0x6F, 0x72, 0x3D, 0x54, 0x65, 0x78, 0x61, 0x73, 0x2D, 0x49, 0x6E, 0x73, 0x74, 0x72, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x73, 0x00, 0xC0, 0x46, 0xC0, 0x00, 0x00, 0x18, 0x00, 0xF3, 0x7E, 0x03, 0x00, 0xC6, 0x05, 0x00, 0x00, 0xDD, 0x7E, 0x03, 0x00, 0xE4, 0x62, 0x08, 0x00, 0xC9, 0xBA, 0x03, 0x00, 0x09, 0xB4, 0x03, 0x00, 0xA7, 0x64, 0x08, 0x00, 0x70, 0x64, 0x08, 0x00, 0xDD, 0x0A, 0x02, 0x00, 0x48, 0x32, 0x08, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xE8, 0x62, 0x08, 0x00, 0xE9, 0x62, 0x08, 0x00, 0xEA, 0x62, 0x08, 0x00, 0xEB, 0x62, 0x08, 0x00, 0x81, 0x03, 0x18, 0x00, 0x80, 0x7B, 0x08, 0x00 , +0x84, 0xF3, 0x1A, 0x00, 0x0D, 0x49, 0x0E, 0x48, 0xFF, 0xFF, 0x84, 0x03, 0x18, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x88, 0x67, 0x0E, 0x48, 0x88, 0x64, 0x0E, 0x48, 0x48, 0x64, 0x0E, 0x48, 0xC8, 0x64, 0x0E, 0x48, 0x08, 0x65, 0x11, 0x48, 0x02, 0x1C, 0x04, 0x32, 0x0C, 0x4B, 0x13, 0x60, 0x0C, 0x4B, 0x93, 0x62, 0x0C, 0x4A, 0x8A, 0x66, 0x0D, 0x49, 0x01, 0x60, 0x0D, 0x48, 0x0E, 0x49, 0x01, 0x60, 0x0E, 0x49, 0x41, 0x60, 0xF7, 0x46, 0x1C, 0x21, 0x08, 0x00, 0x4F, 0x7B, 0x08, 0x00, 0x45, 0x7B, 0x08, 0x00, 0x3B, 0x7B, 0x08, 0x00, 0x6D, 0x7B, 0x08, 0x00, 0x63, 0x7B, 0x08, 0x00, 0x59, 0x7B, 0x08, 0x00, 0x31, 0x7B, 0x08, 0x00, 0x13, 0x7B, 0x08, 0x00, 0x50, 0x23, 0x08, 0x00, 0x09, 0x7B, 0x08, 0x00, 0x58, 0x26, 0x08, 0x00, 0x27, 0x7B, 0x08, 0x00, 0x1D, 0x7B, 0x08, 0x00 }; + +uint16_t drv_length = 8076; + +//Service Pack version P1.12.7.15.15 - FW patches +unsigned char PROGMEM fw_patch[5700] = { 0x00, 0x01, 0x00, 0x00, 0x3C, 0x16, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x14, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x68, 0x46, 0x25, 0xF0, 0x95, 0xFB, 0xE0, 0x6B, 0xD0, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x25, 0xF0, 0x38, 0xFB, 0x2C, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x25, 0xF0, 0x0A, 0xFB, 0x04, 0x15, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xB8, 0xF1, 0x90, 0x0F, 0xA4, 0x16, 0x00, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x66, 0xE0, 0x04, 0xA8, 0x35, 0x1D, 0x21, 0xF0, 0x99, 0xFC, 0x68, 0x46, 0x23, 0xF0, 0x28, 0xFB, 0x9A, 0xF8, 0x00, 0x00, 0x01, 0x28, 0x07, 0xD1, 0x28, 0x46, 0x05, 0xF0, 0xC3, 0xFE, 0x01, 0x46, 0x01, 0xAA, 0x00, 0x20, 0x21, 0xF0, 0x50, 0xF9, 0x28, 0x46, 0x05, 0xF0, 0xBB, 0xFE, 0x01, 0xA9, 0x21, 0xF0, 0x2A, 0xFA, 0xE9, 0x79, 0x4F, 0xEA, 0xE0, 0x00, 0x40, 0xB2, 0x11, 0xB1, 0x00, 0xF1, 0x06, 0x00, 0x40, 0xB2, 0xA8, 0x71, 0x1F, 0x38, 0x40, 0x00, 0xE8, 0x71, 0x30, 0x46 , +0x01, 0xF0, 0x0D, 0xFF, 0x10, 0xF1, 0x00, 0x09, 0x4F, 0xF0, 0x00, 0x01, 0x09, 0xD0, 0x28, 0x68, 0x40, 0x0C, 0x09, 0xD3, 0xE8, 0x68, 0xC0, 0x0B, 0x03, 0xD2, 0x48, 0x46, 0xFF, 0xF7, 0xDD, 0xFE, 0x01, 0x21, 0x28, 0x68, 0x40, 0x0C, 0x0A, 0xD2, 0x38, 0x68, 0x40, 0x1C, 0x38, 0x60, 0x20, 0x68, 0x6F, 0xF3, 0x0F, 0x00, 0x20, 0x60, 0x22, 0x68, 0x38, 0x68, 0x10, 0x43, 0x20, 0x60, 0xE8, 0x68, 0xC0, 0x0B, 0x0F, 0xD3, 0xD8, 0xF8, 0x00, 0x00, 0x00, 0xF1, 0x01, 0x00, 0xC8, 0xF8, 0x00, 0x00, 0x20, 0x68, 0x6F, 0xF3, 0x1F, 0x40, 0x20, 0x60, 0xD8, 0xF8, 0x00, 0x20, 0x20, 0x68, 0x40, 0xEA, 0x02, 0x40, 0x20, 0x60, 0x49, 0xB9, 0xB9, 0xF1, 0x00, 0x0F, 0x03, 0xD1, 0x30, 0x46, 0x07, 0xF0, 0xBE, 0xF9, 0x02, 0xE0, 0x48, 0x46, 0x07, 0xF0, 0x06, 0xFA, 0x6C, 0x17, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x68, 0x46, 0x0E, 0xF0, 0x85, 0xFB, 0x00, 0x9E, 0x00, 0x2E, 0x96, 0xD1, 0x05, 0xB0, 0xBD, 0xE8, 0xF0, 0x87, 0xC0, 0x46 , +0x9C, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x23, 0xF0, 0x2A, 0xFE, 0x74, 0x47, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0B, 0x21, 0x21, 0xF0, 0x41, 0xFA, 0x20, 0x68, 0x18, 0x4B, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x21, 0xF0, 0x1C, 0xF9, 0x0A, 0xE0, 0x20, 0x68, 0x00, 0x68, 0x0C, 0x21, 0x40, 0xF0, 0x20, 0x00, 0x21, 0xF0, 0x14, 0xF9, 0x10, 0x57, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0xA8, 0x20, 0xF0, 0x97, 0xF9, 0x01, 0x98, 0x5C, 0x57, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0xA8, 0x20, 0xF0, 0x71, 0xF9, 0x03, 0x98, 0x00, 0x58, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0xF0, 0x20, 0xF9, 0x1C, 0x58, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0xF0, 0x12, 0xF9, 0x54, 0x58, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0xA8, 0x20, 0xF0, 0xF5, 0xF8, 0x04, 0xAB, 0x04, 0x62, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x79, 0x1F, 0xF0, 0x1B, 0xFD, 0x69, 0xE0, 0x60, 0x93, 0x00, 0x00, 0x40, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xA6, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1B, 0xF0, 0x39, 0xFB, 0x28, 0x46, 0x90, 0xA8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1B, 0xF0, 0x69, 0xF9, 0x1E, 0x48, 0x34, 0xAD, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x68, 0xFF, 0x29, 0x98, 0xAD, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10, 0xD4, 0x21, 0xD4, 0xB2, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0xD0, 0x1A, 0xF0, 0x47, 0xFC, 0x20, 0x98, 0xAC, 0xC5, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x19, 0xF0 , +0xDB, 0xFA, 0x09, 0x49, 0x28, 0xC6, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x19, 0xF0, 0x9E, 0xFA, 0xDC, 0xD3, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xB5, 0x18, 0xF0, 0xAB, 0xFC, 0x00, 0xF0, 0x03, 0xF8, 0x00, 0xBD, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xDF, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x17, 0xF0, 0xA8, 0xFD, 0xCC, 0xEB, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x38, 0x78, 0x17, 0xF0, 0x77, 0xF8, 0x38, 0x78, 0x16, 0xF0, 0xF0, 0xFF, 0xA8, 0xF7, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0E, 0x49, 0x09, 0x68, 0x23, 0x22, 0x41, 0x61, 0xC8, 0xF7, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x31, 0x2E, 0x31, 0x39, 0x2E, 0x33, 0x31, 0x34, 0x5F, 0x4E, 0x65, 0x77, 0x5F, 0x43, 0x43, 0x41, 0x5F, 0x61, 0x6C, 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00, 0xC0, 0x74, 0x56, 0x30, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4C, 0xF9, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0xA8, 0x16, 0xF0, 0x79, 0xF8 , +0x12, 0xE0, 0x38, 0xFA, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0xA8, 0x16, 0xF0, 0x03, 0xF8, 0x32, 0x20, 0x94, 0xFB, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x0C, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x05, 0xA8, 0x14, 0xF0, 0x05, 0xFF, 0x01, 0xF0, 0x10, 0x1B, 0x01, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x1E, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x13, 0xF0, 0x46, 0xBF, 0x18, 0x30, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x30, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x12, 0xF0, 0xD8, 0xFC, 0x9C, 0x31, 0x01, 0x00, 0x08, 0x00 , +0x00, 0x00, 0x68, 0x46, 0x12, 0xF0, 0x51, 0xFC, 0xFE, 0xF7, 0xF0, 0x35, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x68, 0x46, 0x12, 0xF0, 0x27, 0xFA, 0xFE, 0xF7, 0xF0, 0x3D, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x05, 0xA9, 0x11, 0xF0, 0x27, 0xFE, 0x20, 0x6F, 0xD0, 0x62, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0F, 0xF0, 0xB8, 0xFB, 0x80, 0x7E, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0xDF, 0xF8, 0x58, 0x82, 0xE0, 0x7E, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0D, 0xF0, 0x6A, 0xFE, 0x0B, 0xF0, 0x9A, 0xF9, 0x03, 0x20, 0xA8, 0xF5, 0x88, 0x71, 0x08, 0x60, 0xF2, 0xF7, 0x16, 0xF9, 0x7A, 0x48, 0x6B, 0x49, 0x9C, 0x7F, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x70, 0x51, 0x4D, 0xC4, 0x7F, 0x01, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x40, 0x49, 0x00, 0xF1, 0x52, 0x00, 0x3A, 0x4A, 0xA8, 0x81, 0x28, 0x83, 0xE8, 0x83, 0xE8, 0x84, 0xA8, 0x85, 0x2A, 0x60, 0x39, 0x48, 0x41, 0xF2, 0x11, 0x12, 0x2A, 0x85, 0x18, 0x90, 0x19, 0x91 , +0x39, 0x49, 0x1A, 0x91, 0x39, 0x49, 0x1B, 0x91, 0x39, 0x49, 0x20, 0x46, 0xDF, 0xF8, 0xC4, 0x90, 0x1C, 0x91, 0x38, 0x49, 0xDF, 0xF8, 0xC0, 0xB0, 0x31, 0x4E, 0x1D, 0x91, 0x48, 0x80, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0D, 0xF0, 0x7C, 0xFA, 0xB4, 0x80, 0x01, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x12, 0x66, 0x09, 0x84, 0x6B, 0x00, 0x20, 0x94, 0x70, 0x00, 0x20, 0xB4, 0x70, 0x00, 0x20, 0xC4, 0x78, 0x00, 0x20, 0x50, 0x7A, 0x00, 0x20, 0xFE, 0xFF, 0x03, 0x00, 0xA4, 0x70, 0x00, 0x20, 0xB0, 0x70, 0x00, 0x20, 0xB8, 0x70, 0x00, 0x20, 0x60, 0x55, 0x30, 0x80, 0x3C, 0x5C, 0x00, 0x20, 0x04, 0x74, 0x00, 0x20, 0xB8, 0xE4, 0x01, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x20, 0x78, 0x07, 0xF0, 0x01, 0xFC, 0x20, 0x78, 0x07, 0xF0, 0x7A, 0xFB, 0x04, 0x4D, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x2D, 0xE9, 0xF0, 0x4F, 0xAD, 0xF1, 0x8C, 0x0D, 0x04, 0x68, 0x0F, 0x30, 0x03, 0x94, 0xFE, 0xF7, 0xDB, 0xFA, 0x04, 0xF1, 0x14, 0x00 , +0x04, 0x90, 0x21, 0x7D, 0x00, 0x20, 0x21, 0xF0, 0x73, 0x01, 0x88, 0x29, 0x08, 0xBF, 0x01, 0x20, 0x05, 0x90, 0x03, 0x98, 0x00, 0x1D, 0x06, 0x90, 0x5D, 0x48, 0x00, 0x68, 0x01, 0x28, 0x40, 0xF0, 0xFA, 0x83, 0x5B, 0x4D, 0x5C, 0x48, 0xDF, 0xF8, 0x70, 0x91, 0x29, 0x68, 0xDF, 0xF8, 0x70, 0x81, 0xDF, 0xF8, 0x74, 0xA1, 0x88, 0x42, 0x21, 0xD1, 0x10, 0x22, 0x00, 0x21, 0x48, 0x46, 0x4F, 0x46, 0xFB, 0xF7, 0xB7, 0xFE, 0x10, 0x22, 0x00, 0x21, 0x40, 0x46, 0xFB, 0xF7, 0xB2, 0xFE, 0x54, 0x49, 0x08, 0x68, 0x40, 0xF4, 0x80, 0x10, 0x08, 0x60, 0x01, 0x20, 0x51, 0x46, 0x08, 0x60, 0x00, 0x21, 0x29, 0x60, 0x39, 0x78, 0x46, 0x46, 0x00, 0x91, 0x31, 0x78, 0x41, 0xF2, 0x11, 0x13, 0x04, 0x22, 0x01, 0x91, 0x07, 0x21, 0x02, 0x90, 0x03, 0x20, 0xF3, 0xF7, 0x41, 0xFC, 0x51, 0x46, 0x07, 0x91, 0x08, 0x68, 0x56, 0x49, 0xDF, 0xF8, 0x5C, 0xB1, 0x01, 0x28, 0x08, 0x91, 0x56, 0x49, 0xDF, 0xF8, 0x48, 0xA1, 0x09, 0x91, 0x55, 0x49 , +0x0A, 0x91, 0x44, 0x49, 0x0B, 0x91, 0x44, 0x49, 0x0C, 0x91, 0x44, 0x49, 0x0D, 0x91, 0x44, 0x49, 0x0E, 0x91, 0x44, 0x49, 0x0F, 0x91, 0x44, 0x49, 0x10, 0x91, 0x44, 0x49, 0xCC, 0x4D, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x11, 0x91, 0x44, 0x49, 0x12, 0x91, 0x44, 0x49, 0x13, 0x91, 0x44, 0x49, 0x14, 0x91, 0x44, 0x49, 0x15, 0x91, 0x44, 0x49, 0x16, 0x91, 0x9F, 0x49, 0x17, 0x91, 0x9F, 0x49, 0x18, 0x91, 0x9F, 0x49, 0x19, 0x91, 0x9F, 0x49, 0x1A, 0x91, 0x9F, 0x49, 0x1B, 0x91, 0x9F, 0x49, 0x1C, 0x91, 0x9F, 0x49, 0x1D, 0x91, 0x9F, 0x49, 0x1E, 0x91, 0x9F, 0x49, 0x1F, 0x91, 0x40, 0xF0, 0x00, 0x81, 0x04, 0x98, 0x40, 0x78, 0x00, 0xF0, 0x03, 0x01, 0x01, 0x29, 0x40, 0xF0, 0xF9, 0x80, 0x04, 0x99, 0x09, 0x78, 0x01, 0xF0, 0x0C, 0x01, 0x08, 0x29, 0x40, 0xF0, 0xF2, 0x80, 0x06, 0x99, 0x09, 0x88, 0xA1, 0xF1, 0x3C, 0x01, 0x0E, 0xB2, 0x05, 0x99, 0x11, 0xB1, 0xA6, 0xF1, 0x02, 0x06, 0x36, 0xB2, 0xC0, 0x09, 0x4F, 0xF0 , +0x00, 0x07, 0x15, 0xD3, 0x08, 0x3E, 0x36, 0xB2, 0x03, 0x2E, 0x10, 0xD0, 0x17, 0x2E, 0x0E, 0xD0, 0x08, 0x3E, 0x36, 0xB2, 0x03, 0x2E, 0x08, 0xD0, 0x17, 0x2E, 0x06, 0xD0, 0x36, 0x1F, 0x36, 0xB2, 0x03, 0x2E, 0x14, 0xBF, 0x17, 0x2E, 0x02, 0x27, 0x02, 0xE0, 0x03, 0x27, 0x00, 0xE0, 0x01, 0x27, 0x03, 0x2E, 0x18, 0xBF, 0x17, 0x2E, 0x04, 0x9A, 0x40, 0xF0, 0xC8, 0x80, 0x0A, 0x32, 0x12, 0xF8, 0x01, 0x1B, 0x05, 0x24, 0x12, 0xF8, 0x01, 0x3B, 0x4B, 0x40, 0x64, 0x1E, 0xD9, 0xB2, 0xF9, 0xD1, 0x81, 0xEA, 0x21, 0x11, 0x03, 0x2E, 0x94, 0x4E, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x01, 0xF0, 0x0F, 0x01, 0x48, 0x46, 0x35, 0xD0, 0x43, 0x46, 0xCA, 0x5C, 0x52, 0x1C, 0xCA, 0x54, 0x0C, 0x18, 0x33, 0xE0, 0x50, 0x57, 0x02, 0x00, 0x04, 0x74, 0x00, 0x20, 0x34, 0x12, 0x66, 0x09, 0x60, 0x57, 0x02, 0x00, 0x70, 0x57, 0x02, 0x00, 0xC8, 0x48, 0x30, 0x80, 0x4C, 0x57, 0x02, 0x00, 0x88, 0x57, 0x02, 0x00, 0x80, 0x57, 0x02, 0x00 , +0x18, 0x58, 0x02, 0x00, 0x20, 0x58, 0x02, 0x00, 0x28, 0x58, 0x02, 0x00, 0x30, 0x58, 0x02, 0x00, 0x38, 0x58, 0x02, 0x00, 0x40, 0x58, 0x02, 0x00, 0xE4, 0x58, 0x02, 0x00, 0xE2, 0x58, 0x02, 0x00, 0x14, 0x58, 0x02, 0x00, 0xEF, 0x58, 0x02, 0x00, 0xE0, 0x58, 0x02, 0x00, 0xEE, 0x58, 0x02, 0x00, 0x5C, 0x57, 0x02, 0x00, 0xE6, 0x58, 0x02, 0x00, 0xE8, 0x58, 0x02, 0x00, 0x0C, 0x18, 0x20, 0x78, 0x40, 0x1C, 0x20, 0x70, 0x20, 0x78, 0x43, 0x46, 0x03, 0xEB, 0x01, 0x08, 0x0A, 0x28, 0x76, 0xDB, 0x98, 0xF8, 0x00, 0x00, 0x0A, 0x28, 0x72, 0xDB, 0x94, 0x48, 0x00, 0x25, 0x01, 0x60, 0x04, 0x98, 0x00, 0xF1, 0x0A, 0x09, 0x40, 0x78, 0x41, 0x08, 0x24, 0xBF, 0x04, 0x99, 0x09, 0x1D, 0x04, 0xD2, 0x80, 0x08, 0x2E, 0xBF, 0x49, 0x46, 0x04, 0x99, 0x10, 0x31, 0x0B, 0x98, 0x06, 0x22, 0xFA, 0xF7, 0xB9, 0xFC, 0x0C, 0x98, 0x06, 0x22, 0x49, 0x46, 0xFA, 0xF7, 0xB4, 0xFC, 0x9B, 0x48, 0x9A, 0x49, 0x5C, 0x4F, 0x02, 0x00, 0xC8, 0x00 , +0x00, 0x00, 0x00, 0x78, 0x08, 0x22, 0x08, 0x60, 0x58, 0x46, 0x07, 0x60, 0x0D, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0xAF, 0xFD, 0x08, 0x22, 0x0E, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0xAA, 0xFD, 0x08, 0x22, 0x0F, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0xA5, 0xFD, 0x08, 0x22, 0x10, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0xA0, 0xFD, 0x08, 0x22, 0x11, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0x9B, 0xFD, 0x08, 0x22, 0x12, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0x96, 0xFD, 0x07, 0x99, 0x02, 0x20, 0x08, 0x60, 0x13, 0x99, 0x28, 0x46, 0x08, 0x80, 0x08, 0x99, 0x08, 0x70, 0x14, 0x99, 0x08, 0x70, 0x15, 0x99, 0x08, 0x60, 0x16, 0x99, 0x08, 0x70, 0x17, 0x99, 0x08, 0x60, 0x18, 0x99, 0x08, 0x60, 0x19, 0x99, 0x08, 0x60, 0x09, 0x99, 0x08, 0x80, 0x0A, 0x99, 0x08, 0x80, 0x1A, 0x99, 0x08, 0x80, 0x7D, 0x49, 0x0D, 0x60, 0x1B, 0x99, 0x08, 0x70, 0x1C, 0x99, 0x08, 0x70, 0x1D, 0x99, 0x08, 0x70, 0x1E, 0x99, 0x08, 0x80, 0x1F, 0x99, 0x08, 0x80, 0x51, 0x46, 0x08, 0x80 , +0x20, 0x78, 0x00, 0x96, 0x04, 0x22, 0x01, 0x90, 0x98, 0xF8, 0x00, 0x00, 0x41, 0xF2, 0x14, 0x13, 0x07, 0x21, 0x02, 0x90, 0x03, 0x20, 0xF3, 0xF7, 0x07, 0xFB, 0x07, 0x98, 0xA2, 0x49, 0x00, 0x68, 0x20, 0x91, 0xA2, 0x49, 0x05, 0x28, 0x21, 0x91, 0x9E, 0x49, 0x22, 0x91, 0x40, 0xF0, 0x37, 0x82, 0x04, 0x98, 0x40, 0x78, 0x24, 0x50, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x41, 0x08, 0x24, 0xBF, 0x04, 0x99, 0x09, 0x1D, 0x05, 0xD2, 0x80, 0x08, 0x27, 0xBF, 0x04, 0x99, 0x0A, 0x31, 0x04, 0x99, 0x10, 0x31, 0x0B, 0x98, 0xF8, 0xF7, 0x2D, 0xFC, 0x01, 0x28, 0x04, 0x98, 0x40, 0xF0, 0x23, 0x82, 0x40, 0x78, 0x00, 0xF0, 0x03, 0x00, 0x03, 0x28, 0x18, 0xD0, 0x02, 0x28, 0x07, 0xBF, 0x04, 0x99, 0x10, 0x31, 0x04, 0x99, 0x0A, 0x31, 0x13, 0xE0, 0x48, 0x58, 0x02, 0x00, 0x4C, 0x58, 0x02, 0x00, 0x50, 0x58, 0x02, 0x00, 0xF0, 0x58, 0x02, 0x00, 0xF2, 0x58, 0x02, 0x00, 0xF3, 0x58, 0x02, 0x00, 0xF4, 0x58, 0x02, 0x00, 0xEA, 0x58 , +0x02, 0x00, 0xEC, 0x58, 0x02, 0x00, 0x04, 0x99, 0x18, 0x31, 0x0C, 0x98, 0xF8, 0xF7, 0x06, 0xFC, 0x04, 0x99, 0x01, 0x28, 0x40, 0xF0, 0xFC, 0x81, 0x49, 0x78, 0x01, 0xF0, 0x03, 0x01, 0x01, 0x29, 0x40, 0xF0, 0xF6, 0x81, 0x59, 0x46, 0x09, 0x68, 0x04, 0x9A, 0x8E, 0x46, 0x51, 0x46, 0xD2, 0x8A, 0x0B, 0x88, 0x12, 0x11, 0x93, 0x42, 0x00, 0xF0, 0x37, 0x82, 0x0A, 0x80, 0x06, 0x99, 0x09, 0x88, 0x3C, 0x39, 0x0B, 0xB2, 0x71, 0x46, 0x49, 0x1E, 0x09, 0xD0, 0x49, 0x1E, 0x04, 0xD0, 0x49, 0x1E, 0x08, 0xD1, 0xA3, 0xF1, 0x10, 0x03, 0x04, 0xE0, 0xA3, 0xF1, 0x14, 0x03, 0x01, 0xE0, 0xA3, 0xF1, 0x08, 0x03, 0x1B, 0xB2, 0x05, 0x98, 0x10, 0xB1, 0xA3, 0xF1, 0x02, 0x03, 0x1B, 0xB2, 0xEC, 0x50, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0xF1, 0xCE, 0x81, 0x16, 0x98, 0x40, 0xF2, 0x77, 0x51, 0x99, 0x42, 0x0B, 0x90, 0x14, 0x98, 0x05, 0x90, 0x00, 0xF0, 0xA3, 0x81, 0x08, 0x46, 0x00, 0xF1, 0x3C, 0x00, 0x98, 0x42 , +0x05, 0x9A, 0x00, 0xF0, 0x9A, 0x81, 0xDF, 0xF8, 0x48, 0x82, 0x14, 0x78, 0x0B, 0x9A, 0xBB, 0x2C, 0x12, 0x78, 0x0C, 0x92, 0x63, 0xD1, 0xDD, 0xF8, 0x68, 0xC0, 0xBC, 0xF9, 0x00, 0x20, 0x91, 0x42, 0x18, 0xBF, 0x90, 0x42, 0x5B, 0xD1, 0x1C, 0x2B, 0x4F, 0xF0, 0x00, 0x00, 0xC0, 0xF2, 0x82, 0x81, 0x3D, 0x2B, 0x13, 0x9D, 0x80, 0xF2, 0x7E, 0x81, 0xA3, 0xF1, 0x1C, 0x01, 0x09, 0xB2, 0x29, 0x80, 0x1E, 0x9A, 0xDD, 0xF8, 0x30, 0x90, 0xB2, 0xF9, 0x00, 0x60, 0xB9, 0xF1, 0x01, 0x0F, 0x15, 0xD1, 0xDD, 0xF8, 0x24, 0x90, 0x03, 0x2E, 0x0D, 0xDA, 0xB9, 0xF9, 0x00, 0x70, 0xB9, 0x42, 0x07, 0xD0, 0x01, 0x26, 0x16, 0x80, 0x4A, 0x46, 0x0E, 0x46, 0x03, 0xE0, 0xC0, 0x46, 0x90, 0x57, 0x02, 0x00, 0x76, 0x1C, 0x16, 0x80, 0x1B, 0x9A, 0x16, 0x78, 0x1D, 0x9A, 0x16, 0x70, 0x0C, 0x9A, 0x1F, 0x9E, 0x02, 0x2A, 0x28, 0xD1, 0xB6, 0xF9, 0x00, 0x20, 0xBE, 0xF1, 0x00, 0x0F, 0x1A, 0xD0, 0x03, 0x2A, 0x35, 0x46, 0x0B, 0xDA, 0x0A, 0x9E , +0xB6, 0xF9, 0x00, 0x70, 0xB9, 0x42, 0x04, 0xD0, 0x01, 0x22, 0x2A, 0x80, 0x0A, 0x46, 0x35, 0x46, 0x00, 0xE0, 0xB4, 0x51, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x52, 0x1C, 0x2A, 0x80, 0x1C, 0x99, 0x0A, 0x78, 0x1D, 0x99, 0x0A, 0x70, 0x0F, 0xE0, 0xC0, 0x46, 0x58, 0x57, 0x02, 0x00, 0xA6, 0x64, 0x00, 0x20, 0x54, 0x57, 0x02, 0x00, 0x28, 0x80, 0x05, 0x99, 0x08, 0x70, 0x08, 0x9A, 0x11, 0x78, 0x41, 0xF0, 0x04, 0x01, 0x11, 0x70, 0x04, 0x46, 0x45, 0x46, 0xAC, 0xF8, 0x00, 0x00, 0x28, 0x70, 0xCC, 0x2C, 0x09, 0x9A, 0x40, 0xF0, 0x00, 0x81, 0xDD, 0xF8, 0x7C, 0xC0, 0x0A, 0x99, 0x1E, 0x9F, 0x45, 0x46, 0xB1, 0xF9, 0x00, 0x60, 0xB2, 0xF9, 0x00, 0x90, 0x28, 0x78, 0xCD, 0xF8, 0x50, 0xC0, 0x16, 0x91, 0x0A, 0x97, 0x13, 0x92, 0x09, 0x95, 0x0C, 0x99, 0x01, 0x29, 0x05, 0xD1, 0x05, 0x9A, 0xB0, 0xEB, 0x49, 0x0F, 0x01, 0xD1, 0x00, 0x21, 0x11, 0x70, 0x0C, 0x99, 0x02, 0x29, 0x05, 0xD1, 0x05, 0x9A, 0xB0, 0xEB, 0x46, 0x0F , +0x01, 0xD1, 0x00, 0x21, 0x11, 0x70, 0xB3, 0xF5, 0x14, 0x7F, 0x40, 0xF3, 0xBA, 0x80, 0x40, 0xF2, 0x51, 0x31, 0x99, 0x42, 0x08, 0x99, 0x40, 0xF3, 0xB4, 0x80, 0x09, 0x78, 0x06, 0x29, 0x00, 0xF0, 0xB0, 0x80, 0xA3, 0xF2, 0x51, 0x21, 0x0B, 0xB2, 0x4F, 0xEA, 0xE3, 0x01, 0x03, 0xEB, 0x11, 0x71, 0x4F, 0xEA, 0x21, 0x11, 0xCA, 0xB2, 0x4F, 0xEA, 0xE3, 0x01, 0x03, 0xEB, 0x11, 0x71, 0x15, 0x9D, 0x21, 0xF0, 0x0F, 0x01, 0xA3, 0xEB, 0x01, 0x03, 0x1D, 0x99, 0x2E, 0x68, 0x7C, 0x52, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x91, 0xF8, 0x00, 0xE0, 0x5F, 0xFA, 0x83, 0xF8, 0x60, 0xB1, 0x31, 0x18, 0x11, 0xF8, 0x01, 0x1C, 0x51, 0x40, 0xCB, 0xB2, 0x07, 0xE0, 0xC0, 0x46, 0x58, 0x58, 0x02, 0x00, 0x54, 0x58, 0x02, 0x00, 0xDC, 0x58, 0x02, 0x00, 0x13, 0x46, 0x19, 0x99, 0xDD, 0xF8, 0x6C, 0xA0, 0xDD, 0xF8, 0x70, 0xB0, 0xD1, 0xF8, 0x00, 0xC0, 0x00, 0xF0, 0x0F, 0x01, 0x99, 0x42, 0x22, 0xD0, 0x0A, 0x9B, 0x86, 0x45, 0x9A, 0xF8 , +0x00, 0x10, 0xB3, 0xF9, 0x00, 0x30, 0x9B, 0xF8, 0x00, 0x50, 0x15, 0xDD, 0x37, 0x5C, 0x44, 0x1C, 0x82, 0xEA, 0x07, 0x0C, 0x04, 0xF0, 0x0F, 0x07, 0x67, 0x45, 0x0B, 0xD0, 0xA6, 0x45, 0x06, 0x44, 0x0A, 0xDD, 0x76, 0x78, 0x72, 0x40, 0x86, 0x1C, 0x06, 0xF0, 0x0F, 0x06, 0x96, 0x42, 0x03, 0xD1, 0xC0, 0x1C, 0x4D, 0xE0, 0x80, 0x1C, 0x4B, 0xE0, 0x05, 0x9E, 0x00, 0x22, 0x32, 0x70, 0x4A, 0xE0, 0x00, 0xF0, 0x1F, 0x01, 0x01, 0x22, 0x8A, 0x40, 0x17, 0x99, 0xC4, 0x10, 0x0B, 0x68, 0x24, 0xF0, 0x03, 0x01, 0x5C, 0xF8, 0x01, 0x70, 0x3A, 0x42, 0x32, 0xD1, 0x5F, 0x58, 0x3A, 0x42, 0x06, 0x44, 0x1F, 0xD0, 0x18, 0x9B, 0x37, 0x78, 0x1B, 0x68, 0xB8, 0x45, 0x04, 0xD1, 0x58, 0x58, 0x02, 0x42, 0x19, 0xD0, 0x63, 0x46, 0x15, 0xE0, 0xA1, 0x10, 0x8C, 0x00, 0x19, 0x59, 0x91, 0x43, 0x19, 0x51, 0x00, 0x90, 0x30, 0x78, 0x01, 0x90, 0x44, 0x53, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x03, 0x20, 0x06, 0x21, 0x02, 0x46, 0x4D, 0xF6 , +0x80, 0x53, 0xF3, 0xF7, 0x63, 0xF9, 0x09, 0x99, 0x28, 0x68, 0x0E, 0x78, 0x36, 0x18, 0x06, 0xE0, 0xE3, 0x58, 0x02, 0x00, 0xA0, 0x10, 0x81, 0x00, 0x58, 0x58, 0x02, 0x43, 0x5A, 0x50, 0x86, 0xF8, 0x00, 0x80, 0x0B, 0x98, 0x00, 0x78, 0x0C, 0x90, 0x13, 0x98, 0xB0, 0xF9, 0x00, 0x90, 0x09, 0x98, 0x00, 0x78, 0x0A, 0x9A, 0x40, 0x1C, 0x9B, 0xF8, 0x00, 0x50, 0x9A, 0xF8, 0x00, 0x10, 0xB2, 0xF9, 0x00, 0x30, 0x09, 0x9A, 0xC0, 0xB2, 0x10, 0x70, 0x0C, 0x9A, 0x01, 0x2A, 0x03, 0xD1, 0x88, 0x42, 0xC8, 0xBF, 0x8A, 0xF8, 0x00, 0x00, 0x0C, 0x99, 0x02, 0x29, 0x07, 0xD1, 0xA8, 0x42, 0xC8, 0xBF, 0x8B, 0xF8, 0x00, 0x00, 0x02, 0xE0, 0x0A, 0x98, 0xB0, 0xF9, 0x00, 0x30, 0xB9, 0xF1, 0x00, 0x0F, 0x06, 0xDD, 0x03, 0x2B, 0x04, 0xD1, 0x11, 0x98, 0x01, 0x22, 0x49, 0x46, 0x00, 0xF0, 0x72, 0xFB, 0x16, 0x98, 0xB0, 0xF9, 0x00, 0x10, 0x14, 0x98, 0x00, 0x29, 0xB0, 0xF9, 0x00, 0x00, 0x05, 0xDD, 0x03, 0x28, 0x03, 0xD1, 0x12, 0x98 , +0x02, 0x22, 0x00, 0xF0, 0x64, 0xFB, 0x05, 0x98, 0x04, 0x78, 0x0B, 0x98, 0x00, 0x78, 0x0C, 0x90, 0x08, 0x98, 0xBB, 0x2C, 0x01, 0x78, 0x02, 0xD0, 0xAA, 0x2C, 0x2F, 0xD0, 0x31, 0xE0, 0x0C, 0x98, 0x01, 0x28, 0x0B, 0xD1, 0x0D, 0x98, 0x17, 0x9A, 0x10, 0x60, 0x0C, 0x54, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x0F, 0x98, 0x18, 0x9A, 0x10, 0x60, 0x19, 0x9A, 0x11, 0x98, 0x10, 0x60, 0x47, 0x4A, 0x15, 0x98, 0x02, 0x60, 0x0C, 0x98, 0x02, 0x28, 0x0B, 0xD1, 0x0E, 0x98, 0x17, 0x9A, 0x10, 0x60, 0x10, 0x98, 0x18, 0x9A, 0x10, 0x60, 0x19, 0x9A, 0x12, 0x98, 0x10, 0x60, 0x41, 0x4A, 0x15, 0x98, 0x02, 0x60, 0xCC, 0x20, 0x0F, 0xE0, 0x08, 0x99, 0x09, 0x78, 0x0C, 0xE0, 0x02, 0x20, 0x00, 0xE0, 0x01, 0x20, 0x0B, 0x99, 0x08, 0x70, 0x1A, 0x99, 0x0B, 0x80, 0x13, 0x99, 0x00, 0x20, 0x08, 0x80, 0x08, 0x98, 0x01, 0x78, 0xBB, 0x20, 0x05, 0x9A, 0x10, 0x70, 0x06, 0x29, 0x07, 0x99, 0x11, 0xD1, 0x06, 0x20, 0x08, 0x60, 0x20, 0x98 , +0x00, 0x25, 0x05, 0x70, 0x21, 0x98, 0x29, 0x46, 0x04, 0x22, 0xFB, 0xF7, 0x27, 0xFB, 0x01, 0x20, 0x00, 0xF0, 0x3A, 0xFA, 0x02, 0x20, 0x00, 0xF0, 0x37, 0xFA, 0x22, 0x98, 0x05, 0x60, 0x07, 0x98, 0x04, 0x99, 0x00, 0x68, 0x07, 0x28, 0x44, 0xD1, 0x09, 0x78, 0x03, 0x9C, 0x80, 0x29, 0x40, 0xD1, 0x38, 0x34, 0x21, 0x78, 0x64, 0x1C, 0x22, 0x46, 0x00, 0x29, 0x3A, 0xD1, 0x20, 0x98, 0x90, 0xF8, 0x00, 0xA0, 0x22, 0x98, 0x05, 0x90, 0xD0, 0xF8, 0x00, 0x90, 0x51, 0x46, 0x48, 0x46, 0xFD, 0xF7, 0x79, 0xF9, 0x5F, 0xFA, 0x80, 0xF8, 0x21, 0x9F, 0x15, 0x78, 0x51, 0x46, 0x48, 0x46, 0x17, 0xF8, 0x08, 0x30, 0xFD, 0xF7, 0xD4, 0x54, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x6F, 0xF9, 0x1E, 0x46, 0x1B, 0x1D, 0xC0, 0xB2, 0x38, 0x5C, 0x00, 0x1D, 0xA8, 0x42, 0x28, 0x46, 0x07, 0xDD, 0x80, 0x18, 0x82, 0x1C, 0x10, 0x78, 0x2D, 0x18, 0xAD, 0x1C, 0xAD, 0xB2, 0xAB, 0x42, 0xF7, 0xDC, 0x04, 0xF8, 0x01, 0x6B, 0x11, 0x49, 0x32, 0x46 , +0x20, 0x46, 0x01, 0xEB, 0x48, 0x11, 0xFA, 0xF7, 0xDC, 0xF9, 0xAD, 0x1B, 0xFF, 0x20, 0x34, 0x19, 0xAD, 0x1E, 0x04, 0xF8, 0x01, 0x0B, 0x25, 0x70, 0x05, 0x98, 0x01, 0x68, 0x49, 0x1C, 0x01, 0x60, 0x07, 0x98, 0x00, 0x68, 0x07, 0x28, 0x04, 0xD0, 0x06, 0x99, 0x08, 0x68, 0x20, 0xF4, 0x80, 0x30, 0x08, 0x60, 0x23, 0xB0, 0xBD, 0xE8, 0xF0, 0x8F, 0xC0, 0x46, 0x94, 0x57, 0x02, 0x00, 0xD4, 0x57, 0x02, 0x00, 0x5C, 0x58, 0x02, 0x00, 0x6E, 0x48, 0x2D, 0xE9, 0xF0, 0x47, 0x6E, 0x4D, 0x82, 0x89, 0x4A, 0xF6, 0x55, 0x21, 0xAD, 0xF5, 0xFE, 0x7D, 0x91, 0x42, 0x4F, 0xF0, 0x00, 0x01, 0xAD, 0xF1, 0x38, 0x0D, 0x12, 0xD1, 0x29, 0x60, 0x68, 0x4A, 0x11, 0x70, 0x41, 0xF2, 0x10, 0x41, 0x81, 0x81, 0x4F, 0xF6, 0xFF, 0x70, 0x66, 0x49, 0x08, 0x60, 0x28, 0x68, 0x00, 0x90, 0x02, 0x22, 0x05, 0x21, 0x03, 0x20, 0x41, 0xF2, 0x34, 0x23, 0xF3, 0xF7, 0x48, 0xF8, 0x29, 0x68, 0x61, 0x4C, 0x01, 0x29, 0x20, 0x68, 0x40, 0xF0, 0xAF, 0x80 , +0x5F, 0x4D, 0x02, 0x28, 0x29, 0x68, 0x23, 0xD1, 0x9C, 0x55, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x5E, 0x48, 0x00, 0x68, 0x5F, 0x4A, 0x12, 0x5C, 0x00, 0x92, 0x01, 0x91, 0x5E, 0x49, 0x09, 0x68, 0x02, 0x91, 0x5B, 0x49, 0x0B, 0x5C, 0x03, 0x20, 0x07, 0x21, 0x04, 0x22, 0xF3, 0xF7, 0x2E, 0xF8, 0x5B, 0x49, 0x4A, 0x79, 0x59, 0x48, 0x00, 0x92, 0x02, 0x79, 0x01, 0x92, 0x40, 0x79, 0x04, 0x22, 0x02, 0x90, 0x03, 0x20, 0x0B, 0x79, 0x07, 0x21, 0xF3, 0xF7, 0x20, 0xF8, 0x03, 0x20, 0x20, 0x60, 0xEC, 0xF7, 0x1A, 0xFF, 0x20, 0x68, 0x29, 0x68, 0x04, 0x28, 0x15, 0xD1, 0x0D, 0x20, 0x8D, 0xF8, 0x10, 0x00, 0x00, 0x25, 0x8D, 0xF8, 0x14, 0x50, 0x8D, 0xF8, 0x15, 0x10, 0x28, 0x46, 0x63, 0x21, 0x00, 0xF0, 0xAA, 0xFB, 0x63, 0x21, 0x28, 0x46, 0x00, 0xF0, 0xFA, 0xFA, 0x03, 0xA9, 0x04, 0xA8, 0xE0, 0xF7, 0xCA, 0xFC, 0x05, 0x20, 0x20, 0x60, 0x46, 0x4D, 0x05, 0x28, 0x29, 0x68, 0x01, 0xF1, 0x01, 0x01, 0x29, 0x60, 0x1D, 0xD1 , +0x44, 0x4A, 0x8A, 0x42, 0x1A, 0xD1, 0x43, 0x48, 0x01, 0x68, 0x00, 0x91, 0x40, 0x68, 0x01, 0x90, 0x03, 0x20, 0x02, 0x46, 0x06, 0x21, 0x41, 0x4E, 0x33, 0x46, 0x22, 0x3B, 0xF2, 0xF7, 0xEB, 0xFF, 0x3E, 0x48, 0x01, 0x68, 0x00, 0x91, 0x40, 0x68, 0x33, 0x46, 0x06, 0x21, 0x01, 0x90, 0x03, 0x20, 0x02, 0x46, 0xF2, 0xF7, 0xE0, 0xFF, 0x00, 0x20, 0x28, 0x60, 0x20, 0x68, 0x06, 0x28, 0x47, 0xD1, 0x4F, 0xF0, 0x64, 0x56, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x07, 0x0A, 0xC4, 0xF8, 0x00, 0xA0, 0x03, 0x20, 0x48, 0xF2, 0x70, 0x53, 0x01, 0x22, 0x04, 0x21, 0xF2, 0xF7, 0xD0, 0xFF, 0xDF, 0xF8, 0xCC, 0x80, 0x31, 0x4F, 0x48, 0xF2, 0x70, 0x59, 0x01, 0x25, 0x49, 0xEA, 0x05, 0x03, 0x01, 0x22, 0x04, 0x21, 0x03, 0x20, 0xF2, 0xF7, 0xC3, 0xFF, 0x00, 0x24, 0x17, 0xF8, 0x02, 0x0F, 0x20, 0xE0, 0x69, 0x01, 0x04, 0xEB, 0x08, 0x02, 0x88, 0x18, 0xC6, 0x1C, 0x43, 0x78, 0x00, 0x93, 0x80, 0x78, 0x01, 0x90, 0x30, 0x78, 0x02, 0x90 , +0x53, 0x5C, 0x51, 0x46, 0x04, 0x22, 0x03, 0x20, 0xF2, 0xF7, 0xAE, 0xFF, 0x38, 0x78, 0x01, 0x1B, 0xB1, 0xF1, 0xFF, 0x3F, 0x08, 0xD1, 0xF0, 0x78, 0x00, 0x90, 0xB3, 0x78, 0x03, 0x20, 0x02, 0x22, 0x05, 0x21, 0xF2, 0xF7, 0xA1, 0xFF, 0x38, 0x78, 0x24, 0x1D, 0xE4, 0xB2, 0xA0, 0x42, 0xDC, 0xDC, 0xAD, 0x1C, 0xED, 0xB2, 0x04, 0x2D, 0xCD, 0xDB, 0x63, 0x21, 0x4F, 0xF4, 0x05, 0x70, 0xF1, 0xF7, 0xA3, 0xFC, 0xE1, 0xF7, 0x85, 0xFD, 0x7F, 0xB0, 0x0E, 0xB0, 0xBD, 0xE8, 0xF0, 0x87, 0xC0, 0x46, 0x04, 0x74, 0x00, 0x20, 0x50, 0x57, 0x02, 0x00, 0x6C, 0x5D, 0x02, 0x00, 0x40, 0x00, 0x3D, 0x80, 0x4C, 0x57, 0x02, 0x00, 0x58, 0x57, 0x02, 0x00, 0x90, 0x57, 0x02, 0x00, 0x60, 0x57, 0x02, 0x00, 0x70, 0x57, 0x02, 0x00, 0x5C, 0x57, 0x02, 0x00, 0x80, 0x57, 0x02, 0x00, 0x2C, 0x57, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x88, 0x57, 0x02, 0x00, 0x54, 0x57, 0x02, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x38, 0x58, 0x02, 0x00, 0x40, 0x58 , +0x02, 0x00, 0x66, 0x55, 0xDD, 0xEE, 0xDB, 0x58, 0x02, 0x00, 0x5C, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF4, 0x57, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBC, 0x58, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2D, 0xE9, 0xFE, 0x4F, 0x4A, 0x4A, 0x49, 0x4D, 0x00, 0x90, 0xB2, 0xF9, 0x00, 0x20, 0x43, 0xA3, 0x29, 0x78, 0x01, 0x93, 0x43, 0xA3, 0x01, 0x28, 0x02, 0x93, 0x47, 0x4E, 0xDF, 0xF8, 0x1C, 0x81, 0xDF, 0xF8, 0x1C, 0x91, 0x1E, 0xD0, 0x43, 0x48, 0x04, 0x78, 0x48, 0x01, 0x87, 0x19, 0x30, 0x18, 0x01, 0x99, 0x06, 0x22, 0xF9, 0xF7, 0xC8, 0xFF, 0x40, 0x46, 0x01, 0x78, 0x00, 0x68, 0x07, 0xF1, 0x06, 0x07, 0x07, 0xF8, 0x01, 0x1B, 0x07, 0xF8, 0x01, 0x4B, 0x4F, 0xF0, 0x00, 0x01, 0x07, 0xF8, 0x01, 0x1B, 0x20, 0xB9, 0x39, 0x70, 0x28, 0x78, 0x4E, 0x46, 0x0A, 0x21, 0x58, 0xE0, 0xDF, 0xF8, 0xE4, 0xB0, 0x0F, 0xE0, 0xD4, 0xB2, 0x48, 0x01, 0x87, 0x19, 0x30, 0x18, 0x02, 0x99, 0x07, 0x22, 0xF9, 0xF7, 0xAA, 0xFF, 0xFF, 0x1D, 0x00, 0x20, 0xDF, 0xF8, 0xCC, 0xB0, 0x07, 0xF8, 0x01, 0x4B, 0x07, 0xF8, 0x01, 0x0B, 0x16, 0x2C, 0xB2, 0x46, 0xAE, 0xBF, 0x14, 0x20, 0x84, 0x59 , +0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x60, 0x1E, 0xC0, 0xB2, 0x38, 0x70, 0x4E, 0x46, 0x7F, 0x1C, 0x40, 0x1C, 0xC2, 0xB2, 0x28, 0x78, 0x5B, 0x46, 0x00, 0x21, 0x32, 0x54, 0x38, 0x46, 0x00, 0xF0, 0xBC, 0xF9, 0x28, 0x78, 0x16, 0x2C, 0x31, 0x5C, 0x01, 0xF1, 0x0A, 0x01, 0x31, 0x54, 0x00, 0xF1, 0x01, 0x00, 0xC0, 0xB2, 0x28, 0x70, 0x2B, 0xDB, 0x00, 0x99, 0x0A, 0xEB, 0x40, 0x10, 0x07, 0x46, 0x01, 0x29, 0xA4, 0xF1, 0x01, 0x09, 0x09, 0xD0, 0x01, 0x99, 0x06, 0x22, 0xF9, 0xF7, 0x79, 0xFF, 0x40, 0x46, 0x00, 0x78, 0xBF, 0x1D, 0x07, 0xF8, 0x01, 0x0B, 0x04, 0xE0, 0x02, 0x99, 0x07, 0x22, 0xF9, 0xF7, 0x6F, 0xFF, 0xFF, 0x1D, 0x07, 0xF8, 0x01, 0x4B, 0x15, 0x3C, 0x15, 0x21, 0x28, 0x78, 0xE2, 0xB2, 0x5B, 0x46, 0x07, 0xF8, 0x01, 0x1B, 0x32, 0x54, 0x07, 0xF8, 0x01, 0x9B, 0x38, 0x46, 0x00, 0xF0, 0x8B, 0xF9, 0x28, 0x78, 0x31, 0x5C, 0x0A, 0x31, 0x31, 0x54, 0x40, 0x1C, 0x28, 0x70, 0xBD, 0xE8, 0xFE, 0x8F, 0xC0, 0x46 , +0x54, 0x54, 0x54, 0x4B, 0x45, 0x59, 0x00, 0xC0, 0x54, 0x54, 0x54, 0x53, 0x53, 0x49, 0x44, 0x00, 0x54, 0x58, 0x02, 0x00, 0xE6, 0x58, 0x02, 0x00, 0xE8, 0x58, 0x02, 0x00, 0x5C, 0x58, 0x02, 0x00, 0x5C, 0x57, 0x02, 0x00, 0xDC, 0x58, 0x02, 0x00, 0xD4, 0x57, 0x02, 0x00, 0x94, 0x57, 0x02, 0x00, 0xFF, 0xB5, 0x0C, 0x46, 0x06, 0x46, 0xF7, 0xF7, 0x4C, 0x5A, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0xE3, 0xFE, 0x15, 0x49, 0x15, 0x4A, 0x0D, 0x68, 0x01, 0xA9, 0x92, 0xE8, 0x8C, 0x00, 0x81, 0xE8, 0x8C, 0x00, 0xF7, 0xF7, 0xFD, 0xFE, 0x01, 0x98, 0x11, 0x49, 0x28, 0x1A, 0x03, 0x9D, 0x25, 0x60, 0x02, 0x9A, 0x80, 0x18, 0x82, 0x42, 0x30, 0x60, 0x0E, 0xD8, 0x08, 0x46, 0x00, 0x68, 0x22, 0x68, 0x82, 0x42, 0x0E, 0xD2, 0x68, 0x46, 0xE8, 0xF7, 0xB9, 0xFF, 0x9D, 0xF8, 0x00, 0x00, 0x05, 0xF1, 0x01, 0x05, 0x30, 0xB9, 0x03, 0x95, 0x03, 0xE0, 0x25, 0x68, 0x6D, 0x1C, 0x25, 0x60, 0x0C, 0x46, 0x25, 0x60, 0x00, 0x20, 0x00, 0x90 , +0xFF, 0xBD, 0x60, 0x55, 0x30, 0x80, 0x24, 0x5D, 0x00, 0x20, 0x6C, 0x5D, 0x02, 0x00, 0x70, 0xB5, 0x4D, 0x00, 0x20, 0x2D, 0x4F, 0xF0, 0x00, 0x01, 0x0C, 0x46, 0x4F, 0xEA, 0x55, 0x13, 0x09, 0xD3, 0x50, 0xF8, 0x21, 0x60, 0xB6, 0xF1, 0xFF, 0x3F, 0x04, 0xD1, 0x49, 0x1C, 0xC9, 0xB2, 0x20, 0x3D, 0x5B, 0x1E, 0xF5, 0xD1, 0x4D, 0xB1, 0x20, 0x2D, 0x09, 0xD2, 0x01, 0x23, 0xAB, 0x40, 0x5B, 0x1E, 0x50, 0xF8, 0x21, 0x00, 0x18, 0x40, 0x83, 0x42, 0x01, 0xD1, 0x4F, 0xF0, 0x01, 0x04, 0x07, 0x48, 0x03, 0x78, 0x2C, 0xB9, 0x01, 0x21, 0x91, 0x40, 0xC9, 0x43, 0xC9, 0xB2, 0x0B, 0x40, 0x03, 0xE0, 0x01, 0x21, 0x91, 0x40, 0xC9, 0xB2, 0x0B, 0x43, 0x03, 0x70, 0x70, 0xBD, 0xC0, 0x46, 0xEE, 0x58, 0x02, 0x00, 0x14, 0x5B, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x7E, 0xB5, 0x05, 0x46, 0x95, 0xF8, 0x36, 0x20, 0x0E, 0x46, 0x0F, 0x49, 0x07, 0x2A, 0x12, 0xBF, 0x08, 0x68, 0x01, 0x20, 0x08, 0x60, 0x0D, 0x4C, 0x00, 0x92, 0x21, 0x68 , +0x41, 0xF2, 0x12, 0x13, 0x04, 0x22, 0x01, 0x91, 0x07, 0x21, 0x02, 0x90, 0x03, 0x20, 0xF2, 0xF7, 0x6B, 0xFD, 0x31, 0x46, 0x28, 0x46, 0xE7, 0xF7, 0x21, 0xFC, 0x21, 0x68, 0x00, 0x22, 0x05, 0x29, 0x02, 0xD1, 0x04, 0x49, 0x08, 0x31, 0x0A, 0x60, 0x7E, 0xBD, 0xC0, 0x46, 0x50, 0x57, 0x02, 0x00, 0x4C, 0x57, 0x02, 0x00, 0x00, 0x7C, 0x00, 0x20, 0x0E, 0x49, 0x09, 0x68, 0x49, 0x08, 0x15, 0xD2, 0x0D, 0x49, 0x09, 0x78, 0x91, 0xB1, 0x44, 0xF2, 0xE9, 0x21, 0x68, 0xB9, 0x0B, 0x48, 0x01, 0x78, 0x07, 0x48, 0x01, 0x29, 0x03, 0xD1, 0x0A, 0x49, 0x09, 0x78, 0x0E, 0x29, 0x02, 0xD0, 0x44, 0xF2, 0xDE, 0x21, 0x41, 0x60, 0x01, 0x21, 0x00, 0xE0, 0x06, 0x48, 0x01, 0x60, 0x70, 0x47, 0xC0, 0x46, 0x00, 0x97, 0x3C, 0x80, 0x10, 0x0C, 0x30, 0x80, 0xDD, 0x6A, 0x00, 0x20, 0xE0, 0x7C, 0x00, 0x20, 0xA6, 0x64, 0x00, 0x20, 0x04, 0x97, 0x3C, 0x80, 0x00, 0xB5, 0xAD, 0xF1, 0x18, 0x0D, 0x4F, 0xF0, 0x09, 0x00, 0x00, 0x90, 0x4F, 0xF4 , +0x0C, 0x60, 0x03, 0x90, 0x4F, 0xF0, 0x00, 0x00, 0x01, 0x90, 0x02, 0x90, 0x08, 0x48, 0x08, 0x49, 0x05, 0x90, 0x08, 0x68, 0x20, 0xB9, 0xDC, 0x5B, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x68, 0x46, 0x03, 0x22, 0xED, 0xF7, 0x3A, 0xFA, 0x03, 0xE0, 0x68, 0x46, 0x03, 0x22, 0xED, 0xF7, 0xC1, 0xFC, 0x06, 0xB0, 0x00, 0xBD, 0xC0, 0x46, 0x81, 0x5C, 0x02, 0x00, 0xDC, 0x7C, 0x00, 0x20, 0x1C, 0xB5, 0x0F, 0x4C, 0x22, 0x68, 0x01, 0x2A, 0x15, 0xD1, 0x0C, 0x48, 0x00, 0x68, 0x07, 0x28, 0x14, 0xBF, 0x40, 0x20, 0x4F, 0xF4, 0x05, 0x70, 0x63, 0x21, 0xF1, 0xF7, 0x0F, 0xFA, 0x20, 0x68, 0x00, 0x90, 0x43, 0xF2, 0x33, 0x33, 0x06, 0x21, 0x40, 0x20, 0x01, 0x90, 0x03, 0x20, 0x02, 0x46, 0xF2, 0xF7, 0xF4, 0xFC, 0x1C, 0xBD, 0xF1, 0xF7, 0x01, 0xFA, 0x1C, 0xBD, 0x4C, 0x57, 0x02, 0x00, 0x50, 0x57, 0x02, 0x00, 0x1E, 0xB5, 0x04, 0x46, 0x0A, 0x49, 0x00, 0x20, 0x0A, 0x4A, 0x08, 0x60, 0x0A, 0x49, 0x00, 0x90, 0x01, 0x90, 0x11, 0x60 , +0x09, 0x4A, 0x45, 0xF2, 0x55, 0x53, 0x02, 0x91, 0x10, 0x60, 0x07, 0x21, 0x04, 0x22, 0x03, 0x20, 0xF2, 0xF7, 0xD8, 0xFC, 0x20, 0x46, 0xE7, 0xF7, 0x59, 0xFD, 0x1E, 0xBD, 0x50, 0x57, 0x02, 0x00, 0x04, 0x74, 0x00, 0x20, 0x34, 0x12, 0x66, 0x09, 0x4C, 0x57, 0x02, 0x00, 0x00, 0xB5, 0x0B, 0x49, 0x00, 0x20, 0x08, 0x60, 0xE0, 0x20, 0xF7, 0xF7, 0xAA, 0xFD, 0x09, 0x49, 0x09, 0x78, 0x49, 0xB1, 0x08, 0x49, 0x0A, 0x78, 0x08, 0x49, 0x00, 0x2A, 0x06, 0xBF, 0x01, 0x22, 0x09, 0x1F, 0x44, 0xF2, 0xA4, 0x5C, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0xE9, 0x22, 0x0A, 0x60, 0xF7, 0xF7, 0xA1, 0xFD, 0x00, 0xBD, 0xC0, 0x46, 0xDC, 0x7C, 0x00, 0x20, 0xDD, 0x6A, 0x00, 0x20, 0xA7, 0x64, 0x00, 0x20, 0x04, 0x97, 0x3C, 0x80, 0x50, 0xB9, 0x09, 0x48, 0x00, 0x78, 0x01, 0x28, 0x06, 0xD1, 0x08, 0x48, 0x00, 0x78, 0x0E, 0x28, 0x08, 0xBF, 0x44, 0xF2, 0xCB, 0x20, 0x01, 0xD0, 0x44, 0xF2, 0xDE, 0x20, 0x04, 0x49, 0x08, 0x60, 0x01, 0x20 , +0x41, 0xF8, 0x04, 0x0C, 0x70, 0x47, 0xE0, 0x7C, 0x00, 0x20, 0xA6, 0x64, 0x00, 0x20, 0x04, 0x97, 0x3C, 0x80, 0x30, 0xB5, 0x0D, 0x46, 0x84, 0x69, 0xDC, 0xF7, 0x97, 0xFB, 0x24, 0x1D, 0x01, 0x28, 0x04, 0xEB, 0x45, 0x01, 0x06, 0xD1, 0x89, 0x8E, 0x04, 0xEB, 0x85, 0x04, 0x11, 0xB9, 0x21, 0x69, 0x01, 0xB9, 0x00, 0x20, 0x30, 0xBD, 0x30, 0xB5, 0x05, 0x46, 0x5A, 0xB1, 0x03, 0xEB, 0x41, 0x03, 0x1C, 0x78, 0x59, 0x78, 0x41, 0xEA, 0x04, 0x11, 0x52, 0x1E, 0x03, 0xF1, 0x02, 0x03, 0x05, 0xF8, 0x01, 0x1B, 0xF5, 0xD1, 0x30, 0xBD, 0x00, 0xB5, 0x00, 0x20, 0xE7, 0xF7, 0xD6, 0xFE, 0x03, 0x48, 0x01, 0x68, 0x03, 0x29, 0x04, 0xBF, 0x04, 0x21, 0x01, 0x60, 0x00, 0xBD, 0xC0, 0x46, 0x4C, 0x57, 0x02, 0x00, 0x03, 0x4A, 0x12, 0x68, 0x01, 0x2A, 0x04, 0xBF, 0x02, 0x48, 0x63, 0x21, 0xF1, 0xF7, 0x76, 0xB9, 0x50, 0x57, 0x02, 0x00, 0x02, 0x20, 0x01, 0x00, 0x6C, 0x5D, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + +uint16_t fw_length = 5700; + + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_13/driverpatch_1_13.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_13/driverpatch_1_13.ino new file mode 100755 index 0000000000..9266a3fd86 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_13/driverpatch_1_13.ino @@ -0,0 +1,372 @@ +// Adafruit CC3000 Firmware V1.13 Upgrade Sketch +// Based on firmware patcher for MSP430 chips published by Texas Instruments. +// +// This sketch will upgrade CC3000 modules up to firmware version 1.13. +// +// You can find more details about the changes in the 1.13 firmware from TI at: +// http://processors.wiki.ti.com/index.php/CC3000_Release_Notes +// +// In general the 1.13 release is a bug fix release with fixes for stability +// issues that caused the CC3000 to hang when under load. +// +// WARNING: Upgrade firmware at your own risk! In general if the CC3000 is +// currently working fine for your needs then hold off on the upgrade. +// +// Usage (read all the steps before strarting): +// - Wire up your Arduino to the CC3000 just like you're running buildtest or +// other examples. +// - Adjust the ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_VBAT +// defines below to match your wiring (just like running buildtest). +// - Load the sketch on your Arduino and open the serial monitor at 115200 baud. +// - You should see a prompt waiting for a key press to continue. Enter text +// and press enter to start the upgrade. +// - You will see text printed as the firmware is upgraded. The upgrade process +// should be quick and take less than a minute. +// - You might see a message at the end that the firmware version or MAC address +// couldn't be read--this can be ignored. +// - Once the firmware upgrade is complete, run the buildtest sketch to check +// the CC3000 functionality. +// - During the firmware upgrade the CC3000 MAC address might be lost. You can +// write a new MAC address by uncommenting the appropriate line in the buildtest +// example. Make sure to save your MAC address before upgrading the firmware +// if you'd like to keep it the same after + +#include +#include +#include +#include +#include + +#include "utility/debug.h" +#include "utility/nvmem.h" +#include "driverpatchinc_1_13.h" + +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +#define ADAFRUIT_CC3000_CS 10 +#define ADAFRUIT_CC3000_VBAT 5 + +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT); + +/**************************************************************************/ +/*! + @brief Displays the driver mode (tiny of normal), and the buffer + size if tiny mode is not being used + + @note The buffer size and driver mode are defined in cc3000_common.h +*/ +/**************************************************************************/ +void displayDriverMode(void) +{ + #ifdef CC3000_TINY_DRIVER + Serial.println(F("CC3000 is configure in 'Tiny' mode")); + #else + Serial.print(F("RX Buffer : ")); + Serial.print(CC3000_RX_BUFFER_SIZE); + Serial.println(F(" bytes")); + Serial.print(F("TX Buffer : ")); + Serial.print(CC3000_TX_BUFFER_SIZE); + Serial.println(F(" bytes")); + #endif +} + +/**************************************************************************/ +/*! + @brief Tries to read the CC3000's internal firmware patch ID +*/ +/**************************************************************************/ +void displayFirmwareVersion(void) +{ + #ifndef CC3000_TINY_DRIVER + uint8_t major, minor; + + if(!cc3000.getFirmwareVersion(&major, &minor)) + { + Serial.println(F("Unable to retrieve the firmware version!\r\n")); + } + else + { + Serial.print(F("Firmware V. : ")); + Serial.print(major); Serial.print(F(".")); Serial.println(minor); + } + #endif +} + +/**************************************************************************/ +/*! + @brief Tries to read the 6-byte MAC address of the CC3000 module +*/ +/**************************************************************************/ +boolean MACvalid = false; +// array to store MAC address from EEPROM +uint8_t cMacFromEeprom[MAC_ADDR_LEN]; +void displayMACAddress(void) +{ + if(!cc3000.getMacAddress(cMacFromEeprom)) + { + Serial.println(F("Unable to retrieve MAC Address!\r\n")); + MACvalid = false; + } + else + { + Serial.print(F("MAC Address : ")); + cc3000.printHex((byte*)&cMacFromEeprom, 6); + MACvalid = true; + } +} + + + +/**************************************************************************/ +/*! + @brief Sets up the HW and the CC3000 module (called automatically + on startup) +*/ +/**************************************************************************/ + +uint8_t ucStatus_Dr, return_status = 0xFF; +uint8_t counter = 0; + +// array to store RM parameters from EEPROM +unsigned char cRMParamsFromEeprom[128]; + + +// 2 dim array to store address and length of new FAT +uint16_t aFATEntries[2][NVMEM_RM_FILEID + 1] = +/* address */ {{0x50, 0x1f0, 0x1390, 0x0390, 0x2390, 0x4390, 0x6390, 0x63a0, 0x63b0, 0x63f0, 0x6430, 0x6830}, +/* length */ {0x1a0, 0x1a0, 0x1000, 0x1000, 0x2000, 0x2000, 0x10, 0x10, 0x40, 0x40, 0x400, 0x200 }}; +/* 0. NVS */ +/* 1. NVS Shadow */ +/* 2. Wireless Conf */ +/* 3. Wireless Conf Shadow */ +/* 4. BT (WLAN driver) Patches */ +/* 5. WiLink (Firmware) Patches */ +/* 6. MAC addr */ +/* 7. Frontend Vars */ +/* 8. IP config */ +/* 9. IP config Shadow */ +/* 10. Bootloader Patches */ +/* 11. Radio Module params */ +/* 12. AES128 for smart config */ +/* 13. user file */ +/* 14. user file */ +/* 15. user file */ + + +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + Serial.println(F("Hit any key & return to start")); + while (!Serial.available()); + + pinMode(9, OUTPUT); + pinMode(8, OUTPUT); + pinMode(7, OUTPUT); + pinMode(6, OUTPUT); + digitalWrite(9, LOW); + digitalWrite(8, LOW); + digitalWrite(7, LOW); + digitalWrite(6, LOW); + + displayDriverMode(); + displayFreeRam(); + + /* Initialise the module */ + Serial.println(F("\nInitialising the CC3000 ...")); + if (!cc3000.begin(2)) // init with NO patches! + { + Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + while(1); + } + + displayFirmwareVersion(); + displayMACAddress(); + + return_status = 1; + uint8_t index; + uint8_t *pRMParams; + + while ((return_status) && (counter < 3)) { + // read RM parameters + // read in 16 parts to work with tiny driver + + return_status = 0; + pRMParams = cRMParamsFromEeprom; + + for (index = 0; index < 16; index++) { + return_status |= nvmem_read(NVMEM_RM_FILEID, 8, 8*index, pRMParams); + Serial.print(F("\n\rRead NVRAM $")); Serial.print(8*index); Serial.print("\t"); + for(uint8_t x=0; x<8; x++) { + Serial.print("0x"); Serial.print(pRMParams[x], HEX); Serial.print(", "); + } + pRMParams += 8; + } + counter++; + } + // if RM file is not valid, load the default one + if (counter == 3) { + Serial.println(F("\n\rLoad default params")); + pRMParams = (uint8_t *)cRMdefaultParams; + } else { + Serial.println(F("\n\rLoad EEPROM params")); + pRMParams = cRMParamsFromEeprom; + if (EEPROM.read(0) == 0xFF) { + for (uint8_t e=0; e<128; e++) { + EEPROM.write(e, cRMParamsFromEeprom[e]); + } + Serial.println(F("Backed up to eeprom!")); + } + } + + + return_status = 1; + + while (return_status) { + // write new FAT + return_status = fat_write_content(aFATEntries[0], aFATEntries[1]); + Serial.print(F("Wrote FAT entries: ")); Serial.println(return_status, DEC); + } + + //Serial.println(F("Stopping...")); + //cc3000.stop(); + + //Serial.println(F("\nInitialising the CC3000 ...")); + + //if (!cc3000.begin(2)) // no patches! + //{ + // Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + // while(1); + //} + + return_status = 1; + + Serial.println(F("Write params")); + + while (return_status) { + // write RM parameters + // write in 4 parts to work with tiny driver + + return_status = 0; + + for (index = 0; index < 4; index++) { + return_status |= nvmem_write(NVMEM_RM_FILEID, 32, 32*index, (pRMParams + 32*index)); + Serial.println(F("Wrote 32 bytes to NVRAM")); + } + } + Serial.println(F("Wrote params")); + + return_status = 1; + + // write back the MAC address, only if exist + if (MACvalid) { + // zero out MCAST bit if set + cMacFromEeprom[0] &= 0xfe; + while (return_status) { + return_status = nvmem_set_mac_address(cMacFromEeprom); + } + } + + ucStatus_Dr = 1; + Serial.println(F("Writing driver patch")); + + while (ucStatus_Dr) { + //writing driver patch to EEPRROM - PROTABLE CODE + // Note that the array itself is changing between the different Service Packs + ucStatus_Dr = nvmem_write_patch(NVMEM_WLAN_DRIVER_SP_FILEID, drv_length, wlan_drv_patch); + } + + + Serial.println(F("Wrote driver patch")); + + Serial.println(F("Starting w/o patches")); + + //if (!cc3000.begin(2)) + //{ + // Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + // while(1); + //} + + Serial.println(F("Writing firmware")); + + unsigned char ucStatus_FW = 1; + + while (ucStatus_FW) { + //writing FW patch to EAPRROM - PROTABLE CODE + //Note that the array itself is changing between the different Service Packs + ucStatus_FW = nvmem_write_patch(NVMEM_WLAN_FW_SP_FILEID, fw_length, fw_patch); + } + + Serial.println(F("Starting w/patches")); + + cc3000.reboot(); + /* + if (!) + { + Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + while(1); + } + */ + Serial.println(F("Patched!")); + displayFirmwareVersion(); + displayMACAddress(); +} + + +//***************************************************************************** +// +//! fat_write_content +//! +//! \param[in] file_address array of file address in FAT table:\n +//! this is the absolute address of the file in the EEPROM. +//! \param[in] file_length array of file length in FAT table:\n +//! this is the upper limit of the file size in the EEPROM. +//! +//! \return on succes 0, error otherwise +//! +//! \brief parse the FAT table from eeprom +// +//***************************************************************************** +uint8_t fat_write_content(uint16_t *file_address, uint16_t *file_length) +{ + uint16_t index = 0; + uint8_t ucStatus; + uint8_t fatTable[48]; + uint8_t* fatTablePtr = fatTable; + uint8_t LS[3] = "LS"; + + // first, write the magic number + ucStatus = nvmem_write(16, 2, 0, LS); + + for (; index <= NVMEM_RM_FILEID; index++) + { + // write address low char and mark as allocated + *fatTablePtr++ = (uint8_t)(file_address[index] & 0xff) | _BV(0); + + // write address high char + *fatTablePtr++ = (uint8_t)((file_address[index]>>8) & 0xff); + + // write length low char + *fatTablePtr++ = (uint8_t)(file_length[index] & 0xff); + + // write length high char + *fatTablePtr++ = (uint8_t)((file_length[index]>>8) & 0xff); + } + + // second, write the FAT + // write in two parts to work with tiny driver + ucStatus = nvmem_write(16, 24, 4, fatTable); + ucStatus = nvmem_write(16, 24, 24+4, &fatTable[24]); + + // third, we want to erase any user files + memset(fatTable, 0, sizeof(fatTable)); + ucStatus = nvmem_write(16, 16, 52, fatTable); + + return ucStatus; +} + + +void loop(void) +{ + delay(1000); +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_13/driverpatchinc_1_13.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_13/driverpatchinc_1_13.h new file mode 100755 index 0000000000..aaa3f80353 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/driverpatch_1_13/driverpatchinc_1_13.h @@ -0,0 +1,102 @@ +//Service Pack version P1.12.7.15.26 - Driver patches + +uint8_t cRMdefaultParams[128] = { 0x03, 0x00, 0x01, 0x01, 0x14, 0x14, 0x00, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x23, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x23, 0x23, 0x23, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x01, 0x77, 0x80, 0x1D, 0x1F, 0x22, 0x26, 0x28, 0x29, 0x1A, 0x1F, 0x22, 0x24, 0x26, 0x28, 0x16, 0x1D, 0x1E, 0x20, 0x24, 0x25, 0x1E, 0x2D, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x15, 0x15, 0x15, 0x11, 0x15, 0x15, 0x0E, 0x00}; + +unsigned char PROGMEM wlan_drv_patch[8024] = { 0x00, 0x01, 0x00, 0x00, 0x50, 0x1F, 0x00, 0x00, 0xF0, 0x03, 0x18, 0x00, 0xE4, 0x62, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7A, 0x63, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x10, 0x64, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x20, 0x0C, 0x49, 0x08, 0x60, 0x0C, 0x48, 0x19, 0x30, 0xF7, 0x46, 0x30, 0xB5, 0x05, 0x1C, 0xAC, 0x69, 0x68, 0x68, 0x5F, 0x30, 0x09, 0xD1, 0x60, 0x6B, 0x0C, 0x38, 0x01, 0x21, 0x8E, 0x46, 0x06, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x00, 0x20, 0x60, 0x63, 0xAC, 0x69, 0x6C, 0x60, 0x04, 0x48, 0x5B, 0x30, 0x30, 0xBD, 0x40, 0x3B, 0x08, 0x00, 0x49, 0xD0, 0x01, 0x00, 0x09, 0xEA, 0x02, 0x00, 0x91, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xA6, 0x64, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x3C, 0x65, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xB5, 0x85, 0xB0, 0x05, 0x1C, 0xA8, 0x88, 0x00, 0x90, 0x28, 0x89, 0x01, 0x90, 0xE9, 0x68, 0x02, 0x91, 0x28, 0x7C, 0x03, 0x90, 0x2A, 0x6A, 0x00, 0x20, 0x17, 0x56, 0x68, 0x60, 0x00, 0x29, 0x4C, 0xD0, 0x00, 0x2F, 0x4A, 0xDC , +0xCA, 0x49, 0x0C, 0x1C, 0x08, 0x26, 0x04, 0x90, 0x21, 0x88, 0x00, 0x98, 0x81, 0x42, 0x0C, 0xD1, 0x62, 0x88, 0x01, 0x98, 0x82, 0x42, 0x08, 0xD1, 0x46, 0x20, 0x02, 0x5D, 0x03, 0x98, 0x82, 0x42, 0x03, 0xD1, 0x0E, 0x20, 0x00, 0x57, 0xB8, 0x42, 0x0A, 0xD0, 0x46, 0x20, 0x00, 0x5D, 0x11, 0x28, 0x22, 0xD1, 0x00, 0x98, 0x81, 0x42, 0x1F, 0xD1, 0x0E, 0x20, 0x00, 0x57, 0xFF, 0xFF, 0xD2, 0x65, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xB8, 0x42, 0x1B, 0xD1, 0x04, 0x20, 0x02, 0x1C, 0x02, 0x98, 0xB9, 0x49, 0x01, 0x23, 0x9E, 0x46, 0xEC, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x17, 0xD0, 0x20, 0x1D, 0x02, 0x99, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0xE7, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x0D, 0xD0, 0x46, 0x20, 0x00, 0x5D, 0x11, 0x28, 0x09, 0xD0, 0xA0, 0x6D, 0x00, 0x28, 0x06, 0xD0, 0xAC, 0x34, 0x04, 0x98, 0x01, 0x30, 0x04, 0x90, 0x01, 0x3E, 0xC1, 0xD1, 0x07, 0xE0, 0x04, 0x98, 0x00, 0x06, 0x00, 0x0E , +0xAC, 0x21, 0x41, 0x43, 0xA6, 0x48, 0x40, 0x18, 0x68, 0x60, 0xA6, 0x48, 0xAD, 0x30, 0x05, 0xB0, 0xF0, 0xBD, 0x00, 0xB5, 0xC2, 0x68, 0x90, 0x69, 0x02, 0x21, 0x01, 0x23, 0x9E, 0x46, 0xA2, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xA2, 0x48, 0x61, 0x30, 0x00, 0xBD, 0x01, 0x79, 0x0B, 0x29, 0x03, 0xD0, 0x89, 0x00, 0x9F, 0x4A, 0x51, 0x5A, 0x01, 0xE0, 0x01, 0x21, 0x49, 0x02, 0x41, 0x60, 0x9D, 0x48, 0x0D, 0x30, 0xF7, 0x46, 0x01, 0x1C, 0xFF, 0xFF, 0x68, 0x66, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x9C, 0x48, 0x02, 0x68, 0x9C, 0x48, 0x01, 0x2A, 0x01, 0xD1, 0x25, 0x30, 0xF7, 0x46, 0x9B, 0x4A, 0x12, 0x68, 0x4A, 0x60, 0x19, 0x30, 0xF7, 0x46, 0x00, 0x21, 0x41, 0x60, 0x99, 0x48, 0x98, 0x49, 0x08, 0x18, 0xF7, 0x46, 0x00, 0x21, 0x41, 0x60, 0x97, 0x48, 0xE7, 0x49, 0x08, 0x18, 0xF7, 0x46, 0xFF, 0xB5, 0x46, 0x69, 0x40, 0x68, 0x01, 0x90, 0x94, 0x49, 0x0A, 0x7C, 0x9A, 0x4F, 0x01, 0x2A, 0x63, 0xD0, 0x09, 0x7C, 0x03, 0x29 , +0x60, 0xD0, 0x91, 0x4A, 0x92, 0x4B, 0x00, 0x21, 0x02, 0x91, 0x59, 0x56, 0x24, 0x23, 0x59, 0x43, 0x53, 0x18, 0x03, 0x93, 0x01, 0x28, 0x17, 0xD1, 0x8A, 0x18, 0x04, 0x23, 0x6C, 0x46, 0x8C, 0x49, 0x15, 0x79, 0x08, 0x78, 0xC0, 0x43, 0x28, 0x43, 0x20, 0x70, 0x01, 0x32, 0x01, 0x31, 0x01, 0x34, 0x01, 0x3B, 0xF5, 0xD1, 0x31, 0x1D, 0x68, 0x46, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0xA9, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x40, 0xD0, 0x35, 0x1D, 0x82, 0x48, 0x00, 0x78, 0xFF, 0x28, 0xFF, 0xFF, 0xFE, 0x66, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x11, 0xD0, 0x00, 0x28, 0x0F, 0xD0, 0x03, 0x98, 0x01, 0x1D, 0x28, 0x1C, 0x01, 0x24, 0xA6, 0x46, 0x7E, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x00, 0x28, 0x05, 0xD1, 0x7A, 0x48, 0xA6, 0x46, 0x7B, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x05, 0xE0, 0x28, 0x1C, 0x01, 0x21, 0x8E, 0x46, 0x78, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x01, 0x99, 0x01, 0x29, 0x01, 0xD1, 0x00, 0x28, 0x1E, 0xD1 , +0x01, 0x99, 0x5F, 0x31, 0x01, 0xD0, 0x00, 0x28, 0x0F, 0xD1, 0xA8, 0x20, 0x81, 0x5D, 0x00, 0x29, 0x08, 0xD0, 0x49, 0x1E, 0x81, 0x55, 0x80, 0x5D, 0x00, 0x28, 0x09, 0xD1, 0x38, 0x1C, 0xFF, 0x30, 0x08, 0x30, 0x11, 0xE0, 0x03, 0x21, 0x02, 0x91, 0x00, 0xE0, 0xA8, 0x20, 0x02, 0x99, 0x81, 0x55, 0x38, 0x1C, 0xFF, 0x30, 0x16, 0x30, 0x07, 0xE0, 0x01, 0x98, 0x01, 0x28, 0x02, 0xD1, 0x38, 0x1C, 0xA3, 0x30, 0x01, 0xE0, 0x38, 0x1C, 0x9F, 0x30, 0x00, 0x90, 0xFF, 0xBD, 0x00, 0xB5, 0x02, 0x1C, 0x10, 0x6A, 0xD1, 0x69, 0x52, 0x69, 0xC3, 0x69, 0x5A, 0x60, 0xFF, 0xFF, 0x94, 0x67, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x01, 0x22, 0x96, 0x46, 0x5E, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x5E, 0x48, 0xFF, 0x30, 0x6E, 0x30, 0x00, 0xBD, 0x10, 0xB5, 0x0A, 0x1C, 0x41, 0x69, 0x00, 0x6A, 0x93, 0x69, 0xDB, 0x69, 0x58, 0x60, 0x90, 0x69, 0x01, 0x24, 0xA6, 0x46, 0x56, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0xA6, 0x46, 0x56, 0x48, 0xFE, 0x44 , +0x00, 0x47, 0x55, 0x48, 0xFF, 0x30, 0xB6, 0x30, 0x10, 0xBD, 0x70, 0xB5, 0x05, 0x1C, 0x6E, 0x69, 0x53, 0x48, 0x02, 0x68, 0x5C, 0x21, 0x88, 0x5D, 0x04, 0x28, 0x15, 0xD1, 0x07, 0x20, 0x88, 0x55, 0x10, 0x0B, 0x11, 0xD2, 0x01, 0x24, 0xA6, 0x46, 0x4E, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x00, 0x28, 0x0A, 0xD0, 0x47, 0x21, 0x89, 0x57, 0xC1, 0x60, 0x11, 0x21, 0xC9, 0x02, 0x00, 0x22, 0x04, 0x23, 0xA6, 0x46, 0xE8, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x01, 0x20, 0x68, 0x60, 0x43, 0x48, 0xED, 0x49, 0x08, 0x18, 0x70, 0xBD, 0x70, 0xB5, 0x05, 0x1C, 0xAE, 0x69, 0x9C, 0x20, 0x80, 0x19, 0x4B, 0x21, 0x89, 0x00, 0x01, 0x24, 0xFF, 0xFF, 0x2A, 0x68, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xA6, 0x46, 0xE8, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x5C, 0x21, 0x88, 0x5D, 0x07, 0x28, 0x01, 0xD1, 0x09, 0x20, 0x00, 0xE0, 0x05, 0x20, 0xAA, 0x69, 0x88, 0x54, 0x30, 0x1C, 0xA6, 0x46, 0xE9, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x68, 0x60, 0xE8, 0x48 , +0x4D, 0x30, 0x70, 0xBD, 0xF0, 0xB5, 0x41, 0x68, 0x82, 0x68, 0x88, 0x23, 0x5E, 0x18, 0x37, 0x88, 0x0B, 0x6F, 0x00, 0x2B, 0x01, 0xD1, 0x00, 0x2F, 0x10, 0xD1, 0x06, 0x2F, 0x02, 0xDD, 0x00, 0x21, 0xC9, 0x43, 0x07, 0xE0, 0x33, 0x88, 0x9B, 0x00, 0xC9, 0x18, 0x0A, 0x67, 0x31, 0x88, 0x01, 0x31, 0x31, 0x80, 0x01, 0x21, 0x81, 0x60, 0xE1, 0x48, 0x1D, 0x30, 0xF0, 0xBD, 0x0B, 0x1C, 0x01, 0x24, 0x5D, 0x6F, 0x1D, 0x67, 0x04, 0x33, 0x01, 0x34, 0x06, 0x2C, 0xE1, 0xDA, 0xF8, 0xE7, 0x00, 0xB5, 0x00, 0x21, 0xC1, 0x60, 0xE9, 0x48, 0x01, 0x68, 0x10, 0x31, 0xE6, 0x48, 0x20, 0x22, 0x01, 0x23, 0x9E, 0x46, 0xE7, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xE5, 0x48, 0xFB, 0x30, 0x00, 0xBD, 0xFF, 0xFF, 0xC0, 0x68, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x14, 0x0D, 0x1B, 0x00, 0x54, 0x19, 0x1B, 0x00, 0x91, 0x1A, 0x01, 0x00, 0x4B, 0xAD, 0x03, 0x00, 0x61, 0x4E, 0x01, 0x00, 0x06, 0x32, 0x08, 0x00, 0x1F, 0x0B, 0x02, 0x00, 0x54, 0x3F , +0x08, 0x00, 0x45, 0xC1, 0x00, 0x00, 0x84, 0x3C, 0x08, 0x00, 0x1B, 0x02, 0x00, 0x00, 0xED, 0x17, 0x00, 0x00, 0xF3, 0xC1, 0x01, 0x00, 0x34, 0x19, 0x1B, 0x00, 0x08, 0x19, 0x1B, 0x00, 0xA6, 0x44, 0x08, 0x00, 0x1C, 0x17, 0x1B, 0x00, 0x18, 0x17, 0x1B, 0x00, 0xCB, 0x67, 0x03, 0x00, 0x0D, 0x47, 0x02, 0x00, 0x39, 0x42, 0x03, 0x00, 0xBD, 0xE7, 0x02, 0x00, 0xB1, 0x40, 0x03, 0x00, 0xB9, 0xEA, 0x01, 0x00, 0x45, 0xDA, 0x00, 0x00, 0x24, 0x41, 0x08, 0x00, 0x71, 0xC0, 0x02, 0x00, 0xF0, 0xB5, 0x88, 0xB0, 0x06, 0x91, 0x07, 0x90, 0x86, 0x69, 0xF0, 0x1C, 0xD9, 0xA1, 0x04, 0x22, 0x01, 0x24, 0xA6, 0x46, 0x14, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x32, 0xD1, 0xF2, 0x79, 0xD7, 0x48, 0x02, 0x70, 0x35, 0x7A, 0x77, 0x7A, 0x78, 0x1B, 0xFF, 0xFF, 0x56, 0x69, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x43, 0x1C, 0x93, 0x42, 0x1D, 0xD0, 0x16, 0x2A, 0x0C, 0xDB, 0x00, 0x2D, 0x0A, 0xD1, 0xD6, 0x48, 0x04, 0x70, 0x0A, 0x20 , +0x81, 0x19, 0xD0, 0x48, 0x1A, 0x1C, 0xA6, 0x46, 0xB8, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x74, 0xE0, 0xD2, 0x48, 0x04, 0x70, 0xCC, 0x48, 0x40, 0x19, 0x0A, 0x21, 0x89, 0x19, 0x7A, 0x1B, 0x52, 0x1C, 0xA6, 0x46, 0xB1, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x67, 0xE0, 0x8F, 0xC6, 0x03, 0x00, 0xC9, 0x48, 0x04, 0x70, 0xC9, 0x48, 0x04, 0x70, 0x0A, 0x20, 0x81, 0x19, 0xC2, 0x48, 0xA6, 0x46, 0xAA, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x59, 0xE0, 0xF0, 0x1C, 0x03, 0x21, 0x0A, 0x1C, 0xBC, 0xA1, 0xA6, 0x46, 0xC6, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x4F, 0xD1, 0xF1, 0x79, 0xBB, 0x48, 0x01, 0x70, 0xBB, 0x4D, 0xB2, 0x79, 0x2A, 0x70, 0x03, 0x20, 0x17, 0x49, 0xF4, 0x31, 0xA6, 0x46, 0xB8, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x28, 0x78, 0x00, 0x28, 0x0B, 0xD1, 0xFF, 0xE7, 0xB8, 0x49, 0x0C, 0x70, 0xB8, 0x49, 0xFF, 0xFF, 0xEC, 0x69, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x0C, 0x70, 0x03, 0x20, 0x0F, 0x49, 0xF5, 0x31, 0xA6, 0x46 , +0xB6, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x20, 0x1C, 0xF2, 0x79, 0x35, 0x7A, 0x77, 0x7A, 0x79, 0x1B, 0x4B, 0x1C, 0x93, 0x42, 0x20, 0xD0, 0xA9, 0x49, 0x09, 0x78, 0x16, 0x29, 0x0F, 0xDB, 0x00, 0x2D, 0x0D, 0xD1, 0xAB, 0x49, 0x08, 0x70, 0x0A, 0x20, 0x81, 0x19, 0xE9, 0x48, 0x1A, 0x1C, 0xA6, 0x46, 0x8B, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x1A, 0xE0, 0xC0, 0x46, 0xC7, 0x04, 0x00, 0x00, 0xA5, 0x49, 0x08, 0x70, 0xE3, 0x48, 0x40, 0x19, 0x0A, 0x21, 0x89, 0x19, 0x7A, 0x1B, 0x52, 0x1C, 0xA6, 0x46, 0x83, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x0A, 0xE0, 0x9E, 0x49, 0x08, 0x70, 0x9E, 0x49, 0x08, 0x70, 0x0A, 0x20, 0x81, 0x19, 0xDB, 0x48, 0xA6, 0x46, 0x7D, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x96, 0x48, 0x00, 0x78, 0x00, 0x28, 0x0A, 0xD0, 0x95, 0x48, 0x00, 0x78, 0x00, 0x28, 0x06, 0xD0, 0x94, 0x48, 0x00, 0x78, 0x00, 0x28, 0x02, 0xD0, 0x93, 0x48, 0x00, 0x78, 0x00, 0x28, 0xFF, 0xFF, 0x82, 0x6A, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00 , +0x00, 0xD1, 0x8C, 0xE0, 0x03, 0x20, 0x17, 0x21, 0x89, 0x01, 0xA6, 0x46, 0x90, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x87, 0x48, 0x01, 0x78, 0x87, 0x48, 0x07, 0x78, 0x84, 0x4E, 0x83, 0x4D, 0xE0, 0x48, 0x00, 0x68, 0x00, 0x28, 0x2E, 0xD1, 0x07, 0x98, 0x41, 0x61, 0x06, 0x62, 0xC6, 0x48, 0x06, 0x9A, 0x10, 0x64, 0x02, 0x2F, 0x01, 0xD0, 0x03, 0x2F, 0x01, 0xD1, 0x03, 0x22, 0x00, 0xE0, 0x3A, 0x1C, 0x06, 0x9B, 0xDA, 0x63, 0x2A, 0x78, 0x9A, 0x63, 0x01, 0x2F, 0x03, 0xD1, 0x05, 0x29, 0x04, 0xD0, 0x0D, 0x29, 0x02, 0xD0, 0xEC, 0x48, 0xDB, 0x30, 0x64, 0xE0, 0x00, 0x25, 0x00, 0x95, 0x01, 0x91, 0x02, 0x96, 0x03, 0x95, 0x04, 0x90, 0x2B, 0x1C, 0x20, 0x1C, 0x01, 0x1C, 0x8E, 0x46, 0xE6, 0x4E, 0xFE, 0x44, 0x30, 0x47, 0xE6, 0x48, 0x04, 0x60, 0x28, 0x1C, 0xA6, 0x46, 0xE5, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x4C, 0xE0, 0x0D, 0x27, 0x00, 0x20, 0x39, 0x1C, 0x05, 0xAA, 0xA6, 0x46, 0xE3, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x68, 0x46 , +0xFF, 0xFF, 0x18, 0x6B, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x80, 0x8A, 0x40, 0x08, 0x05, 0xD2, 0x38, 0x1C, 0x50, 0x21, 0xA6, 0x46, 0xDC, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x38, 0x1C, 0x21, 0x1C, 0x0B, 0x1C, 0x29, 0x1C, 0x00, 0x22, 0xA6, 0x46, 0xD9, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0x2B, 0x78, 0x0D, 0x20, 0x31, 0x1C, 0x22, 0x1C, 0xA6, 0x46, 0xD5, 0x4E, 0xFE, 0x44, 0x30, 0x47, 0x28, 0x78, 0x01, 0x30, 0x02, 0x1C, 0x0D, 0x20, 0x57, 0x49, 0x23, 0x1C, 0xA6, 0x46, 0xD0, 0x4E, 0xFE, 0x44, 0x30, 0x47, 0x55, 0x4E, 0x28, 0x78, 0x02, 0x30, 0x02, 0x1C, 0x0D, 0x20, 0x31, 0x1C, 0x23, 0x1C, 0xA6, 0x46, 0xCA, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0x30, 0x78, 0x00, 0x28, 0x0A, 0xD0, 0x28, 0x78, 0x03, 0x30, 0x02, 0x1C, 0x4C, 0x48, 0x03, 0x78, 0x0D, 0x20, 0x8F, 0x49, 0xA6, 0x46, 0xC3, 0x4D, 0xFE, 0x44, 0x28, 0x47, 0xBF, 0x48, 0x04, 0x60, 0x00, 0x20, 0xA6, 0x46, 0xBE, 0x49, 0xFE, 0x44, 0x08, 0x47, 0xB9, 0x48, 0xEC, 0x49 , +0x08, 0x18, 0x08, 0xB0, 0xF0, 0xBD, 0xC0, 0x46, 0x7B, 0xC0, 0xFF, 0xFF, 0xAE, 0x6B, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x1C, 0xE9, 0x48, 0x02, 0x68, 0xE9, 0x48, 0x00, 0x2A, 0x04, 0xD0, 0x00, 0x22, 0x0A, 0x62, 0x8A, 0x61, 0x1D, 0x30, 0xF7, 0x46, 0xD7, 0x30, 0xF7, 0x46, 0xC0, 0x46, 0x9F, 0x03, 0x00, 0x00, 0x7D, 0xB8, 0x03, 0x00, 0x01, 0x1C, 0xE2, 0x48, 0x02, 0x68, 0xE2, 0x48, 0x00, 0x2A, 0x02, 0xD0, 0xFF, 0x30, 0xB4, 0x30, 0xF7, 0x46, 0x00, 0x22, 0xCA, 0x61, 0x8A, 0x61, 0x4F, 0x30, 0xF7, 0x46, 0xC9, 0x21, 0x01, 0x00, 0x91, 0xE1, 0x00, 0x00, 0xDB, 0x48, 0x01, 0x68, 0x8A, 0x69, 0x01, 0x20, 0xC0, 0x03, 0x10, 0x43, 0x88, 0x61, 0x00, 0x20, 0x08, 0x61, 0xD8, 0x48, 0x23, 0x30, 0xF7, 0x46, 0x89, 0x17, 0x02, 0x00, 0x70, 0xB5, 0x05, 0x1C, 0xD5, 0x4E, 0x29, 0x6A, 0xEA, 0x69, 0x30, 0x1C, 0x01, 0x24, 0xA6, 0x46, 0x0B, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x68, 0x69, 0xA6, 0x46, 0xD1, 0x49 , +0xFE, 0x44, 0x08, 0x47, 0xA8, 0x69, 0x06, 0x30, 0xA8, 0x60, 0xCF, 0x48, 0x00, 0x68, 0x68, 0x60, 0xEE, 0x60, 0xCE, 0x48, 0xFF, 0xFF, 0x44, 0x6C, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x6D, 0x30, 0x70, 0xBD, 0x46, 0x17, 0x1B, 0x00, 0x30, 0x3F, 0x08, 0x00, 0x41, 0xEB, 0x00, 0x00, 0x09, 0xB4, 0x03, 0x00, 0x30, 0xB5, 0xEE, 0x48, 0x01, 0x6D, 0x80, 0x6C, 0x08, 0x43, 0x18, 0xD0, 0xEC, 0x49, 0x08, 0x1C, 0x07, 0x22, 0xFF, 0x23, 0x09, 0x33, 0x1B, 0x58, 0x00, 0x2B, 0x04, 0xD0, 0xFF, 0x30, 0x1D, 0x30, 0x01, 0x3A, 0xF6, 0xD1, 0x0B, 0xE0, 0x02, 0x20, 0xF0, 0x4A, 0xF1, 0x4B, 0x01, 0x24, 0xA6, 0x46, 0xF0, 0x4D, 0xFE, 0x44, 0x28, 0x47, 0xA6, 0x46, 0xEF, 0x48, 0xFE, 0x44, 0x00, 0x47, 0xEF, 0x48, 0xFF, 0x30, 0x5C, 0x30, 0x30, 0xBD, 0xC0, 0x46, 0x53, 0x53, 0x49, 0x44, 0x00, 0xC0, 0x46, 0xC0, 0x4B, 0x45, 0x59, 0x00, 0xEE, 0x62, 0x08, 0x00, 0xF0, 0x62, 0x08, 0x00, 0xEC, 0x62, 0x08, 0x00, 0xED, 0x62, 0x08, 0x00 , +0xE7, 0x7E, 0x03, 0x00, 0xE8, 0x62, 0x08, 0x00, 0xE9, 0x62, 0x08, 0x00, 0xEA, 0x62, 0x08, 0x00, 0xEB, 0x62, 0x08, 0x00, 0xDD, 0x7E, 0x03, 0x00, 0x8F, 0xC6, 0x03, 0x00, 0xF0, 0xB5, 0xFF, 0xFF, 0xDA, 0x6C, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x87, 0xB0, 0x00, 0x91, 0x01, 0x90, 0x6B, 0x48, 0x01, 0x68, 0xCC, 0x4A, 0x14, 0x1C, 0x02, 0x94, 0x07, 0x26, 0x00, 0x25, 0x03, 0x95, 0x04, 0x94, 0x05, 0x95, 0xDF, 0x48, 0x00, 0x68, 0x08, 0x43, 0x27, 0xD0, 0xE0, 0x68, 0x03, 0x99, 0x88, 0x42, 0x0A, 0xDD, 0x03, 0x90, 0x40, 0x1C, 0x00, 0x99, 0x88, 0x60, 0xC2, 0x49, 0xFF, 0x20, 0x1D, 0x30, 0x68, 0x43, 0x0C, 0x18, 0xE0, 0x68, 0x04, 0x91, 0x02, 0x99, 0xC9, 0x68, 0x88, 0x42, 0x10, 0xDB, 0x88, 0x42, 0x10, 0xD1, 0x02, 0x98, 0x01, 0x27, 0xBE, 0x46, 0xCE, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x06, 0x90, 0x20, 0x1C, 0xBE, 0x46, 0xCB, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x06, 0x99, 0x88, 0x42, 0x01, 0xDA, 0x05, 0x95, 0x02, 0x94 , +0x51, 0x48, 0x01, 0x68, 0xFF, 0x27, 0x09, 0x37, 0x38, 0x59, 0x00, 0x28, 0x06, 0xD0, 0xC7, 0x48, 0x00, 0x68, 0x07, 0x2E, 0x00, 0xD1, 0x2E, 0x1C, 0x08, 0x43, 0x04, 0xD0, 0xFF, 0x34, 0x1D, 0x34, 0x01, 0x35, 0x07, 0x2D, 0xC2, 0xDB, 0x07, 0x2E, 0xFF, 0xFF, 0x70, 0x6D, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x0A, 0xD1, 0xC0, 0x48, 0x00, 0x68, 0x08, 0x43, 0x06, 0xD0, 0x05, 0x9E, 0x30, 0x1C, 0x01, 0x21, 0x8E, 0x46, 0xBA, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x01, 0x98, 0x47, 0x61, 0x00, 0x21, 0x81, 0x61, 0xFF, 0x22, 0x1D, 0x32, 0x72, 0x43, 0x04, 0x99, 0x89, 0x18, 0xC1, 0x61, 0x06, 0x62, 0xB4, 0x48, 0x39, 0x30, 0x07, 0xB0, 0xF0, 0xBD, 0x10, 0xB5, 0x04, 0x1C, 0x00, 0x20, 0x01, 0x21, 0x8E, 0x46, 0xB1, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x40, 0x1E, 0x00, 0xD5, 0x00, 0x20, 0x60, 0x60, 0xE0, 0x61, 0xAE, 0x48, 0x21, 0x30, 0x10, 0xBD, 0xC0, 0x46, 0x10, 0x63, 0x08, 0x00, 0x70, 0xB5, 0x04, 0x1C, 0xE5, 0x69, 0x66, 0x69 , +0x00, 0x20, 0x01, 0x21, 0x8E, 0x46, 0xA7, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x60, 0x60, 0xAB, 0x19, 0xA6, 0x4A, 0xA5, 0x49, 0x93, 0x42, 0x02, 0xD3, 0x9A, 0x1A, 0x82, 0x42, 0x02, 0xD9, 0x08, 0x1C, 0x99, 0x30, 0x70, 0xBD, 0x08, 0x1C, 0xAB, 0x30, 0x70, 0xBD, 0x08, 0x6B, 0x41, 0x7D, 0x02, 0x88, 0x92, 0x00, 0xFF, 0xFF, 0x06, 0x6E, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x51, 0x1A, 0x3C, 0x39, 0xFF, 0x22, 0x5F, 0x32, 0x91, 0x42, 0x03, 0xD9, 0x65, 0x21, 0x01, 0x80, 0x02, 0x21, 0x81, 0x73, 0x9B, 0x48, 0x99, 0x49, 0x08, 0x18, 0xF7, 0x46, 0xC0, 0x46, 0x30, 0x63, 0x08, 0x00, 0xF8, 0xB5, 0x40, 0x68, 0x24, 0x21, 0x41, 0x43, 0x97, 0x48, 0x45, 0x18, 0x28, 0x1D, 0x0C, 0x21, 0x49, 0x19, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0x94, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x91, 0x4C, 0x00, 0x28, 0x1B, 0xD0, 0x2B, 0x1C, 0x04, 0x22, 0x6E, 0x46, 0x91, 0x49, 0x1F, 0x7B, 0x08, 0x78, 0xC0, 0x43, 0x38, 0x43, 0x30, 0x70, 0x01, 0x33 , +0x01, 0x31, 0x01, 0x36, 0x01, 0x3A, 0xF5, 0xD1, 0x0C, 0x20, 0x41, 0x19, 0x68, 0x46, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0x87, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x02, 0xD0, 0x20, 0x1C, 0x4A, 0x30, 0xF8, 0xBD, 0x20, 0x1C, 0xF8, 0xBD, 0xB1, 0xBD, 0x00, 0x00, 0x15, 0x95, 0x00, 0x00, 0x58, 0x3F, 0x08, 0x00, 0xF3, 0xF8, 0x00, 0x00, 0xE9, 0x09, 0x02, 0x00, 0xFF, 0xFF, 0x9C, 0x6E, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x2B, 0x09, 0x02, 0x00, 0xDD, 0x0A, 0x02, 0x00, 0xF8, 0xB5, 0x05, 0x1C, 0xAA, 0x69, 0x7D, 0x49, 0x00, 0x20, 0x08, 0x56, 0x24, 0x21, 0x41, 0x43, 0x76, 0x48, 0x43, 0x18, 0x04, 0x24, 0x6E, 0x46, 0x76, 0x49, 0x1F, 0x79, 0x08, 0x78, 0xC0, 0x43, 0x38, 0x43, 0x30, 0x70, 0x01, 0x33, 0x01, 0x31, 0x01, 0x36, 0x01, 0x3C, 0xF5, 0xD1, 0x11, 0x1D, 0x68, 0x46, 0x04, 0x22, 0x01, 0x24, 0xA6, 0x46, 0x6D, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x01, 0x1C, 0x6D, 0x48, 0x04, 0xD0, 0x6E, 0x49, 0x09, 0x78 , +0x69, 0x60, 0x45, 0x30, 0xF8, 0xBD, 0xEC, 0x61, 0xAF, 0x30, 0xF8, 0xBD, 0x70, 0xB5, 0xC5, 0x68, 0x81, 0x68, 0x0A, 0x89, 0x6D, 0x4E, 0x00, 0x2A, 0x22, 0xD0, 0x01, 0x24, 0xC2, 0x6D, 0xA2, 0x18, 0xC2, 0x65, 0x08, 0x89, 0x0D, 0x28, 0x1B, 0xD1, 0x68, 0x6B, 0x21, 0x1C, 0xA6, 0x46, 0x63, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x22, 0x1C, 0x28, 0x1C, 0x00, 0x21, 0xA6, 0x46, 0x60, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x2C, 0x60, 0xE9, 0x6B, 0xFF, 0xFF, 0x32, 0x6F, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x28, 0x1C, 0xA6, 0x46, 0x5E, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x28, 0x1C, 0xA6, 0x46, 0x5C, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x30, 0x1C, 0x3D, 0x30, 0x70, 0xBD, 0x30, 0x1C, 0x23, 0x30, 0x70, 0xBD, 0xC0, 0x46, 0xB1, 0x02, 0x00, 0x00, 0x74, 0x3F, 0x08, 0x00, 0x19, 0xC6, 0x00, 0x00, 0x5C, 0x3F, 0x08, 0x00, 0x1D, 0xC2, 0x00, 0x00, 0x68, 0x44, 0x08, 0x00, 0x43, 0x12, 0x03, 0x00, 0x34, 0x63, 0x08, 0x00, 0x2F, 0x7A, 0x02, 0x00 , +0xB4, 0x36, 0x08, 0x00, 0x8F, 0xF4, 0x01, 0x00, 0xF0, 0xB5, 0x05, 0x1C, 0xAB, 0x69, 0xEC, 0x69, 0x60, 0x68, 0x00, 0x68, 0x2A, 0x30, 0x01, 0x78, 0x0A, 0x06, 0x41, 0x78, 0x09, 0x04, 0x8A, 0x18, 0x81, 0x78, 0x09, 0x02, 0x8A, 0x18, 0xC1, 0x78, 0x8A, 0x18, 0x8E, 0x26, 0xF1, 0x5A, 0x09, 0x0A, 0x01, 0x70, 0xF0, 0x5C, 0x61, 0x68, 0x09, 0x68, 0x2B, 0x26, 0x70, 0x54, 0x8C, 0x20, 0xC0, 0x18, 0x61, 0x68, 0x0E, 0x68, 0x01, 0x88, 0x09, 0x0A, 0x2C, 0x27, 0xB9, 0x55, 0x61, 0x68, 0x09, 0x68, 0xFF, 0xFF, 0xC8, 0x6F, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x2D, 0x26, 0x00, 0x78, 0x70, 0x54, 0x60, 0x68, 0x01, 0x68, 0x32, 0x31, 0x08, 0x78, 0x00, 0x02, 0x49, 0x78, 0x08, 0x18, 0x00, 0x04, 0x00, 0x0C, 0x8C, 0x21, 0xCB, 0x58, 0x35, 0x49, 0x41, 0x40, 0x08, 0x04, 0x00, 0x0C, 0xC0, 0x18, 0x80, 0x1A, 0x01, 0x21, 0x8E, 0x46, 0x32, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x61, 0x68, 0x0A, 0x68, 0x32, 0x23, 0x01, 0x0A, 0x99, 0x54 , +0x61, 0x68, 0x09, 0x68, 0x33, 0x22, 0x50, 0x54, 0x60, 0x68, 0x68, 0x60, 0x2C, 0x48, 0xF0, 0xBD, 0x00, 0x00, 0x1B, 0x00, 0x34, 0x04, 0x1B, 0x00, 0x02, 0x6A, 0x8B, 0x69, 0xDB, 0x69, 0x1B, 0x68, 0x83, 0x60, 0x88, 0x69, 0xC0, 0x69, 0x41, 0x68, 0x8A, 0x42, 0x00, 0xDA, 0x42, 0x60, 0x25, 0x48, 0x79, 0x30, 0xF7, 0x46, 0x24, 0x48, 0x57, 0x30, 0xF7, 0x46, 0x24, 0x48, 0x91, 0x30, 0xF7, 0x46, 0x32, 0x04, 0x00, 0x00, 0xC4, 0x07, 0x00, 0x00, 0x15, 0x09, 0x02, 0x00, 0xC5, 0x93, 0x00, 0x00, 0x0D, 0x91, 0x00, 0x00, 0x40, 0x1E, 0x80, 0x00, 0x1E, 0x4B, 0xFF, 0xFF, 0x5E, 0x70, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x19, 0x50, 0x1C, 0x49, 0x0A, 0x50, 0xF7, 0x46, 0xC0, 0x46, 0xBD, 0xB5, 0x00, 0x00, 0x95, 0x92, 0x00, 0x00, 0xFD, 0x93, 0x00, 0x00, 0x54, 0x3F, 0x08, 0x00, 0x29, 0x4F, 0x03, 0x00, 0xDF, 0xE8, 0x02, 0x00, 0x36, 0x89, 0x41, 0x00, 0x81, 0x06, 0x00, 0x00, 0xB1, 0x78, 0x00, 0x00, 0x94, 0xEC, 0x01, 0x00 , +0x08, 0x19, 0x1B, 0x00, 0x8F, 0xC6, 0x03, 0x00, 0x1C, 0x17, 0x1B, 0x00, 0x67, 0x66, 0x03, 0x00, 0xA6, 0x44, 0x08, 0x00, 0x18, 0x17, 0x1B, 0x00, 0xA7, 0x2F, 0x02, 0x00, 0x91, 0x44, 0x03, 0x00, 0x91, 0x63, 0x03, 0x00, 0x5B, 0x44, 0x03, 0x00, 0xE7, 0x44, 0x03, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x61, 0xA2, 0x03, 0x00, 0x6A, 0x1E, 0x01, 0x00, 0x45, 0xDA, 0x00, 0x00, 0xD7, 0xE8, 0x01, 0x00, 0xE9, 0x78, 0x02, 0x00, 0x04, 0xF3, 0x1A, 0x00, 0x80, 0x7B, 0x08, 0x00, 0xFC, 0xB5, 0x04, 0x1C, 0xA5, 0x69, 0x60, 0x6A, 0x01, 0x90, 0x20, 0x69, 0x00, 0x28, 0x35, 0xD4, 0x08, 0x28, 0x33, 0xDA, 0xE1, 0x69, 0x09, 0x68, 0xFF, 0xFF, 0xF4, 0x70, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x10, 0x29, 0x2F, 0xD1, 0xAC, 0x21, 0x41, 0x43, 0x9E, 0x4A, 0x51, 0x5C, 0x49, 0x08, 0x27, 0xD3, 0x00, 0x06, 0x00, 0x16, 0xA2, 0x68, 0x69, 0x46, 0x01, 0x23, 0x9E, 0x46, 0x9A, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x06, 0x1C, 0x39, 0x30, 0x1F, 0xD0 , +0x00, 0x2E, 0x1D, 0xD0, 0x00, 0x98, 0x07, 0x68, 0x00, 0x99, 0x0C, 0x39, 0x01, 0x98, 0x01, 0x60, 0x28, 0x1D, 0x10, 0x21, 0x79, 0x1A, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0x91, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x02, 0x22, 0x2A, 0x80, 0xA8, 0x1C, 0x08, 0x21, 0x79, 0x1A, 0x01, 0x23, 0x9E, 0x46, 0x8C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x03, 0xE0, 0x38, 0x20, 0x00, 0xE0, 0x00, 0x20, 0xC6, 0x43, 0x26, 0x60, 0x89, 0x48, 0x7C, 0x30, 0x20, 0x62, 0xFC, 0xBD, 0x30, 0xB5, 0x05, 0x1C, 0x28, 0x69, 0xA9, 0x69, 0x90, 0x29, 0x1D, 0xD1, 0x69, 0x69, 0x09, 0x78, 0x04, 0x29, 0x19, 0xD0, 0x05, 0x29, 0x17, 0xD0, 0x0A, 0x29, 0x15, 0xD0, 0x06, 0x29, 0x13, 0xD0, 0x0C, 0x29, 0x01, 0xDB, 0xFF, 0xFF, 0x8A, 0x71, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x10, 0x29, 0x0F, 0xD1, 0x01, 0x24, 0xA6, 0x46, 0x7D, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x7C, 0x48, 0x7D, 0x49, 0x00, 0x22, 0xA6, 0x46, 0x7C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x7C, 0x48 , +0xFF, 0x30, 0x5F, 0x30, 0x28, 0x62, 0x30, 0xBD, 0xF0, 0xB5, 0x89, 0xB0, 0x05, 0x90, 0x41, 0x69, 0x02, 0x69, 0x75, 0x48, 0x79, 0x4E, 0x82, 0x42, 0x3A, 0xD0, 0x04, 0x30, 0x82, 0x42, 0x25, 0xD0, 0x74, 0x4D, 0xAA, 0x42, 0x00, 0xD0, 0xCC, 0xE0, 0x08, 0x68, 0x06, 0x1C, 0x0C, 0x22, 0x8F, 0x1A, 0x4A, 0x68, 0x89, 0x18, 0x09, 0x1D, 0x10, 0x22, 0x01, 0x24, 0xA6, 0x46, 0x6E, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x01, 0x1C, 0x09, 0xD1, 0xAC, 0x22, 0x72, 0x43, 0xCB, 0x48, 0x80, 0x18, 0x46, 0x22, 0x12, 0x5C, 0x11, 0x2A, 0x01, 0xD1, 0x44, 0x22, 0x14, 0x54, 0x28, 0x1C, 0x3A, 0x1C, 0xA6, 0x46, 0x62, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x69, 0x48, 0xEC, 0x30, 0xAB, 0xE0, 0x08, 0x68, 0xC0, 0x00, 0x30, 0x18, 0x8A, 0x68, 0x02, 0x2A, 0x02, 0xD0, 0xFF, 0xFF, 0x20, 0x72, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xE7, 0x20, 0x80, 0x00, 0xA2, 0xE0, 0xCA, 0x68, 0x89, 0x18, 0x09, 0x7B, 0x41, 0x60, 0x80, 0x21, 0x01, 0x60, 0x3B, 0x20 , +0x00, 0x01, 0x99, 0xE0, 0x08, 0x68, 0x06, 0x90, 0xC0, 0x00, 0x34, 0x58, 0x10, 0x20, 0x04, 0x90, 0x01, 0x25, 0xAE, 0x46, 0x57, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x07, 0x90, 0x00, 0x28, 0x00, 0xD1, 0x89, 0xE0, 0x0C, 0x21, 0x07, 0x98, 0x0F, 0x18, 0xB0, 0x49, 0xAC, 0x20, 0x06, 0x9A, 0x50, 0x43, 0x08, 0x18, 0x48, 0x22, 0x13, 0x5C, 0x5B, 0x06, 0x5B, 0x0E, 0x13, 0x54, 0x06, 0x9A, 0xD2, 0x00, 0xB6, 0x18, 0x71, 0x68, 0x00, 0x29, 0x47, 0xD1, 0x00, 0x2C, 0x01, 0xDD, 0x08, 0x2C, 0x21, 0xDB, 0x00, 0x22, 0x69, 0x46, 0x0A, 0x70, 0x01, 0x92, 0x0A, 0x81, 0x8A, 0x72, 0xCD, 0x72, 0x0D, 0x73, 0x4D, 0x73, 0x01, 0x88, 0x44, 0x48, 0x06, 0x23, 0xAE, 0x46, 0x44, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x04, 0x1C, 0x02, 0xDC, 0x00, 0x20, 0xC0, 0x43, 0x36, 0xE0, 0x34, 0x60, 0xAC, 0x20, 0x60, 0x43, 0x9A, 0x49, 0xFF, 0xFF, 0xB6, 0x72, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x09, 0x18, 0x5C, 0x22, 0x28, 0x1C, 0x50, 0x54, 0x48, 0x20 , +0x42, 0x5C, 0x52, 0x06, 0x52, 0x0E, 0x42, 0x54, 0xAC, 0x20, 0x60, 0x43, 0x94, 0x49, 0x08, 0x18, 0x5C, 0x21, 0x09, 0x5C, 0x49, 0x1E, 0x02, 0x29, 0x16, 0xD9, 0x03, 0x39, 0x08, 0xD0, 0x00, 0x20, 0x30, 0x56, 0xAE, 0x46, 0xEA, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x80, 0x20, 0x30, 0x60, 0xDB, 0xE7, 0x08, 0x94, 0x80, 0x21, 0x31, 0x60, 0x48, 0x22, 0x13, 0x5C, 0x19, 0x43, 0x11, 0x54, 0xAE, 0x46, 0xE4, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x0A, 0xE0, 0x01, 0x20, 0xCE, 0xE7, 0x06, 0x98, 0x39, 0x1C, 0x04, 0xAA, 0xAE, 0x46, 0xE0, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x04, 0x1C, 0x08, 0x90, 0x06, 0x98, 0x38, 0x60, 0x08, 0x98, 0x78, 0x60, 0x00, 0x28, 0x15, 0xD0, 0xAC, 0x20, 0x60, 0x43, 0x7C, 0x49, 0x09, 0x18, 0x48, 0x88, 0x02, 0x04, 0x02, 0x20, 0x10, 0x43, 0xB8, 0x60, 0x48, 0x68, 0x02, 0x0E, 0x01, 0x02, 0x09, 0x0E, 0x09, 0x02, 0x11, 0x43, 0x02, 0x04, 0x12, 0x0E, 0xFF, 0xFF, 0x4C, 0x73, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00 , +0x12, 0x04, 0x0A, 0x43, 0x00, 0x06, 0x10, 0x43, 0xF8, 0x60, 0x07, 0x98, 0x0D, 0x49, 0x00, 0x22, 0x10, 0x23, 0xAE, 0x46, 0xCE, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x13, 0x48, 0x00, 0xE0, 0x16, 0x20, 0xCC, 0x49, 0x09, 0x18, 0x05, 0x98, 0x01, 0x62, 0x09, 0xB0, 0xF0, 0xBD, 0x5D, 0x0D, 0x1B, 0x00, 0x81, 0xE7, 0x02, 0x00, 0x09, 0xB4, 0x03, 0x00, 0x27, 0x1A, 0x02, 0x00, 0x2F, 0x7A, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x05, 0x10, 0x00, 0x00, 0xCF, 0xF6, 0x00, 0x00, 0xD5, 0xF4, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x91, 0x19, 0x02, 0x00, 0x50, 0x65, 0x08, 0x00, 0x71, 0xC0, 0x02, 0x00, 0x50, 0x19, 0x1B, 0x00, 0x29, 0x16, 0x01, 0x00, 0x2A, 0x03, 0x00, 0x00, 0xF0, 0xB5, 0x8B, 0xB0, 0x07, 0x90, 0x05, 0x69, 0x47, 0x69, 0x0C, 0x20, 0x38, 0x1A, 0x08, 0x90, 0xB6, 0x49, 0x8D, 0x42, 0x16, 0xD1, 0x78, 0x68, 0x0F, 0x30, 0x00, 0x11, 0x00, 0x01, 0x78, 0x60, 0x38, 0x68, 0x0B, 0x28, 0x0E, 0xD8, 0x00, 0x23, 0x68, 0x46 , +0xFF, 0xFF, 0xE2, 0x73, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x03, 0x70, 0x08, 0x98, 0x05, 0x22, 0x01, 0x24, 0xA6, 0x46, 0xAE, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0xAE, 0x48, 0xFF, 0x30, 0x95, 0x30, 0x07, 0x99, 0x08, 0x62, 0xAC, 0x48, 0x85, 0x42, 0x23, 0xD1, 0xAC, 0x48, 0x02, 0x78, 0x6C, 0x46, 0x22, 0x72, 0x43, 0x78, 0x63, 0x72, 0x81, 0x78, 0xA1, 0x72, 0xC0, 0x78, 0xE0, 0x72, 0x00, 0x91, 0x01, 0x90, 0x03, 0x20, 0xA6, 0x49, 0x01, 0x39, 0x01, 0x26, 0xB6, 0x46, 0xF3, 0x4E, 0xFE, 0x44, 0x30, 0x47, 0x04, 0x20, 0x20, 0x70, 0x08, 0x98, 0x9F, 0x49, 0x00, 0x22, 0x02, 0xAB, 0x01, 0x24, 0xA6, 0x46, 0x9B, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x9A, 0x48, 0xFF, 0x30, 0x95, 0x30, 0x07, 0x99, 0x08, 0x62, 0xEB, 0x49, 0x8D, 0x42, 0x14, 0xD1, 0x02, 0x22, 0x68, 0x46, 0x02, 0x70, 0x3A, 0x68, 0xAC, 0x20, 0x42, 0x43, 0x30, 0x48, 0x68, 0x30, 0x83, 0x18, 0x08, 0x98, 0x00, 0x22, 0x01, 0x24, 0xA6, 0x46, 0x8F, 0x4C, 0xFE, 0x44 , +0x20, 0x47, 0x8E, 0x48, 0xFF, 0x30, 0x95, 0x30, 0x07, 0x99, 0xFF, 0xFF, 0x78, 0x74, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x08, 0x62, 0xEF, 0x48, 0x85, 0x42, 0x00, 0xD0, 0x04, 0xE1, 0x03, 0x20, 0x8C, 0x49, 0x01, 0x22, 0x96, 0x46, 0xEC, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x86, 0x48, 0xFF, 0x30, 0x95, 0x30, 0x09, 0x90, 0x38, 0x68, 0xEA, 0x4D, 0x00, 0x28, 0x00, 0xD1, 0xE2, 0xE0, 0x01, 0x24, 0xA6, 0x46, 0xE6, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x00, 0x28, 0x00, 0xD1, 0xD6, 0xE0, 0xE4, 0x48, 0x02, 0x68, 0x03, 0x20, 0x7F, 0x49, 0x01, 0x31, 0xA6, 0x46, 0xE2, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xDF, 0x48, 0x00, 0x68, 0x00, 0x28, 0x5A, 0xD1, 0xDF, 0x4D, 0x2E, 0x20, 0x41, 0x19, 0xB8, 0x68, 0x03, 0x30, 0x08, 0x70, 0x38, 0x7A, 0x48, 0x70, 0x2E, 0x1C, 0x30, 0x36, 0xB8, 0x68, 0x28, 0x18, 0x30, 0x30, 0xDA, 0x49, 0x0A, 0x68, 0x30, 0x3A, 0x31, 0x1C, 0xA6, 0x46, 0xD8, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x78, 0x68, 0x38, 0x18 , +0x01, 0x1D, 0xBA, 0x68, 0x30, 0x1C, 0xA6, 0x46, 0xD9, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xB8, 0x68, 0x41, 0x19, 0x97, 0x22, 0xFF, 0xFF, 0x0E, 0x75, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x09, 0x30, 0x50, 0x54, 0xB8, 0x68, 0x46, 0x19, 0x9E, 0x36, 0x30, 0x70, 0x01, 0x36, 0xB8, 0x68, 0x01, 0xE0, 0x14, 0x0D, 0x1B, 0x00, 0x30, 0x18, 0xCA, 0x49, 0x0A, 0x68, 0x9E, 0x3A, 0x31, 0x1C, 0xA6, 0x46, 0xC8, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x78, 0x68, 0x38, 0x18, 0x01, 0x1D, 0xBA, 0x68, 0x30, 0x1C, 0xA6, 0x46, 0xC9, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xB8, 0x68, 0x40, 0x00, 0xC0, 0x49, 0x09, 0x68, 0x08, 0x18, 0x28, 0x18, 0xC0, 0x49, 0x0A, 0x79, 0x02, 0x70, 0x4A, 0x79, 0x42, 0x70, 0x8A, 0x79, 0x82, 0x70, 0xC9, 0x79, 0xC1, 0x70, 0x04, 0x30, 0x0F, 0x21, 0x41, 0x1A, 0x0A, 0x78, 0xBB, 0x68, 0x9A, 0x18, 0x0A, 0x70, 0x40, 0x1B, 0x00, 0x04, 0x00, 0x0C, 0xB5, 0x49, 0x08, 0x60, 0xB1, 0x48, 0x04, 0x60, 0x02, 0x20, 0x01, 0x1C , +0x11, 0x22, 0xA6, 0x46, 0xB4, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x06, 0x1C, 0x63, 0xD4, 0x03, 0x20, 0xA6, 0x46, 0xB1, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x0A, 0x90, 0x00, 0x25, 0x01, 0x1C, 0xFF, 0xFF, 0xA4, 0x75, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x8D, 0x42, 0x50, 0xD0, 0x29, 0x1C, 0x2B, 0x22, 0xA6, 0x46, 0xAD, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x0C, 0x20, 0x0A, 0x99, 0x40, 0x18, 0xAC, 0x22, 0x72, 0x43, 0xAB, 0x49, 0x8F, 0x18, 0x78, 0x63, 0x29, 0x1C, 0x18, 0x22, 0xA6, 0x46, 0xA6, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x9F, 0x48, 0x02, 0x68, 0x79, 0x6B, 0x4A, 0x60, 0x0A, 0x98, 0xAC, 0x30, 0x08, 0x60, 0x08, 0x68, 0x9A, 0x49, 0xA6, 0x46, 0xA0, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x29, 0x1C, 0x03, 0xA8, 0x10, 0x22, 0xA6, 0x46, 0x9C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xE0, 0x21, 0x68, 0x46, 0x01, 0x74, 0x45, 0x74, 0x85, 0x74, 0xFB, 0x21, 0xC1, 0x74, 0xEE, 0x49, 0xC1, 0x81, 0x02, 0x21, 0x81, 0x81, 0x79, 0x6B, 0xCA, 0x68 , +0x01, 0x20, 0xC0, 0x03, 0x10, 0x43, 0xC8, 0x60, 0x48, 0x68, 0x00, 0x90, 0x2A, 0x1C, 0x30, 0x1C, 0x0A, 0x9D, 0x29, 0x1C, 0x03, 0xAB, 0xA6, 0x46, 0xE6, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0x07, 0x1C, 0x30, 0x06, 0x00, 0x16, 0xA6, 0x46, 0xEF, 0x49, 0xFF, 0xFF, 0x3A, 0x76, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xFE, 0x44, 0x08, 0x47, 0x28, 0x1C, 0xA6, 0x46, 0xEE, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x11, 0xE0, 0x30, 0x06, 0x00, 0x16, 0xA6, 0x46, 0xE9, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x01, 0x20, 0xC7, 0x43, 0x08, 0xE0, 0x07, 0x1C, 0x06, 0xE0, 0x00, 0x20, 0x00, 0x21, 0xCF, 0x43, 0x01, 0xE0, 0x00, 0x20, 0x07, 0x1C, 0x28, 0x60, 0x00, 0x23, 0x68, 0x46, 0x03, 0x70, 0x3A, 0x06, 0x12, 0x0E, 0x08, 0x98, 0x6F, 0x49, 0x01, 0x24, 0xA6, 0x46, 0x09, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x07, 0x98, 0x09, 0x99, 0x01, 0x62, 0x0B, 0xB0, 0xF0, 0xBD, 0xC1, 0x18, 0x01, 0x00, 0xF1, 0x1B, 0x01, 0x00, 0xF3, 0x1C, 0x02, 0x00, 0x7B, 0xC0 , +0x02, 0x00, 0x91, 0xF0, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0xA3, 0xC0, 0x02, 0x00, 0xA9, 0xE9, 0x00, 0x00, 0x07, 0x02, 0x00, 0x00, 0xE4, 0x62, 0x08, 0x00, 0xAC, 0x05, 0x00, 0x00, 0xFE, 0xB5, 0x07, 0x1C, 0x7D, 0x69, 0xBE, 0x69, 0x0C, 0x20, 0x30, 0x1A, 0x01, 0x90, 0xDF, 0x4C, 0x0A, 0x2D, 0x13, 0xD1, 0xFF, 0xFF, 0xD0, 0x76, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x30, 0x68, 0xDB, 0x49, 0x08, 0x60, 0x01, 0x20, 0x86, 0x46, 0xDA, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x0A, 0x20, 0x00, 0x21, 0x01, 0x9A, 0x01, 0x23, 0x9E, 0x46, 0xE6, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xF5, 0x20, 0x80, 0x00, 0x00, 0x19, 0x38, 0x62, 0x03, 0x2D, 0x79, 0xD1, 0xF5, 0x20, 0x80, 0x00, 0x00, 0x19, 0x02, 0x90, 0x70, 0x68, 0x00, 0x28, 0x0C, 0xD1, 0x00, 0x21, 0xCF, 0x48, 0x01, 0x60, 0xCF, 0x48, 0x00, 0x68, 0x00, 0x28, 0x61, 0xD0, 0x01, 0x21, 0x8E, 0x46, 0xCD, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x5B, 0xE0, 0xCC, 0x48, 0xB1, 0x68, 0x01, 0x60 , +0xF1, 0x68, 0x41, 0x60, 0x31, 0x69, 0x81, 0x60, 0x71, 0x69, 0xC1, 0x60, 0xB1, 0x69, 0xC1, 0x63, 0xF1, 0x69, 0x01, 0x64, 0x31, 0x6A, 0xC1, 0x64, 0x01, 0x24, 0xA6, 0x46, 0xC5, 0x48, 0xFE, 0x44, 0x00, 0x47, 0xA6, 0x46, 0xC4, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x70, 0x68, 0x7D, 0x25, 0xED, 0x00, 0xA8, 0x42, 0x21, 0xD8, 0x01, 0x28, 0x18, 0xD0, 0x02, 0x28, 0x05, 0xD0, 0xFF, 0xFF, 0x66, 0x77, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x28, 0x1C, 0xA6, 0x46, 0xBE, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x1C, 0xE0, 0xB9, 0x48, 0x00, 0x23, 0x19, 0x1C, 0x59, 0x43, 0x3E, 0x22, 0x4A, 0x43, 0x82, 0x83, 0x02, 0x30, 0x01, 0x33, 0x10, 0x2B, 0xF6, 0xDB, 0xA6, 0x46, 0xB4, 0x48, 0xFE, 0x44, 0x00, 0x47, 0xB5, 0x48, 0x0D, 0xE0, 0xB5, 0x4D, 0x28, 0x1C, 0xA6, 0x46, 0xB2, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x04, 0xE0, 0xA6, 0x46, 0xAF, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x75, 0x68, 0xAE, 0x48, 0x05, 0x60, 0x05, 0x1C, 0xA7, 0x4E, 0x30, 0x68 , +0x00, 0x28, 0x06, 0xD1, 0xAD, 0x48, 0x00, 0x68, 0xA6, 0x46, 0xAC, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x30, 0x60, 0x00, 0x94, 0x2B, 0x68, 0xAA, 0x49, 0xAB, 0x4A, 0xA6, 0x46, 0xAB, 0x4D, 0xFE, 0x44, 0x28, 0x47, 0x9C, 0x48, 0x04, 0x60, 0x03, 0x20, 0x00, 0x21, 0x01, 0x9A, 0x01, 0x23, 0x9E, 0x46, 0xA7, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x02, 0x98, 0x38, 0x62, 0xFE, 0xBD, 0xC0, 0x46, 0x13, 0x7F, 0x03, 0x00, 0x12, 0x10, 0x00, 0x00, 0xFF, 0xFF, 0xFC, 0x77, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x30, 0xB5, 0x05, 0x1C, 0x00, 0x20, 0x01, 0x24, 0xA6, 0x46, 0xA0, 0x49, 0xFE, 0x44, 0x08, 0x47, 0xA6, 0x46, 0x9F, 0x49, 0xFE, 0x44, 0x08, 0x47, 0xA6, 0x46, 0x9E, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x7D, 0x21, 0xC9, 0x00, 0xA6, 0x46, 0x9E, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0x9B, 0x49, 0x08, 0x18, 0x99, 0x49, 0x08, 0x80, 0x9B, 0x48, 0x0A, 0x30, 0x28, 0x62, 0x30, 0xBD, 0x11, 0x10, 0x00, 0x00, 0xDD, 0x7E, 0x03, 0x00, 0xB9, 0x90 , +0x00, 0x00, 0x6C, 0x64, 0x08, 0x00, 0xE7, 0x7E, 0x03, 0x00, 0x74, 0x64, 0x08, 0x00, 0x70, 0x64, 0x08, 0x00, 0x6D, 0xC6, 0x03, 0x00, 0x08, 0x19, 0x1B, 0x00, 0x11, 0x18, 0x02, 0x00, 0xD1, 0x78, 0x02, 0x00, 0xC9, 0xBA, 0x03, 0x00, 0x09, 0xB4, 0x03, 0x00, 0x14, 0x0D, 0x1B, 0x00, 0xFE, 0xB5, 0x02, 0x90, 0x45, 0x69, 0x68, 0x46, 0x01, 0x21, 0x8E, 0x46, 0x89, 0x49, 0xFE, 0x44, 0x08, 0x47, 0x89, 0x48, 0x04, 0x1C, 0x68, 0x68, 0x01, 0x69, 0x4A, 0x78, 0x00, 0x27, 0x3E, 0x1C, 0x20, 0x88, 0xFF, 0xFF, 0x92, 0x78, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x40, 0x08, 0x22, 0xD3, 0x20, 0x1D, 0x89, 0x1C, 0x01, 0x23, 0x9E, 0x46, 0x83, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x00, 0x28, 0x07, 0xD1, 0x68, 0x68, 0x00, 0x69, 0x40, 0x78, 0x21, 0x88, 0x09, 0x04, 0x89, 0x16, 0x81, 0x42, 0x3D, 0xD0, 0x02, 0x20, 0x00, 0x5F, 0x00, 0x99, 0x08, 0x1A, 0x00, 0x04, 0x00, 0x14, 0x3C, 0x28, 0x03, 0xDD, 0x20, 0x88, 0x40, 0x10, 0x40, 0x00 , +0x20, 0x80, 0x78, 0x1C, 0x07, 0x06, 0x3F, 0x0E, 0x68, 0x68, 0x01, 0x69, 0x4A, 0x78, 0x2A, 0x34, 0x01, 0x36, 0x14, 0x2E, 0xD5, 0xDB, 0x00, 0x2A, 0x02, 0xD1, 0xAB, 0x20, 0x40, 0x00, 0x50, 0xE0, 0x00, 0x9B, 0x6D, 0x48, 0x14, 0x21, 0x00, 0x22, 0x04, 0x88, 0x64, 0x08, 0x03, 0xD3, 0x2A, 0x30, 0x01, 0x32, 0x01, 0x39, 0xF8, 0xD1, 0x12, 0x06, 0x12, 0x0E, 0x14, 0x2F, 0x16, 0xD1, 0x66, 0x48, 0x00, 0x88, 0x00, 0x06, 0x44, 0x16, 0x64, 0x49, 0x00, 0x22, 0x01, 0x20, 0x4E, 0x8D, 0x36, 0x06, 0x76, 0x16, 0xA6, 0x42, 0x02, 0xDD, 0x34, 0x1C, 0x02, 0x06, 0xFF, 0xFF, 0x28, 0x79, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0x12, 0x0E, 0x2A, 0x31, 0x01, 0x30, 0x14, 0x28, 0xF3, 0xDB, 0x02, 0xE0, 0x32, 0x06, 0x12, 0x0E, 0x00, 0x9B, 0x2A, 0x20, 0x42, 0x43, 0x5A, 0x48, 0x11, 0x18, 0x0C, 0x88, 0x01, 0x20, 0x20, 0x43, 0x00, 0x04, 0x00, 0x0C, 0x08, 0x80, 0xFE, 0x24, 0xA0, 0x43, 0x14, 0x24, 0x64, 0x57, 0x64, 0x06, 0x24, 0x0E , +0x04, 0x43, 0x52, 0x48, 0x14, 0x52, 0x14, 0x18, 0x63, 0x80, 0x08, 0x88, 0x80, 0x05, 0x82, 0x0D, 0x68, 0x68, 0x00, 0x69, 0x40, 0x78, 0x80, 0x02, 0x10, 0x43, 0x08, 0x80, 0x68, 0x68, 0x02, 0x69, 0x20, 0x1D, 0x91, 0x1C, 0x52, 0x78, 0x01, 0x23, 0x9E, 0x46, 0x4B, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x02, 0x98, 0x04, 0x61, 0xFE, 0x20, 0x47, 0x49, 0x09, 0x18, 0x02, 0x98, 0x01, 0x62, 0xFE, 0xBD, 0x82, 0x69, 0x41, 0x69, 0x03, 0x69, 0x02, 0x2B, 0x0A, 0xD1, 0x01, 0x2A, 0x01, 0xD1, 0x00, 0x29, 0x05, 0xD0, 0x02, 0x2A, 0x04, 0xD1, 0x00, 0x29, 0x02, 0xD1, 0x11, 0x21, 0x00, 0xE0, 0x06, 0x21, 0x41, 0x61, 0xF7, 0x46, 0xFF, 0xFF, 0xBE, 0x79, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xC0, 0x46, 0x14, 0xE9, 0x00, 0x00, 0xC9, 0x18, 0x02, 0x00, 0x30, 0xB5, 0x05, 0x1C, 0x3A, 0x48, 0x00, 0x78, 0x00, 0x28, 0x04, 0xD0, 0x01, 0x20, 0x86, 0x46, 0x38, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x01, 0x24, 0xA6, 0x46, 0x37, 0x48, 0xFE, 0x44 , +0x00, 0x47, 0xA6, 0x46, 0x36, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x35, 0x48, 0x0E, 0x30, 0x28, 0x62, 0x30, 0xBD, 0x49, 0x19, 0x01, 0x00, 0x2F, 0x7A, 0x02, 0x00, 0x18, 0xB5, 0x43, 0x69, 0x81, 0x69, 0x31, 0x48, 0x81, 0x29, 0x00, 0xD1, 0x0B, 0x38, 0x00, 0x21, 0x00, 0x91, 0x1A, 0x68, 0x9B, 0x68, 0x01, 0x24, 0xA6, 0x46, 0x2D, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x18, 0xBD, 0x18, 0xB5, 0x40, 0x69, 0x00, 0x21, 0x00, 0x91, 0x02, 0x68, 0x83, 0x68, 0x27, 0x48, 0x01, 0x30, 0x01, 0x24, 0xA6, 0x46, 0x26, 0x4C, 0xFE, 0x44, 0x20, 0x47, 0x18, 0xBD, 0xC0, 0x46, 0x30, 0x63, 0x08, 0x00, 0x19, 0x9E, 0x00, 0x00, 0xB9, 0xEC, 0x00, 0x00, 0x74, 0x3F, 0x08, 0x00, 0x80, 0x3F, 0x08, 0x00, 0xFF, 0xFF, 0x54, 0x7A, 0x08, 0x00, 0x96, 0x00, 0x00, 0x00, 0xB7, 0x5D, 0x03, 0x00, 0x00, 0x00, 0x1B, 0x00, 0xD3, 0x8E, 0x00, 0x00, 0xF7, 0xC6, 0x00, 0x00, 0xE5, 0x90, 0x00, 0x00, 0x68, 0x64, 0x08, 0x00, 0xC0, 0x27, 0x09, 0x00, 0xA0, 0x3B , +0x08, 0x00, 0x3D, 0x5D, 0x03, 0x00, 0x19, 0xC6, 0x00, 0x00, 0xE8, 0x3A, 0x08, 0x00, 0x81, 0x5D, 0x03, 0x00, 0xCF, 0xF6, 0x00, 0x00, 0x4B, 0x4F, 0x03, 0x00, 0x6B, 0xC0, 0x03, 0x00, 0x95, 0x1E, 0x01, 0x00, 0xDA, 0x40, 0x08, 0x00, 0xDC, 0x05, 0x00, 0x00, 0x55, 0xAA, 0x03, 0x00, 0x0D, 0x91, 0x00, 0x00, 0xD7, 0x56, 0x03, 0x00, 0x08, 0x51, 0x08, 0x00, 0x8F, 0xC6, 0x03, 0x00, 0x65, 0xB8, 0x00, 0x00, 0x09, 0xB4, 0x03, 0x00, 0x84, 0x17, 0x1B, 0x00, 0xB5, 0x86, 0x01, 0x00, 0x3D, 0x47, 0x02, 0x00, 0x73, 0x49, 0x02, 0x00, 0x5F, 0x90, 0x00, 0x00, 0x0E, 0x10, 0x00, 0x00, 0xF7, 0xF6, 0x00, 0x00, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x76, 0xFF, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x5A, 0xFF, 0xFF, 0xBD, 0xFF, 0xB5, 0xFF, 0xFF, 0xEA, 0x7A, 0x08, 0x00, 0x58, 0x00, 0x00, 0x00, 0x68, 0x46, 0xFF, 0xF7, 0x99, 0xFF, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x83, 0xFF, 0xFF, 0xBD, 0xFF, 0xB5 , +0x68, 0x46, 0xFF, 0xF7, 0xB6, 0xFE, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x55, 0xFC, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x27, 0xFB, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0xDD, 0xFA, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x68, 0xFE, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0x3D, 0xFB, 0xFF, 0xBD, 0xFF, 0xB5, 0x68, 0x46, 0xFF, 0xF7, 0xBE, 0xFD, 0xFF, 0xBD, 0x78, 0x7B, 0x08, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0xB5, 0xF8, 0xF0, 0x43, 0xFA, 0x00, 0xBD, 0x35, 0x66, 0x08, 0x00, 0x67, 0x66, 0x08, 0x00, 0x71, 0x65, 0x08, 0x00, 0x4D, 0x66, 0x08, 0x00, 0x25, 0x64, 0x08, 0x00, 0x81, 0x66, 0x08, 0x00, 0x8D, 0x66, 0x08, 0x00, 0x99, 0x66, 0x08, 0x00, 0x87, 0x67, 0x08, 0x00, 0xA7, 0x67, 0x08, 0x00, 0xD1, 0x67, 0x08, 0x00, 0x1B, 0x68, 0x08, 0x00, 0x57, 0x68, 0x08, 0x00, 0x2D, 0x69, 0x08, 0x00, 0xB1, 0x6B, 0x08, 0x00, 0xD5, 0x6B, 0x08, 0x00, 0xF9, 0x6B , +0x08, 0x00, 0x15, 0x6C, 0x08, 0x00, 0xA1, 0x68, 0x08, 0x00, 0x59, 0x6C, 0x08, 0x00, 0xA7, 0x6D, 0x08, 0x00, 0xFF, 0x6D, 0x08, 0x00, 0x29, 0x6E, 0x08, 0x00, 0xF9, 0x6E, 0x08, 0x00, 0xD9, 0x6C, 0x08, 0x00, 0xA5, 0x6E, 0x08, 0x00, 0xCD, 0x6D, 0x08, 0x00, 0x81, 0x6F, 0x08, 0x00, 0x1D, 0x70, 0x08, 0x00, 0x31, 0x64, 0x08, 0x00, 0x39, 0x70, 0x08, 0x00, 0x3F, 0x70, 0x08, 0x00, 0x04, 0xF3, 0x1A, 0x00, 0x80, 0x00, 0x00, 0x00, 0xB2, 0x4E, 0x01, 0x00, 0x5A, 0xC1, 0x00, 0x00, 0x96, 0x1A, 0x01, 0x00, 0x22, 0x0B, 0x02, 0x00, 0x60, 0xD0, 0x01, 0x00, 0x06, 0x1A, 0x00, 0x00, 0xB8, 0xC6, 0x01, 0x00, 0xD8, 0x42, 0x03, 0x00, 0x16, 0x42, 0x03, 0x00, 0xEE, 0xDB, 0x00, 0x00, 0x62, 0xDC, 0x00, 0x00, 0xC8, 0xE1, 0x00, 0x00, 0x8A, 0x17, 0x02, 0x00, 0x38, 0xBE, 0x00, 0x00, 0x26, 0xC6, 0x00, 0x00, 0x56, 0xC2, 0x00, 0x00, 0x62, 0x12, 0x03, 0x00, 0xE4, 0xF4, 0x01, 0x00, 0x3A, 0xEC, 0x00, 0x00, 0x5E, 0x92, 0x00, 0x00 , +0xFE, 0xE8, 0x02, 0x00, 0x18, 0x7F, 0x00, 0x00, 0x64, 0xEC, 0x01, 0x00, 0xFE, 0x44, 0x03, 0x00, 0x1C, 0x94, 0x00, 0x00, 0xA8, 0x66, 0x03, 0x00, 0x74, 0xE9, 0x02, 0x00, 0x68, 0x1E, 0x01, 0x00, 0xBC, 0xDA, 0x00, 0x00, 0xEA, 0xE1, 0x00, 0x00, 0x24, 0xE9, 0x01, 0x00, 0x70, 0x79, 0x02, 0x00, 0x00, 0x00, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 0x1C, 0xF0, 0xB5, 0x88, 0xB0, 0xCA, 0x4C, 0x03, 0x20, 0x22, 0x78, 0x63, 0x78, 0xCA, 0x4E, 0x31, 0x1C, 0x01, 0x39, 0x01, 0x25, 0xAE, 0x46, 0xC7, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0xA2, 0x78, 0xE3, 0x78, 0x03, 0x20, 0x31, 0x1C, 0xAE, 0x46, 0xC3, 0x4F, 0xFE, 0x44, 0x38, 0x47, 0x03, 0x20, 0x31, 0x1C, 0x01, 0x31, 0xAE, 0x46, 0xC1, 0x4A, 0xFE, 0x44, 0x10, 0x47, 0xC1, 0x48, 0x21, 0x78, 0x01, 0x70, 0x61, 0x78, 0x41, 0x70, 0xE1, 0x78, 0xC1, 0x70, 0xA1, 0x78, 0x81, 0x70, 0xBF, 0x48, 0x04, 0x1C, 0x33, 0x3C, 0x20, 0x1C, 0x00, 0x21, 0xDC, 0x22, 0xAE, 0x46 , +0xBA, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x84, 0x20, 0xA0, 0x70, 0x05, 0x27, 0xE7, 0x71, 0x0C, 0x26, 0x26, 0x73, 0x0D, 0x20, 0x00, 0x19, 0x98, 0xA1, 0x32, 0x1C, 0xAE, 0x46, 0xB4, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x04, 0x20, 0x60, 0x76, 0x1A, 0x20, 0x00, 0x19, 0x97, 0xA1, 0x06, 0x91, 0x04, 0x22, 0xAE, 0x46, 0xAE, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xFF, 0xFF, 0x96, 0x00, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0xA7, 0x77, 0x1F, 0x34, 0x95, 0xA1, 0x07, 0x91, 0x20, 0x1C, 0x3A, 0x1C, 0xAE, 0x46, 0xA9, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xE6, 0x71, 0x28, 0x1C, 0x60, 0x72, 0x11, 0x20, 0x20, 0x73, 0x94, 0x20, 0x60, 0x73, 0xC0, 0x25, 0x65, 0x74, 0xA6, 0x74, 0x09, 0x22, 0xE2, 0x74, 0xA3, 0x4C, 0x20, 0x1C, 0x8C, 0xA1, 0x01, 0x23, 0x9E, 0x46, 0x9F, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x07, 0x22, 0x62, 0x72, 0x9E, 0x4C, 0x0A, 0x34, 0x20, 0x1C, 0x89, 0xA1, 0x01, 0x23, 0x9E, 0x46, 0x9A, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x04, 0x20 , +0xE0, 0x71, 0x98, 0x4C, 0x12, 0x34, 0x20, 0x1C, 0x06, 0x99, 0x04, 0x22, 0x01, 0x23, 0x9E, 0x46, 0x94, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x27, 0x71, 0x93, 0x4C, 0x17, 0x34, 0x20, 0x1C, 0x07, 0x99, 0x3A, 0x1C, 0x01, 0x23, 0x9E, 0x46, 0x8E, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0xE6, 0x71, 0x01, 0x20, 0x60, 0x72, 0x11, 0x20, 0x20, 0x73, 0x94, 0x20, 0x60, 0x73, 0x02, 0x20, 0xE0, 0x73, 0x25, 0x74, 0x66, 0x74, 0xFF, 0xFF, 0x2C, 0x01, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0xA5, 0x74, 0x2F, 0x27, 0xE7, 0x74, 0x10, 0x20, 0x60, 0x75, 0x80, 0x26, 0xA6, 0x75, 0x01, 0x20, 0xE0, 0x75, 0x11, 0x20, 0xA0, 0x76, 0x94, 0x20, 0xE0, 0x76, 0x24, 0x20, 0x60, 0x77, 0x0A, 0x22, 0xA2, 0x77, 0x80, 0x4C, 0x36, 0x34, 0x20, 0x1C, 0x6D, 0xA1, 0x01, 0x23, 0x9E, 0x46, 0x7C, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x18, 0x22, 0xA2, 0x72, 0x7A, 0x4C, 0x41, 0x34, 0x20, 0x1C, 0x6B, 0xA1, 0x01, 0x23, 0x9E, 0x46, 0x76, 0x4B, 0xFE, 0x44, 0x18, 0x47 , +0x25, 0x76, 0x67, 0x76, 0x21, 0x20, 0xE0, 0x76, 0x26, 0x77, 0x01, 0x20, 0x60, 0x77, 0x72, 0x48, 0x61, 0x30, 0x11, 0x21, 0x01, 0x70, 0x94, 0x21, 0x41, 0x70, 0x04, 0x21, 0x01, 0x72, 0xD2, 0x21, 0x41, 0x72, 0xC5, 0x72, 0x1E, 0x21, 0x01, 0x73, 0x45, 0x73, 0x9E, 0x21, 0x81, 0x73, 0x01, 0x21, 0x01, 0x74, 0x46, 0x74, 0x81, 0x74, 0x11, 0x21, 0x41, 0x75, 0x94, 0x21, 0x81, 0x75, 0x04, 0x21, 0x01, 0x76, 0xAD, 0x20, 0x66, 0x49, 0x08, 0x60, 0x00, 0x24, 0x0F, 0x25, 0xFF, 0xFF, 0xC2, 0x01, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0x29, 0x06, 0x09, 0x0E, 0x00, 0x20, 0x6A, 0x46, 0x01, 0x23, 0x9E, 0x46, 0x62, 0x4B, 0xFE, 0x44, 0x18, 0x47, 0x6B, 0x46, 0x18, 0x88, 0x40, 0x08, 0x0E, 0xD3, 0xA0, 0x00, 0x0F, 0x21, 0xCA, 0x43, 0x69, 0x46, 0x0E, 0x88, 0x16, 0x40, 0x01, 0xAF, 0x3E, 0x52, 0x49, 0x88, 0x11, 0x40, 0x68, 0x44, 0xC1, 0x80, 0x60, 0x1C, 0x04, 0x04, 0x24, 0x0C, 0x01, 0x3D, 0x0B, 0x2D, 0xE0, 0xDA, 0x60, 0x1E , +0x00, 0x04, 0x00, 0x0C, 0x1D, 0xD0, 0x86, 0x46, 0x01, 0x1C, 0x01, 0xAD, 0x01, 0x22, 0xAE, 0x88, 0x90, 0x00, 0xC7, 0x5A, 0xB7, 0x42, 0x0A, 0xDA, 0xBC, 0x46, 0x07, 0x1C, 0x6F, 0x44, 0x7F, 0x88, 0x68, 0x44, 0x06, 0x80, 0xEE, 0x88, 0x46, 0x80, 0x60, 0x46, 0xA8, 0x80, 0xEF, 0x80, 0x04, 0x35, 0x50, 0x1C, 0x02, 0x04, 0x12, 0x0C, 0x01, 0x39, 0xE9, 0xD1, 0x70, 0x46, 0x01, 0x38, 0x86, 0x46, 0xE2, 0xD1, 0x99, 0x88, 0x68, 0x46, 0xC0, 0x88, 0x40, 0x18, 0x00, 0x04, 0x00, 0x0C, 0x42, 0x4B, 0x18, 0x80, 0x42, 0x49, 0x08, 0x1A, 0xFF, 0xFF, 0x58, 0x02, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0x58, 0x80, 0x02, 0x2C, 0x1E, 0xDB, 0x65, 0x1E, 0x01, 0xAA, 0x01, 0x20, 0x01, 0x1C, 0x8C, 0x00, 0x6B, 0x46, 0xE6, 0x5A, 0x93, 0x88, 0xD4, 0x88, 0xE7, 0x18, 0xB7, 0x42, 0x0C, 0xDA, 0x06, 0x24, 0x44, 0x43, 0x38, 0x4B, 0x1B, 0x19, 0x1F, 0x80, 0x1C, 0x88, 0x34, 0x1B, 0x5C, 0x80, 0x01, 0x24, 0x1C, 0x71, 0x40, 0x1C, 0x00, 0x04 , +0x00, 0x0C, 0x04, 0x32, 0x49, 0x1C, 0x09, 0x06, 0x09, 0x0E, 0x01, 0x3D, 0xE4, 0xD1, 0x00, 0x24, 0x31, 0x48, 0x04, 0x70, 0x31, 0x48, 0x04, 0x70, 0x31, 0x48, 0x04, 0x70, 0x31, 0x48, 0x04, 0x70, 0x01, 0x20, 0x86, 0x46, 0x30, 0x48, 0xFE, 0x44, 0x00, 0x47, 0x2F, 0x49, 0x22, 0x1C, 0x08, 0x68, 0x00, 0x28, 0x02, 0xD0, 0x01, 0x20, 0x90, 0x40, 0x04, 0x43, 0x04, 0x31, 0x01, 0x32, 0x20, 0x2A, 0xF5, 0xD3, 0x2A, 0x48, 0x04, 0x60, 0x08, 0xB0, 0xF0, 0xBD, 0x5F, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2D, 0x69, 0x6E, 0x66, 0x6F, 0x00, 0xC0, 0x46, 0xC0, 0x5F, 0x75, 0x64, 0x70, 0x00, 0xC0, 0xFF, 0xFF, 0xEE, 0x02, 0x18, 0x00, 0x96, 0x00, 0x00, 0x00, 0x46, 0xC0, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0xC0, 0x46, 0x5F, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x00, 0xC0, 0x46, 0x5F, 0x64, 0x6E, 0x73, 0x2D, 0x73, 0x64, 0x00, 0x64, 0x65, 0x76, 0x3D, 0x43, 0x43, 0x33, 0x30, 0x30, 0x30, 0x00, 0xC0, 0x76, 0x65 , +0x6E, 0x64, 0x6F, 0x72, 0x3D, 0x54, 0x65, 0x78, 0x61, 0x73, 0x2D, 0x49, 0x6E, 0x73, 0x74, 0x72, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x73, 0x00, 0xC0, 0x46, 0xC0, 0x00, 0x00, 0x18, 0x00, 0xF3, 0x7E, 0x03, 0x00, 0xC6, 0x05, 0x00, 0x00, 0xDD, 0x7E, 0x03, 0x00, 0xE4, 0x62, 0x08, 0x00, 0xC9, 0xBA, 0x03, 0x00, 0x09, 0xB4, 0x03, 0x00, 0xA7, 0x64, 0x08, 0x00, 0x70, 0x64, 0x08, 0x00, 0xDD, 0x0A, 0x02, 0x00, 0x48, 0x32, 0x08, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xE8, 0x62, 0x08, 0x00, 0xE9, 0x62, 0x08, 0x00, 0xEA, 0x62, 0x08, 0x00, 0xEB, 0x62, 0x08, 0x00, 0x81, 0x03, 0x18, 0x00, 0x80, 0x7B, 0x08, 0x00, 0x84, 0xF3, 0x1A, 0x00, 0x0D, 0x49, 0x0E, 0x48, 0xFF, 0xFF, 0x84, 0x03, 0x18, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x88, 0x67, 0x0E, 0x48, 0x88, 0x64, 0x0E, 0x48, 0x48, 0x64, 0x0E, 0x48, 0xC8, 0x64, 0x0E, 0x48, 0x08, 0x65, 0x11, 0x48, 0x02, 0x1C, 0x04, 0x32, 0x0C, 0x4B, 0x13, 0x60, 0x0C, 0x4B, 0x93, 0x62, 0x0C, 0x4A , +0x8A, 0x66, 0x0D, 0x49, 0x01, 0x60, 0x0D, 0x48, 0x0E, 0x49, 0x01, 0x60, 0x0E, 0x49, 0x41, 0x60, 0xF7, 0x46, 0x1C, 0x21, 0x08, 0x00, 0x1B, 0x7B, 0x08, 0x00, 0x11, 0x7B, 0x08, 0x00, 0x07, 0x7B, 0x08, 0x00, 0x39, 0x7B, 0x08, 0x00, 0x2F, 0x7B, 0x08, 0x00, 0x25, 0x7B, 0x08, 0x00, 0xFD, 0x7A, 0x08, 0x00, 0xDF, 0x7A, 0x08, 0x00, 0x50, 0x23, 0x08, 0x00, 0xD5, 0x7A, 0x08, 0x00, 0x58, 0x26, 0x08, 0x00, 0xF3, 0x7A, 0x08, 0x00, 0xE9, 0x7A, 0x08, 0x00 }; + +uint16_t drv_length = 8024; + +//Service Pack version P1.12.7.15.15 - FW patches +unsigned char PROGMEM fw_patch[5700] = { 0x00, 0x01, 0x00, 0x00, 0x3C, 0x16, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x14, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x68, 0x46, 0x25, 0xF0, 0x95, 0xFB, 0xE0, 0x6B, 0xD0, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x25, 0xF0, 0x38, 0xFB, 0x2C, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x25, 0xF0, 0x0A, 0xFB, 0x04, 0x15, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xB8, 0xF1, 0x90, 0x0F, 0xA4, 0x16, 0x00, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x66, 0xE0, 0x04, 0xA8, 0x35, 0x1D, 0x21, 0xF0, 0x99, 0xFC, 0x68, 0x46, 0x23, 0xF0, 0x28, 0xFB, 0x9A, 0xF8, 0x00, 0x00, 0x01, 0x28, 0x07, 0xD1, 0x28, 0x46, 0x05, 0xF0, 0xC3, 0xFE, 0x01, 0x46, 0x01, 0xAA, 0x00, 0x20, 0x21, 0xF0, 0x50, 0xF9, 0x28, 0x46, 0x05, 0xF0, 0xBB, 0xFE, 0x01, 0xA9, 0x21, 0xF0, 0x2A, 0xFA, 0xE9, 0x79, 0x4F, 0xEA, 0xE0, 0x00, 0x40, 0xB2, 0x11, 0xB1, 0x00, 0xF1, 0x06, 0x00, 0x40, 0xB2, 0xA8, 0x71, 0x1F, 0x38, 0x40, 0x00, 0xE8, 0x71, 0x30, 0x46 , +0x01, 0xF0, 0x0D, 0xFF, 0x10, 0xF1, 0x00, 0x09, 0x4F, 0xF0, 0x00, 0x01, 0x09, 0xD0, 0x28, 0x68, 0x40, 0x0C, 0x09, 0xD3, 0xE8, 0x68, 0xC0, 0x0B, 0x03, 0xD2, 0x48, 0x46, 0xFF, 0xF7, 0xDD, 0xFE, 0x01, 0x21, 0x28, 0x68, 0x40, 0x0C, 0x0A, 0xD2, 0x38, 0x68, 0x40, 0x1C, 0x38, 0x60, 0x20, 0x68, 0x6F, 0xF3, 0x0F, 0x00, 0x20, 0x60, 0x22, 0x68, 0x38, 0x68, 0x10, 0x43, 0x20, 0x60, 0xE8, 0x68, 0xC0, 0x0B, 0x0F, 0xD3, 0xD8, 0xF8, 0x00, 0x00, 0x00, 0xF1, 0x01, 0x00, 0xC8, 0xF8, 0x00, 0x00, 0x20, 0x68, 0x6F, 0xF3, 0x1F, 0x40, 0x20, 0x60, 0xD8, 0xF8, 0x00, 0x20, 0x20, 0x68, 0x40, 0xEA, 0x02, 0x40, 0x20, 0x60, 0x49, 0xB9, 0xB9, 0xF1, 0x00, 0x0F, 0x03, 0xD1, 0x30, 0x46, 0x07, 0xF0, 0xBE, 0xF9, 0x02, 0xE0, 0x48, 0x46, 0x07, 0xF0, 0x06, 0xFA, 0x6C, 0x17, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x68, 0x46, 0x0E, 0xF0, 0x85, 0xFB, 0x00, 0x9E, 0x00, 0x2E, 0x96, 0xD1, 0x05, 0xB0, 0xBD, 0xE8, 0xF0, 0x87, 0xC0, 0x46 , +0x9C, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x23, 0xF0, 0x2A, 0xFE, 0x74, 0x47, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0B, 0x21, 0x21, 0xF0, 0x41, 0xFA, 0x20, 0x68, 0x18, 0x4B, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x21, 0xF0, 0x1C, 0xF9, 0x0A, 0xE0, 0x20, 0x68, 0x00, 0x68, 0x0C, 0x21, 0x40, 0xF0, 0x20, 0x00, 0x21, 0xF0, 0x14, 0xF9, 0x10, 0x57, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0xA8, 0x20, 0xF0, 0x97, 0xF9, 0x01, 0x98, 0x5C, 0x57, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0xA8, 0x20, 0xF0, 0x71, 0xF9, 0x03, 0x98, 0x00, 0x58, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0xF0, 0x20, 0xF9, 0x1C, 0x58, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0xF0, 0x12, 0xF9, 0x54, 0x58, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0xA8, 0x20, 0xF0, 0xF5, 0xF8, 0x04, 0xAB, 0x04, 0x62, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x79, 0x1F, 0xF0, 0x1B, 0xFD, 0x69, 0xE0, 0x60, 0x93, 0x00, 0x00, 0x40, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xA6, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1B, 0xF0, 0x39, 0xFB, 0x28, 0x46, 0x90, 0xA8, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1B, 0xF0, 0x69, 0xF9, 0x1E, 0x48, 0x34, 0xAD, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x68, 0xFF, 0x29, 0x98, 0xAD, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10, 0xD4, 0x21, 0xD4, 0xB2, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0xD0, 0x1A, 0xF0, 0x47, 0xFC, 0x20, 0x98, 0xAC, 0xC5, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x19, 0xF0 , +0xDB, 0xFA, 0x09, 0x49, 0x28, 0xC6, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x19, 0xF0, 0x9E, 0xFA, 0xDC, 0xD3, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xB5, 0x18, 0xF0, 0xAB, 0xFC, 0x00, 0xF0, 0x03, 0xF8, 0x00, 0xBD, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xDF, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x17, 0xF0, 0xA8, 0xFD, 0xCC, 0xEB, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x38, 0x78, 0x17, 0xF0, 0x77, 0xF8, 0x38, 0x78, 0x16, 0xF0, 0xF0, 0xFF, 0xA8, 0xF7, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0E, 0x49, 0x09, 0x68, 0x23, 0x22, 0x41, 0x61, 0xC8, 0xF7, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x31, 0x2E, 0x31, 0x39, 0x2E, 0x33, 0x31, 0x34, 0x5F, 0x4E, 0x65, 0x77, 0x5F, 0x43, 0x43, 0x41, 0x5F, 0x61, 0x6C, 0x67, 0x6F, 0x72, 0x69, 0x74, 0x68, 0x6D, 0x00, 0xC0, 0x74, 0x56, 0x30, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4C, 0xF9, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0xA8, 0x16, 0xF0, 0x79, 0xF8 , +0x12, 0xE0, 0x38, 0xFA, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0xA8, 0x16, 0xF0, 0x03, 0xF8, 0x32, 0x20, 0x94, 0xFB, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x0C, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x05, 0xA8, 0x14, 0xF0, 0x05, 0xFF, 0x01, 0xF0, 0x10, 0x1B, 0x01, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x1E, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x13, 0xF0, 0x46, 0xBF, 0x18, 0x30, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x30, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x12, 0xF0, 0xD8, 0xFC, 0x9C, 0x31, 0x01, 0x00, 0x08, 0x00 , +0x00, 0x00, 0x68, 0x46, 0x12, 0xF0, 0x51, 0xFC, 0xFE, 0xF7, 0xF0, 0x35, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x68, 0x46, 0x12, 0xF0, 0x27, 0xFA, 0xFE, 0xF7, 0xF0, 0x3D, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x05, 0xA9, 0x11, 0xF0, 0x27, 0xFE, 0x20, 0x6F, 0xD0, 0x62, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0F, 0xF0, 0xB8, 0xFB, 0x80, 0x7E, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0xDF, 0xF8, 0x58, 0x82, 0xE0, 0x7E, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0D, 0xF0, 0x6A, 0xFE, 0x0B, 0xF0, 0x9A, 0xF9, 0x03, 0x20, 0xA8, 0xF5, 0x88, 0x71, 0x08, 0x60, 0xF2, 0xF7, 0x16, 0xF9, 0x7A, 0x48, 0x6B, 0x49, 0x9C, 0x7F, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x70, 0x51, 0x4D, 0xC4, 0x7F, 0x01, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x40, 0x49, 0x00, 0xF1, 0x52, 0x00, 0x3A, 0x4A, 0xA8, 0x81, 0x28, 0x83, 0xE8, 0x83, 0xE8, 0x84, 0xA8, 0x85, 0x2A, 0x60, 0x39, 0x48, 0x41, 0xF2, 0x11, 0x12, 0x2A, 0x85, 0x18, 0x90, 0x19, 0x91 , +0x39, 0x49, 0x1A, 0x91, 0x39, 0x49, 0x1B, 0x91, 0x39, 0x49, 0x20, 0x46, 0xDF, 0xF8, 0xC4, 0x90, 0x1C, 0x91, 0x38, 0x49, 0xDF, 0xF8, 0xC0, 0xB0, 0x31, 0x4E, 0x1D, 0x91, 0x48, 0x80, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0D, 0xF0, 0x7C, 0xFA, 0xB4, 0x80, 0x01, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x12, 0x66, 0x09, 0x84, 0x6B, 0x00, 0x20, 0x94, 0x70, 0x00, 0x20, 0xB4, 0x70, 0x00, 0x20, 0xC4, 0x78, 0x00, 0x20, 0x50, 0x7A, 0x00, 0x20, 0xFE, 0xFF, 0x03, 0x00, 0xA4, 0x70, 0x00, 0x20, 0xB0, 0x70, 0x00, 0x20, 0xB8, 0x70, 0x00, 0x20, 0x60, 0x55, 0x30, 0x80, 0x3C, 0x5C, 0x00, 0x20, 0x04, 0x74, 0x00, 0x20, 0xB8, 0xE4, 0x01, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x20, 0x78, 0x07, 0xF0, 0x01, 0xFC, 0x20, 0x78, 0x07, 0xF0, 0x7A, 0xFB, 0x04, 0x4D, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x2D, 0xE9, 0xF0, 0x4F, 0xAD, 0xF1, 0x8C, 0x0D, 0x04, 0x68, 0x0F, 0x30, 0x03, 0x94, 0xFE, 0xF7, 0xDB, 0xFA, 0x04, 0xF1, 0x14, 0x00 , +0x04, 0x90, 0x21, 0x7D, 0x00, 0x20, 0x21, 0xF0, 0x73, 0x01, 0x88, 0x29, 0x08, 0xBF, 0x01, 0x20, 0x05, 0x90, 0x03, 0x98, 0x00, 0x1D, 0x06, 0x90, 0x5D, 0x48, 0x00, 0x68, 0x01, 0x28, 0x40, 0xF0, 0xFA, 0x83, 0x5B, 0x4D, 0x5C, 0x48, 0xDF, 0xF8, 0x70, 0x91, 0x29, 0x68, 0xDF, 0xF8, 0x70, 0x81, 0xDF, 0xF8, 0x74, 0xA1, 0x88, 0x42, 0x21, 0xD1, 0x10, 0x22, 0x00, 0x21, 0x48, 0x46, 0x4F, 0x46, 0xFB, 0xF7, 0xB7, 0xFE, 0x10, 0x22, 0x00, 0x21, 0x40, 0x46, 0xFB, 0xF7, 0xB2, 0xFE, 0x54, 0x49, 0x08, 0x68, 0x40, 0xF4, 0x80, 0x10, 0x08, 0x60, 0x01, 0x20, 0x51, 0x46, 0x08, 0x60, 0x00, 0x21, 0x29, 0x60, 0x39, 0x78, 0x46, 0x46, 0x00, 0x91, 0x31, 0x78, 0x41, 0xF2, 0x11, 0x13, 0x04, 0x22, 0x01, 0x91, 0x07, 0x21, 0x02, 0x90, 0x03, 0x20, 0xF3, 0xF7, 0x41, 0xFC, 0x51, 0x46, 0x07, 0x91, 0x08, 0x68, 0x56, 0x49, 0xDF, 0xF8, 0x5C, 0xB1, 0x01, 0x28, 0x08, 0x91, 0x56, 0x49, 0xDF, 0xF8, 0x48, 0xA1, 0x09, 0x91, 0x55, 0x49 , +0x0A, 0x91, 0x44, 0x49, 0x0B, 0x91, 0x44, 0x49, 0x0C, 0x91, 0x44, 0x49, 0x0D, 0x91, 0x44, 0x49, 0x0E, 0x91, 0x44, 0x49, 0x0F, 0x91, 0x44, 0x49, 0x10, 0x91, 0x44, 0x49, 0xCC, 0x4D, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x11, 0x91, 0x44, 0x49, 0x12, 0x91, 0x44, 0x49, 0x13, 0x91, 0x44, 0x49, 0x14, 0x91, 0x44, 0x49, 0x15, 0x91, 0x44, 0x49, 0x16, 0x91, 0x9F, 0x49, 0x17, 0x91, 0x9F, 0x49, 0x18, 0x91, 0x9F, 0x49, 0x19, 0x91, 0x9F, 0x49, 0x1A, 0x91, 0x9F, 0x49, 0x1B, 0x91, 0x9F, 0x49, 0x1C, 0x91, 0x9F, 0x49, 0x1D, 0x91, 0x9F, 0x49, 0x1E, 0x91, 0x9F, 0x49, 0x1F, 0x91, 0x40, 0xF0, 0x00, 0x81, 0x04, 0x98, 0x40, 0x78, 0x00, 0xF0, 0x03, 0x01, 0x01, 0x29, 0x40, 0xF0, 0xF9, 0x80, 0x04, 0x99, 0x09, 0x78, 0x01, 0xF0, 0x0C, 0x01, 0x08, 0x29, 0x40, 0xF0, 0xF2, 0x80, 0x06, 0x99, 0x09, 0x88, 0xA1, 0xF1, 0x3C, 0x01, 0x0E, 0xB2, 0x05, 0x99, 0x11, 0xB1, 0xA6, 0xF1, 0x02, 0x06, 0x36, 0xB2, 0xC0, 0x09, 0x4F, 0xF0 , +0x00, 0x07, 0x15, 0xD3, 0x08, 0x3E, 0x36, 0xB2, 0x03, 0x2E, 0x10, 0xD0, 0x17, 0x2E, 0x0E, 0xD0, 0x08, 0x3E, 0x36, 0xB2, 0x03, 0x2E, 0x08, 0xD0, 0x17, 0x2E, 0x06, 0xD0, 0x36, 0x1F, 0x36, 0xB2, 0x03, 0x2E, 0x14, 0xBF, 0x17, 0x2E, 0x02, 0x27, 0x02, 0xE0, 0x03, 0x27, 0x00, 0xE0, 0x01, 0x27, 0x03, 0x2E, 0x18, 0xBF, 0x17, 0x2E, 0x04, 0x9A, 0x40, 0xF0, 0xC8, 0x80, 0x0A, 0x32, 0x12, 0xF8, 0x01, 0x1B, 0x05, 0x24, 0x12, 0xF8, 0x01, 0x3B, 0x4B, 0x40, 0x64, 0x1E, 0xD9, 0xB2, 0xF9, 0xD1, 0x81, 0xEA, 0x21, 0x11, 0x03, 0x2E, 0x94, 0x4E, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x01, 0xF0, 0x0F, 0x01, 0x48, 0x46, 0x35, 0xD0, 0x43, 0x46, 0xCA, 0x5C, 0x52, 0x1C, 0xCA, 0x54, 0x0C, 0x18, 0x33, 0xE0, 0x50, 0x57, 0x02, 0x00, 0x04, 0x74, 0x00, 0x20, 0x34, 0x12, 0x66, 0x09, 0x60, 0x57, 0x02, 0x00, 0x70, 0x57, 0x02, 0x00, 0xC8, 0x48, 0x30, 0x80, 0x4C, 0x57, 0x02, 0x00, 0x88, 0x57, 0x02, 0x00, 0x80, 0x57, 0x02, 0x00 , +0x18, 0x58, 0x02, 0x00, 0x20, 0x58, 0x02, 0x00, 0x28, 0x58, 0x02, 0x00, 0x30, 0x58, 0x02, 0x00, 0x38, 0x58, 0x02, 0x00, 0x40, 0x58, 0x02, 0x00, 0xE4, 0x58, 0x02, 0x00, 0xE2, 0x58, 0x02, 0x00, 0x14, 0x58, 0x02, 0x00, 0xEF, 0x58, 0x02, 0x00, 0xE0, 0x58, 0x02, 0x00, 0xEE, 0x58, 0x02, 0x00, 0x5C, 0x57, 0x02, 0x00, 0xE6, 0x58, 0x02, 0x00, 0xE8, 0x58, 0x02, 0x00, 0x0C, 0x18, 0x20, 0x78, 0x40, 0x1C, 0x20, 0x70, 0x20, 0x78, 0x43, 0x46, 0x03, 0xEB, 0x01, 0x08, 0x0A, 0x28, 0x76, 0xDB, 0x98, 0xF8, 0x00, 0x00, 0x0A, 0x28, 0x72, 0xDB, 0x94, 0x48, 0x00, 0x25, 0x01, 0x60, 0x04, 0x98, 0x00, 0xF1, 0x0A, 0x09, 0x40, 0x78, 0x41, 0x08, 0x24, 0xBF, 0x04, 0x99, 0x09, 0x1D, 0x04, 0xD2, 0x80, 0x08, 0x2E, 0xBF, 0x49, 0x46, 0x04, 0x99, 0x10, 0x31, 0x0B, 0x98, 0x06, 0x22, 0xFA, 0xF7, 0xB9, 0xFC, 0x0C, 0x98, 0x06, 0x22, 0x49, 0x46, 0xFA, 0xF7, 0xB4, 0xFC, 0x9B, 0x48, 0x9A, 0x49, 0x5C, 0x4F, 0x02, 0x00, 0xC8, 0x00 , +0x00, 0x00, 0x00, 0x78, 0x08, 0x22, 0x08, 0x60, 0x58, 0x46, 0x07, 0x60, 0x0D, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0xAF, 0xFD, 0x08, 0x22, 0x0E, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0xAA, 0xFD, 0x08, 0x22, 0x0F, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0xA5, 0xFD, 0x08, 0x22, 0x10, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0xA0, 0xFD, 0x08, 0x22, 0x11, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0x9B, 0xFD, 0x08, 0x22, 0x12, 0x98, 0x29, 0x46, 0xFB, 0xF7, 0x96, 0xFD, 0x07, 0x99, 0x02, 0x20, 0x08, 0x60, 0x13, 0x99, 0x28, 0x46, 0x08, 0x80, 0x08, 0x99, 0x08, 0x70, 0x14, 0x99, 0x08, 0x70, 0x15, 0x99, 0x08, 0x60, 0x16, 0x99, 0x08, 0x70, 0x17, 0x99, 0x08, 0x60, 0x18, 0x99, 0x08, 0x60, 0x19, 0x99, 0x08, 0x60, 0x09, 0x99, 0x08, 0x80, 0x0A, 0x99, 0x08, 0x80, 0x1A, 0x99, 0x08, 0x80, 0x7D, 0x49, 0x0D, 0x60, 0x1B, 0x99, 0x08, 0x70, 0x1C, 0x99, 0x08, 0x70, 0x1D, 0x99, 0x08, 0x70, 0x1E, 0x99, 0x08, 0x80, 0x1F, 0x99, 0x08, 0x80, 0x51, 0x46, 0x08, 0x80 , +0x20, 0x78, 0x00, 0x96, 0x04, 0x22, 0x01, 0x90, 0x98, 0xF8, 0x00, 0x00, 0x41, 0xF2, 0x14, 0x13, 0x07, 0x21, 0x02, 0x90, 0x03, 0x20, 0xF3, 0xF7, 0x07, 0xFB, 0x07, 0x98, 0xA2, 0x49, 0x00, 0x68, 0x20, 0x91, 0xA2, 0x49, 0x05, 0x28, 0x21, 0x91, 0x9E, 0x49, 0x22, 0x91, 0x40, 0xF0, 0x37, 0x82, 0x04, 0x98, 0x40, 0x78, 0x24, 0x50, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x41, 0x08, 0x24, 0xBF, 0x04, 0x99, 0x09, 0x1D, 0x05, 0xD2, 0x80, 0x08, 0x27, 0xBF, 0x04, 0x99, 0x0A, 0x31, 0x04, 0x99, 0x10, 0x31, 0x0B, 0x98, 0xF8, 0xF7, 0x2D, 0xFC, 0x01, 0x28, 0x04, 0x98, 0x40, 0xF0, 0x23, 0x82, 0x40, 0x78, 0x00, 0xF0, 0x03, 0x00, 0x03, 0x28, 0x18, 0xD0, 0x02, 0x28, 0x07, 0xBF, 0x04, 0x99, 0x10, 0x31, 0x04, 0x99, 0x0A, 0x31, 0x13, 0xE0, 0x48, 0x58, 0x02, 0x00, 0x4C, 0x58, 0x02, 0x00, 0x50, 0x58, 0x02, 0x00, 0xF0, 0x58, 0x02, 0x00, 0xF2, 0x58, 0x02, 0x00, 0xF3, 0x58, 0x02, 0x00, 0xF4, 0x58, 0x02, 0x00, 0xEA, 0x58 , +0x02, 0x00, 0xEC, 0x58, 0x02, 0x00, 0x04, 0x99, 0x18, 0x31, 0x0C, 0x98, 0xF8, 0xF7, 0x06, 0xFC, 0x04, 0x99, 0x01, 0x28, 0x40, 0xF0, 0xFC, 0x81, 0x49, 0x78, 0x01, 0xF0, 0x03, 0x01, 0x01, 0x29, 0x40, 0xF0, 0xF6, 0x81, 0x59, 0x46, 0x09, 0x68, 0x04, 0x9A, 0x8E, 0x46, 0x51, 0x46, 0xD2, 0x8A, 0x0B, 0x88, 0x12, 0x11, 0x93, 0x42, 0x00, 0xF0, 0x37, 0x82, 0x0A, 0x80, 0x06, 0x99, 0x09, 0x88, 0x3C, 0x39, 0x0B, 0xB2, 0x71, 0x46, 0x49, 0x1E, 0x09, 0xD0, 0x49, 0x1E, 0x04, 0xD0, 0x49, 0x1E, 0x08, 0xD1, 0xA3, 0xF1, 0x10, 0x03, 0x04, 0xE0, 0xA3, 0xF1, 0x14, 0x03, 0x01, 0xE0, 0xA3, 0xF1, 0x08, 0x03, 0x1B, 0xB2, 0x05, 0x98, 0x10, 0xB1, 0xA3, 0xF1, 0x02, 0x03, 0x1B, 0xB2, 0xEC, 0x50, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0xF1, 0xCE, 0x81, 0x16, 0x98, 0x40, 0xF2, 0x77, 0x51, 0x99, 0x42, 0x0B, 0x90, 0x14, 0x98, 0x05, 0x90, 0x00, 0xF0, 0xA3, 0x81, 0x08, 0x46, 0x00, 0xF1, 0x3C, 0x00, 0x98, 0x42 , +0x05, 0x9A, 0x00, 0xF0, 0x9A, 0x81, 0xDF, 0xF8, 0x48, 0x82, 0x14, 0x78, 0x0B, 0x9A, 0xBB, 0x2C, 0x12, 0x78, 0x0C, 0x92, 0x63, 0xD1, 0xDD, 0xF8, 0x68, 0xC0, 0xBC, 0xF9, 0x00, 0x20, 0x91, 0x42, 0x18, 0xBF, 0x90, 0x42, 0x5B, 0xD1, 0x1C, 0x2B, 0x4F, 0xF0, 0x00, 0x00, 0xC0, 0xF2, 0x82, 0x81, 0x3D, 0x2B, 0x13, 0x9D, 0x80, 0xF2, 0x7E, 0x81, 0xA3, 0xF1, 0x1C, 0x01, 0x09, 0xB2, 0x29, 0x80, 0x1E, 0x9A, 0xDD, 0xF8, 0x30, 0x90, 0xB2, 0xF9, 0x00, 0x60, 0xB9, 0xF1, 0x01, 0x0F, 0x15, 0xD1, 0xDD, 0xF8, 0x24, 0x90, 0x03, 0x2E, 0x0D, 0xDA, 0xB9, 0xF9, 0x00, 0x70, 0xB9, 0x42, 0x07, 0xD0, 0x01, 0x26, 0x16, 0x80, 0x4A, 0x46, 0x0E, 0x46, 0x03, 0xE0, 0xC0, 0x46, 0x90, 0x57, 0x02, 0x00, 0x76, 0x1C, 0x16, 0x80, 0x1B, 0x9A, 0x16, 0x78, 0x1D, 0x9A, 0x16, 0x70, 0x0C, 0x9A, 0x1F, 0x9E, 0x02, 0x2A, 0x28, 0xD1, 0xB6, 0xF9, 0x00, 0x20, 0xBE, 0xF1, 0x00, 0x0F, 0x1A, 0xD0, 0x03, 0x2A, 0x35, 0x46, 0x0B, 0xDA, 0x0A, 0x9E , +0xB6, 0xF9, 0x00, 0x70, 0xB9, 0x42, 0x04, 0xD0, 0x01, 0x22, 0x2A, 0x80, 0x0A, 0x46, 0x35, 0x46, 0x00, 0xE0, 0xB4, 0x51, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x52, 0x1C, 0x2A, 0x80, 0x1C, 0x99, 0x0A, 0x78, 0x1D, 0x99, 0x0A, 0x70, 0x0F, 0xE0, 0xC0, 0x46, 0x58, 0x57, 0x02, 0x00, 0xA6, 0x64, 0x00, 0x20, 0x54, 0x57, 0x02, 0x00, 0x28, 0x80, 0x05, 0x99, 0x08, 0x70, 0x08, 0x9A, 0x11, 0x78, 0x41, 0xF0, 0x04, 0x01, 0x11, 0x70, 0x04, 0x46, 0x45, 0x46, 0xAC, 0xF8, 0x00, 0x00, 0x28, 0x70, 0xCC, 0x2C, 0x09, 0x9A, 0x40, 0xF0, 0x00, 0x81, 0xDD, 0xF8, 0x7C, 0xC0, 0x0A, 0x99, 0x1E, 0x9F, 0x45, 0x46, 0xB1, 0xF9, 0x00, 0x60, 0xB2, 0xF9, 0x00, 0x90, 0x28, 0x78, 0xCD, 0xF8, 0x50, 0xC0, 0x16, 0x91, 0x0A, 0x97, 0x13, 0x92, 0x09, 0x95, 0x0C, 0x99, 0x01, 0x29, 0x05, 0xD1, 0x05, 0x9A, 0xB0, 0xEB, 0x49, 0x0F, 0x01, 0xD1, 0x00, 0x21, 0x11, 0x70, 0x0C, 0x99, 0x02, 0x29, 0x05, 0xD1, 0x05, 0x9A, 0xB0, 0xEB, 0x46, 0x0F , +0x01, 0xD1, 0x00, 0x21, 0x11, 0x70, 0xB3, 0xF5, 0x14, 0x7F, 0x40, 0xF3, 0xBA, 0x80, 0x40, 0xF2, 0x51, 0x31, 0x99, 0x42, 0x08, 0x99, 0x40, 0xF3, 0xB4, 0x80, 0x09, 0x78, 0x06, 0x29, 0x00, 0xF0, 0xB0, 0x80, 0xA3, 0xF2, 0x51, 0x21, 0x0B, 0xB2, 0x4F, 0xEA, 0xE3, 0x01, 0x03, 0xEB, 0x11, 0x71, 0x4F, 0xEA, 0x21, 0x11, 0xCA, 0xB2, 0x4F, 0xEA, 0xE3, 0x01, 0x03, 0xEB, 0x11, 0x71, 0x15, 0x9D, 0x21, 0xF0, 0x0F, 0x01, 0xA3, 0xEB, 0x01, 0x03, 0x1D, 0x99, 0x2E, 0x68, 0x7C, 0x52, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x91, 0xF8, 0x00, 0xE0, 0x5F, 0xFA, 0x83, 0xF8, 0x60, 0xB1, 0x31, 0x18, 0x11, 0xF8, 0x01, 0x1C, 0x51, 0x40, 0xCB, 0xB2, 0x07, 0xE0, 0xC0, 0x46, 0x58, 0x58, 0x02, 0x00, 0x54, 0x58, 0x02, 0x00, 0xDC, 0x58, 0x02, 0x00, 0x13, 0x46, 0x19, 0x99, 0xDD, 0xF8, 0x6C, 0xA0, 0xDD, 0xF8, 0x70, 0xB0, 0xD1, 0xF8, 0x00, 0xC0, 0x00, 0xF0, 0x0F, 0x01, 0x99, 0x42, 0x22, 0xD0, 0x0A, 0x9B, 0x86, 0x45, 0x9A, 0xF8 , +0x00, 0x10, 0xB3, 0xF9, 0x00, 0x30, 0x9B, 0xF8, 0x00, 0x50, 0x15, 0xDD, 0x37, 0x5C, 0x44, 0x1C, 0x82, 0xEA, 0x07, 0x0C, 0x04, 0xF0, 0x0F, 0x07, 0x67, 0x45, 0x0B, 0xD0, 0xA6, 0x45, 0x06, 0x44, 0x0A, 0xDD, 0x76, 0x78, 0x72, 0x40, 0x86, 0x1C, 0x06, 0xF0, 0x0F, 0x06, 0x96, 0x42, 0x03, 0xD1, 0xC0, 0x1C, 0x4D, 0xE0, 0x80, 0x1C, 0x4B, 0xE0, 0x05, 0x9E, 0x00, 0x22, 0x32, 0x70, 0x4A, 0xE0, 0x00, 0xF0, 0x1F, 0x01, 0x01, 0x22, 0x8A, 0x40, 0x17, 0x99, 0xC4, 0x10, 0x0B, 0x68, 0x24, 0xF0, 0x03, 0x01, 0x5C, 0xF8, 0x01, 0x70, 0x3A, 0x42, 0x32, 0xD1, 0x5F, 0x58, 0x3A, 0x42, 0x06, 0x44, 0x1F, 0xD0, 0x18, 0x9B, 0x37, 0x78, 0x1B, 0x68, 0xB8, 0x45, 0x04, 0xD1, 0x58, 0x58, 0x02, 0x42, 0x19, 0xD0, 0x63, 0x46, 0x15, 0xE0, 0xA1, 0x10, 0x8C, 0x00, 0x19, 0x59, 0x91, 0x43, 0x19, 0x51, 0x00, 0x90, 0x30, 0x78, 0x01, 0x90, 0x44, 0x53, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x03, 0x20, 0x06, 0x21, 0x02, 0x46, 0x4D, 0xF6 , +0x80, 0x53, 0xF3, 0xF7, 0x63, 0xF9, 0x09, 0x99, 0x28, 0x68, 0x0E, 0x78, 0x36, 0x18, 0x06, 0xE0, 0xE3, 0x58, 0x02, 0x00, 0xA0, 0x10, 0x81, 0x00, 0x58, 0x58, 0x02, 0x43, 0x5A, 0x50, 0x86, 0xF8, 0x00, 0x80, 0x0B, 0x98, 0x00, 0x78, 0x0C, 0x90, 0x13, 0x98, 0xB0, 0xF9, 0x00, 0x90, 0x09, 0x98, 0x00, 0x78, 0x0A, 0x9A, 0x40, 0x1C, 0x9B, 0xF8, 0x00, 0x50, 0x9A, 0xF8, 0x00, 0x10, 0xB2, 0xF9, 0x00, 0x30, 0x09, 0x9A, 0xC0, 0xB2, 0x10, 0x70, 0x0C, 0x9A, 0x01, 0x2A, 0x03, 0xD1, 0x88, 0x42, 0xC8, 0xBF, 0x8A, 0xF8, 0x00, 0x00, 0x0C, 0x99, 0x02, 0x29, 0x07, 0xD1, 0xA8, 0x42, 0xC8, 0xBF, 0x8B, 0xF8, 0x00, 0x00, 0x02, 0xE0, 0x0A, 0x98, 0xB0, 0xF9, 0x00, 0x30, 0xB9, 0xF1, 0x00, 0x0F, 0x06, 0xDD, 0x03, 0x2B, 0x04, 0xD1, 0x11, 0x98, 0x01, 0x22, 0x49, 0x46, 0x00, 0xF0, 0x72, 0xFB, 0x16, 0x98, 0xB0, 0xF9, 0x00, 0x10, 0x14, 0x98, 0x00, 0x29, 0xB0, 0xF9, 0x00, 0x00, 0x05, 0xDD, 0x03, 0x28, 0x03, 0xD1, 0x12, 0x98 , +0x02, 0x22, 0x00, 0xF0, 0x64, 0xFB, 0x05, 0x98, 0x04, 0x78, 0x0B, 0x98, 0x00, 0x78, 0x0C, 0x90, 0x08, 0x98, 0xBB, 0x2C, 0x01, 0x78, 0x02, 0xD0, 0xAA, 0x2C, 0x2F, 0xD0, 0x31, 0xE0, 0x0C, 0x98, 0x01, 0x28, 0x0B, 0xD1, 0x0D, 0x98, 0x17, 0x9A, 0x10, 0x60, 0x0C, 0x54, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x0F, 0x98, 0x18, 0x9A, 0x10, 0x60, 0x19, 0x9A, 0x11, 0x98, 0x10, 0x60, 0x47, 0x4A, 0x15, 0x98, 0x02, 0x60, 0x0C, 0x98, 0x02, 0x28, 0x0B, 0xD1, 0x0E, 0x98, 0x17, 0x9A, 0x10, 0x60, 0x10, 0x98, 0x18, 0x9A, 0x10, 0x60, 0x19, 0x9A, 0x12, 0x98, 0x10, 0x60, 0x41, 0x4A, 0x15, 0x98, 0x02, 0x60, 0xCC, 0x20, 0x0F, 0xE0, 0x08, 0x99, 0x09, 0x78, 0x0C, 0xE0, 0x02, 0x20, 0x00, 0xE0, 0x01, 0x20, 0x0B, 0x99, 0x08, 0x70, 0x1A, 0x99, 0x0B, 0x80, 0x13, 0x99, 0x00, 0x20, 0x08, 0x80, 0x08, 0x98, 0x01, 0x78, 0xBB, 0x20, 0x05, 0x9A, 0x10, 0x70, 0x06, 0x29, 0x07, 0x99, 0x11, 0xD1, 0x06, 0x20, 0x08, 0x60, 0x20, 0x98 , +0x00, 0x25, 0x05, 0x70, 0x21, 0x98, 0x29, 0x46, 0x04, 0x22, 0xFB, 0xF7, 0x27, 0xFB, 0x01, 0x20, 0x00, 0xF0, 0x3A, 0xFA, 0x02, 0x20, 0x00, 0xF0, 0x37, 0xFA, 0x22, 0x98, 0x05, 0x60, 0x07, 0x98, 0x04, 0x99, 0x00, 0x68, 0x07, 0x28, 0x44, 0xD1, 0x09, 0x78, 0x03, 0x9C, 0x80, 0x29, 0x40, 0xD1, 0x38, 0x34, 0x21, 0x78, 0x64, 0x1C, 0x22, 0x46, 0x00, 0x29, 0x3A, 0xD1, 0x20, 0x98, 0x90, 0xF8, 0x00, 0xA0, 0x22, 0x98, 0x05, 0x90, 0xD0, 0xF8, 0x00, 0x90, 0x51, 0x46, 0x48, 0x46, 0xFD, 0xF7, 0x79, 0xF9, 0x5F, 0xFA, 0x80, 0xF8, 0x21, 0x9F, 0x15, 0x78, 0x51, 0x46, 0x48, 0x46, 0x17, 0xF8, 0x08, 0x30, 0xFD, 0xF7, 0xD4, 0x54, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x6F, 0xF9, 0x1E, 0x46, 0x1B, 0x1D, 0xC0, 0xB2, 0x38, 0x5C, 0x00, 0x1D, 0xA8, 0x42, 0x28, 0x46, 0x07, 0xDD, 0x80, 0x18, 0x82, 0x1C, 0x10, 0x78, 0x2D, 0x18, 0xAD, 0x1C, 0xAD, 0xB2, 0xAB, 0x42, 0xF7, 0xDC, 0x04, 0xF8, 0x01, 0x6B, 0x11, 0x49, 0x32, 0x46 , +0x20, 0x46, 0x01, 0xEB, 0x48, 0x11, 0xFA, 0xF7, 0xDC, 0xF9, 0xAD, 0x1B, 0xFF, 0x20, 0x34, 0x19, 0xAD, 0x1E, 0x04, 0xF8, 0x01, 0x0B, 0x25, 0x70, 0x05, 0x98, 0x01, 0x68, 0x49, 0x1C, 0x01, 0x60, 0x07, 0x98, 0x00, 0x68, 0x07, 0x28, 0x04, 0xD0, 0x06, 0x99, 0x08, 0x68, 0x20, 0xF4, 0x80, 0x30, 0x08, 0x60, 0x23, 0xB0, 0xBD, 0xE8, 0xF0, 0x8F, 0xC0, 0x46, 0x94, 0x57, 0x02, 0x00, 0xD4, 0x57, 0x02, 0x00, 0x5C, 0x58, 0x02, 0x00, 0x6E, 0x48, 0x2D, 0xE9, 0xF0, 0x47, 0x6E, 0x4D, 0x82, 0x89, 0x4A, 0xF6, 0x55, 0x21, 0xAD, 0xF5, 0xFE, 0x7D, 0x91, 0x42, 0x4F, 0xF0, 0x00, 0x01, 0xAD, 0xF1, 0x38, 0x0D, 0x12, 0xD1, 0x29, 0x60, 0x68, 0x4A, 0x11, 0x70, 0x41, 0xF2, 0x10, 0x41, 0x81, 0x81, 0x4F, 0xF6, 0xFF, 0x70, 0x66, 0x49, 0x08, 0x60, 0x28, 0x68, 0x00, 0x90, 0x02, 0x22, 0x05, 0x21, 0x03, 0x20, 0x41, 0xF2, 0x34, 0x23, 0xF3, 0xF7, 0x48, 0xF8, 0x29, 0x68, 0x61, 0x4C, 0x01, 0x29, 0x20, 0x68, 0x40, 0xF0, 0xAF, 0x80 , +0x5F, 0x4D, 0x02, 0x28, 0x29, 0x68, 0x23, 0xD1, 0x9C, 0x55, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x5E, 0x48, 0x00, 0x68, 0x5F, 0x4A, 0x12, 0x5C, 0x00, 0x92, 0x01, 0x91, 0x5E, 0x49, 0x09, 0x68, 0x02, 0x91, 0x5B, 0x49, 0x0B, 0x5C, 0x03, 0x20, 0x07, 0x21, 0x04, 0x22, 0xF3, 0xF7, 0x2E, 0xF8, 0x5B, 0x49, 0x4A, 0x79, 0x59, 0x48, 0x00, 0x92, 0x02, 0x79, 0x01, 0x92, 0x40, 0x79, 0x04, 0x22, 0x02, 0x90, 0x03, 0x20, 0x0B, 0x79, 0x07, 0x21, 0xF3, 0xF7, 0x20, 0xF8, 0x03, 0x20, 0x20, 0x60, 0xEC, 0xF7, 0x1A, 0xFF, 0x20, 0x68, 0x29, 0x68, 0x04, 0x28, 0x15, 0xD1, 0x0D, 0x20, 0x8D, 0xF8, 0x10, 0x00, 0x00, 0x25, 0x8D, 0xF8, 0x14, 0x50, 0x8D, 0xF8, 0x15, 0x10, 0x28, 0x46, 0x63, 0x21, 0x00, 0xF0, 0xAA, 0xFB, 0x63, 0x21, 0x28, 0x46, 0x00, 0xF0, 0xFA, 0xFA, 0x03, 0xA9, 0x04, 0xA8, 0xE0, 0xF7, 0xCA, 0xFC, 0x05, 0x20, 0x20, 0x60, 0x46, 0x4D, 0x05, 0x28, 0x29, 0x68, 0x01, 0xF1, 0x01, 0x01, 0x29, 0x60, 0x1D, 0xD1 , +0x44, 0x4A, 0x8A, 0x42, 0x1A, 0xD1, 0x43, 0x48, 0x01, 0x68, 0x00, 0x91, 0x40, 0x68, 0x01, 0x90, 0x03, 0x20, 0x02, 0x46, 0x06, 0x21, 0x41, 0x4E, 0x33, 0x46, 0x22, 0x3B, 0xF2, 0xF7, 0xEB, 0xFF, 0x3E, 0x48, 0x01, 0x68, 0x00, 0x91, 0x40, 0x68, 0x33, 0x46, 0x06, 0x21, 0x01, 0x90, 0x03, 0x20, 0x02, 0x46, 0xF2, 0xF7, 0xE0, 0xFF, 0x00, 0x20, 0x28, 0x60, 0x20, 0x68, 0x06, 0x28, 0x47, 0xD1, 0x4F, 0xF0, 0x64, 0x56, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x07, 0x0A, 0xC4, 0xF8, 0x00, 0xA0, 0x03, 0x20, 0x48, 0xF2, 0x70, 0x53, 0x01, 0x22, 0x04, 0x21, 0xF2, 0xF7, 0xD0, 0xFF, 0xDF, 0xF8, 0xCC, 0x80, 0x31, 0x4F, 0x48, 0xF2, 0x70, 0x59, 0x01, 0x25, 0x49, 0xEA, 0x05, 0x03, 0x01, 0x22, 0x04, 0x21, 0x03, 0x20, 0xF2, 0xF7, 0xC3, 0xFF, 0x00, 0x24, 0x17, 0xF8, 0x02, 0x0F, 0x20, 0xE0, 0x69, 0x01, 0x04, 0xEB, 0x08, 0x02, 0x88, 0x18, 0xC6, 0x1C, 0x43, 0x78, 0x00, 0x93, 0x80, 0x78, 0x01, 0x90, 0x30, 0x78, 0x02, 0x90 , +0x53, 0x5C, 0x51, 0x46, 0x04, 0x22, 0x03, 0x20, 0xF2, 0xF7, 0xAE, 0xFF, 0x38, 0x78, 0x01, 0x1B, 0xB1, 0xF1, 0xFF, 0x3F, 0x08, 0xD1, 0xF0, 0x78, 0x00, 0x90, 0xB3, 0x78, 0x03, 0x20, 0x02, 0x22, 0x05, 0x21, 0xF2, 0xF7, 0xA1, 0xFF, 0x38, 0x78, 0x24, 0x1D, 0xE4, 0xB2, 0xA0, 0x42, 0xDC, 0xDC, 0xAD, 0x1C, 0xED, 0xB2, 0x04, 0x2D, 0xCD, 0xDB, 0x63, 0x21, 0x4F, 0xF4, 0x05, 0x70, 0xF1, 0xF7, 0xA3, 0xFC, 0xE1, 0xF7, 0x85, 0xFD, 0x7F, 0xB0, 0x0E, 0xB0, 0xBD, 0xE8, 0xF0, 0x87, 0xC0, 0x46, 0x04, 0x74, 0x00, 0x20, 0x50, 0x57, 0x02, 0x00, 0x6C, 0x5D, 0x02, 0x00, 0x40, 0x00, 0x3D, 0x80, 0x4C, 0x57, 0x02, 0x00, 0x58, 0x57, 0x02, 0x00, 0x90, 0x57, 0x02, 0x00, 0x60, 0x57, 0x02, 0x00, 0x70, 0x57, 0x02, 0x00, 0x5C, 0x57, 0x02, 0x00, 0x80, 0x57, 0x02, 0x00, 0x2C, 0x57, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x88, 0x57, 0x02, 0x00, 0x54, 0x57, 0x02, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x38, 0x58, 0x02, 0x00, 0x40, 0x58 , +0x02, 0x00, 0x66, 0x55, 0xDD, 0xEE, 0xDB, 0x58, 0x02, 0x00, 0x5C, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF4, 0x57, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBC, 0x58, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2D, 0xE9, 0xFE, 0x4F, 0x4A, 0x4A, 0x49, 0x4D, 0x00, 0x90, 0xB2, 0xF9, 0x00, 0x20, 0x43, 0xA3, 0x29, 0x78, 0x01, 0x93, 0x43, 0xA3, 0x01, 0x28, 0x02, 0x93, 0x47, 0x4E, 0xDF, 0xF8, 0x1C, 0x81, 0xDF, 0xF8, 0x1C, 0x91, 0x1E, 0xD0, 0x43, 0x48, 0x04, 0x78, 0x48, 0x01, 0x87, 0x19, 0x30, 0x18, 0x01, 0x99, 0x06, 0x22, 0xF9, 0xF7, 0xC8, 0xFF, 0x40, 0x46, 0x01, 0x78, 0x00, 0x68, 0x07, 0xF1, 0x06, 0x07, 0x07, 0xF8, 0x01, 0x1B, 0x07, 0xF8, 0x01, 0x4B, 0x4F, 0xF0, 0x00, 0x01, 0x07, 0xF8, 0x01, 0x1B, 0x20, 0xB9, 0x39, 0x70, 0x28, 0x78, 0x4E, 0x46, 0x0A, 0x21, 0x58, 0xE0, 0xDF, 0xF8, 0xE4, 0xB0, 0x0F, 0xE0, 0xD4, 0xB2, 0x48, 0x01, 0x87, 0x19, 0x30, 0x18, 0x02, 0x99, 0x07, 0x22, 0xF9, 0xF7, 0xAA, 0xFF, 0xFF, 0x1D, 0x00, 0x20, 0xDF, 0xF8, 0xCC, 0xB0, 0x07, 0xF8, 0x01, 0x4B, 0x07, 0xF8, 0x01, 0x0B, 0x16, 0x2C, 0xB2, 0x46, 0xAE, 0xBF, 0x14, 0x20, 0x84, 0x59 , +0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x60, 0x1E, 0xC0, 0xB2, 0x38, 0x70, 0x4E, 0x46, 0x7F, 0x1C, 0x40, 0x1C, 0xC2, 0xB2, 0x28, 0x78, 0x5B, 0x46, 0x00, 0x21, 0x32, 0x54, 0x38, 0x46, 0x00, 0xF0, 0xBC, 0xF9, 0x28, 0x78, 0x16, 0x2C, 0x31, 0x5C, 0x01, 0xF1, 0x0A, 0x01, 0x31, 0x54, 0x00, 0xF1, 0x01, 0x00, 0xC0, 0xB2, 0x28, 0x70, 0x2B, 0xDB, 0x00, 0x99, 0x0A, 0xEB, 0x40, 0x10, 0x07, 0x46, 0x01, 0x29, 0xA4, 0xF1, 0x01, 0x09, 0x09, 0xD0, 0x01, 0x99, 0x06, 0x22, 0xF9, 0xF7, 0x79, 0xFF, 0x40, 0x46, 0x00, 0x78, 0xBF, 0x1D, 0x07, 0xF8, 0x01, 0x0B, 0x04, 0xE0, 0x02, 0x99, 0x07, 0x22, 0xF9, 0xF7, 0x6F, 0xFF, 0xFF, 0x1D, 0x07, 0xF8, 0x01, 0x4B, 0x15, 0x3C, 0x15, 0x21, 0x28, 0x78, 0xE2, 0xB2, 0x5B, 0x46, 0x07, 0xF8, 0x01, 0x1B, 0x32, 0x54, 0x07, 0xF8, 0x01, 0x9B, 0x38, 0x46, 0x00, 0xF0, 0x8B, 0xF9, 0x28, 0x78, 0x31, 0x5C, 0x0A, 0x31, 0x31, 0x54, 0x40, 0x1C, 0x28, 0x70, 0xBD, 0xE8, 0xFE, 0x8F, 0xC0, 0x46 , +0x54, 0x54, 0x54, 0x4B, 0x45, 0x59, 0x00, 0xC0, 0x54, 0x54, 0x54, 0x53, 0x53, 0x49, 0x44, 0x00, 0x54, 0x58, 0x02, 0x00, 0xE6, 0x58, 0x02, 0x00, 0xE8, 0x58, 0x02, 0x00, 0x5C, 0x58, 0x02, 0x00, 0x5C, 0x57, 0x02, 0x00, 0xDC, 0x58, 0x02, 0x00, 0xD4, 0x57, 0x02, 0x00, 0x94, 0x57, 0x02, 0x00, 0xFF, 0xB5, 0x0C, 0x46, 0x06, 0x46, 0xF7, 0xF7, 0x4C, 0x5A, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0xE3, 0xFE, 0x15, 0x49, 0x15, 0x4A, 0x0D, 0x68, 0x01, 0xA9, 0x92, 0xE8, 0x8C, 0x00, 0x81, 0xE8, 0x8C, 0x00, 0xF7, 0xF7, 0xFD, 0xFE, 0x01, 0x98, 0x11, 0x49, 0x28, 0x1A, 0x03, 0x9D, 0x25, 0x60, 0x02, 0x9A, 0x80, 0x18, 0x82, 0x42, 0x30, 0x60, 0x0E, 0xD8, 0x08, 0x46, 0x00, 0x68, 0x22, 0x68, 0x82, 0x42, 0x0E, 0xD2, 0x68, 0x46, 0xE8, 0xF7, 0xB9, 0xFF, 0x9D, 0xF8, 0x00, 0x00, 0x05, 0xF1, 0x01, 0x05, 0x30, 0xB9, 0x03, 0x95, 0x03, 0xE0, 0x25, 0x68, 0x6D, 0x1C, 0x25, 0x60, 0x0C, 0x46, 0x25, 0x60, 0x00, 0x20, 0x00, 0x90 , +0xFF, 0xBD, 0x60, 0x55, 0x30, 0x80, 0x24, 0x5D, 0x00, 0x20, 0x6C, 0x5D, 0x02, 0x00, 0x70, 0xB5, 0x4D, 0x00, 0x20, 0x2D, 0x4F, 0xF0, 0x00, 0x01, 0x0C, 0x46, 0x4F, 0xEA, 0x55, 0x13, 0x09, 0xD3, 0x50, 0xF8, 0x21, 0x60, 0xB6, 0xF1, 0xFF, 0x3F, 0x04, 0xD1, 0x49, 0x1C, 0xC9, 0xB2, 0x20, 0x3D, 0x5B, 0x1E, 0xF5, 0xD1, 0x4D, 0xB1, 0x20, 0x2D, 0x09, 0xD2, 0x01, 0x23, 0xAB, 0x40, 0x5B, 0x1E, 0x50, 0xF8, 0x21, 0x00, 0x18, 0x40, 0x83, 0x42, 0x01, 0xD1, 0x4F, 0xF0, 0x01, 0x04, 0x07, 0x48, 0x03, 0x78, 0x2C, 0xB9, 0x01, 0x21, 0x91, 0x40, 0xC9, 0x43, 0xC9, 0xB2, 0x0B, 0x40, 0x03, 0xE0, 0x01, 0x21, 0x91, 0x40, 0xC9, 0xB2, 0x0B, 0x43, 0x03, 0x70, 0x70, 0xBD, 0xC0, 0x46, 0xEE, 0x58, 0x02, 0x00, 0x14, 0x5B, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x7E, 0xB5, 0x05, 0x46, 0x95, 0xF8, 0x36, 0x20, 0x0E, 0x46, 0x0F, 0x49, 0x07, 0x2A, 0x12, 0xBF, 0x08, 0x68, 0x01, 0x20, 0x08, 0x60, 0x0D, 0x4C, 0x00, 0x92, 0x21, 0x68 , +0x41, 0xF2, 0x12, 0x13, 0x04, 0x22, 0x01, 0x91, 0x07, 0x21, 0x02, 0x90, 0x03, 0x20, 0xF2, 0xF7, 0x6B, 0xFD, 0x31, 0x46, 0x28, 0x46, 0xE7, 0xF7, 0x21, 0xFC, 0x21, 0x68, 0x00, 0x22, 0x05, 0x29, 0x02, 0xD1, 0x04, 0x49, 0x08, 0x31, 0x0A, 0x60, 0x7E, 0xBD, 0xC0, 0x46, 0x50, 0x57, 0x02, 0x00, 0x4C, 0x57, 0x02, 0x00, 0x00, 0x7C, 0x00, 0x20, 0x0E, 0x49, 0x09, 0x68, 0x49, 0x08, 0x15, 0xD2, 0x0D, 0x49, 0x09, 0x78, 0x91, 0xB1, 0x44, 0xF2, 0xE9, 0x21, 0x68, 0xB9, 0x0B, 0x48, 0x01, 0x78, 0x07, 0x48, 0x01, 0x29, 0x03, 0xD1, 0x0A, 0x49, 0x09, 0x78, 0x0E, 0x29, 0x02, 0xD0, 0x44, 0xF2, 0xDE, 0x21, 0x41, 0x60, 0x01, 0x21, 0x00, 0xE0, 0x06, 0x48, 0x01, 0x60, 0x70, 0x47, 0xC0, 0x46, 0x00, 0x97, 0x3C, 0x80, 0x10, 0x0C, 0x30, 0x80, 0xDD, 0x6A, 0x00, 0x20, 0xE0, 0x7C, 0x00, 0x20, 0xA6, 0x64, 0x00, 0x20, 0x04, 0x97, 0x3C, 0x80, 0x00, 0xB5, 0xAD, 0xF1, 0x18, 0x0D, 0x4F, 0xF0, 0x09, 0x00, 0x00, 0x90, 0x4F, 0xF4 , +0x0C, 0x60, 0x03, 0x90, 0x4F, 0xF0, 0x00, 0x00, 0x01, 0x90, 0x02, 0x90, 0x08, 0x48, 0x08, 0x49, 0x05, 0x90, 0x08, 0x68, 0x20, 0xB9, 0xDC, 0x5B, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x68, 0x46, 0x03, 0x22, 0xED, 0xF7, 0x3A, 0xFA, 0x03, 0xE0, 0x68, 0x46, 0x03, 0x22, 0xED, 0xF7, 0xC1, 0xFC, 0x06, 0xB0, 0x00, 0xBD, 0xC0, 0x46, 0x81, 0x5C, 0x02, 0x00, 0xDC, 0x7C, 0x00, 0x20, 0x1C, 0xB5, 0x0F, 0x4C, 0x22, 0x68, 0x01, 0x2A, 0x15, 0xD1, 0x0C, 0x48, 0x00, 0x68, 0x07, 0x28, 0x14, 0xBF, 0x40, 0x20, 0x4F, 0xF4, 0x05, 0x70, 0x63, 0x21, 0xF1, 0xF7, 0x0F, 0xFA, 0x20, 0x68, 0x00, 0x90, 0x43, 0xF2, 0x33, 0x33, 0x06, 0x21, 0x40, 0x20, 0x01, 0x90, 0x03, 0x20, 0x02, 0x46, 0xF2, 0xF7, 0xF4, 0xFC, 0x1C, 0xBD, 0xF1, 0xF7, 0x01, 0xFA, 0x1C, 0xBD, 0x4C, 0x57, 0x02, 0x00, 0x50, 0x57, 0x02, 0x00, 0x1E, 0xB5, 0x04, 0x46, 0x0A, 0x49, 0x00, 0x20, 0x0A, 0x4A, 0x08, 0x60, 0x0A, 0x49, 0x00, 0x90, 0x01, 0x90, 0x11, 0x60 , +0x09, 0x4A, 0x45, 0xF2, 0x55, 0x53, 0x02, 0x91, 0x10, 0x60, 0x07, 0x21, 0x04, 0x22, 0x03, 0x20, 0xF2, 0xF7, 0xD8, 0xFC, 0x20, 0x46, 0xE7, 0xF7, 0x59, 0xFD, 0x1E, 0xBD, 0x50, 0x57, 0x02, 0x00, 0x04, 0x74, 0x00, 0x20, 0x34, 0x12, 0x66, 0x09, 0x4C, 0x57, 0x02, 0x00, 0x00, 0xB5, 0x0B, 0x49, 0x00, 0x20, 0x08, 0x60, 0xE0, 0x20, 0xF7, 0xF7, 0xAA, 0xFD, 0x09, 0x49, 0x09, 0x78, 0x49, 0xB1, 0x08, 0x49, 0x0A, 0x78, 0x08, 0x49, 0x00, 0x2A, 0x06, 0xBF, 0x01, 0x22, 0x09, 0x1F, 0x44, 0xF2, 0xA4, 0x5C, 0x02, 0x00, 0xC8, 0x00, 0x00, 0x00, 0xE9, 0x22, 0x0A, 0x60, 0xF7, 0xF7, 0xA1, 0xFD, 0x00, 0xBD, 0xC0, 0x46, 0xDC, 0x7C, 0x00, 0x20, 0xDD, 0x6A, 0x00, 0x20, 0xA7, 0x64, 0x00, 0x20, 0x04, 0x97, 0x3C, 0x80, 0x50, 0xB9, 0x09, 0x48, 0x00, 0x78, 0x01, 0x28, 0x06, 0xD1, 0x08, 0x48, 0x00, 0x78, 0x0E, 0x28, 0x08, 0xBF, 0x44, 0xF2, 0xCB, 0x20, 0x01, 0xD0, 0x44, 0xF2, 0xDE, 0x20, 0x04, 0x49, 0x08, 0x60, 0x01, 0x20 , +0x41, 0xF8, 0x04, 0x0C, 0x70, 0x47, 0xE0, 0x7C, 0x00, 0x20, 0xA6, 0x64, 0x00, 0x20, 0x04, 0x97, 0x3C, 0x80, 0x30, 0xB5, 0x0D, 0x46, 0x84, 0x69, 0xDC, 0xF7, 0x97, 0xFB, 0x24, 0x1D, 0x01, 0x28, 0x04, 0xEB, 0x45, 0x01, 0x06, 0xD1, 0x89, 0x8E, 0x04, 0xEB, 0x85, 0x04, 0x11, 0xB9, 0x21, 0x69, 0x01, 0xB9, 0x00, 0x20, 0x30, 0xBD, 0x30, 0xB5, 0x05, 0x46, 0x5A, 0xB1, 0x03, 0xEB, 0x41, 0x03, 0x1C, 0x78, 0x59, 0x78, 0x41, 0xEA, 0x04, 0x11, 0x52, 0x1E, 0x03, 0xF1, 0x02, 0x03, 0x05, 0xF8, 0x01, 0x1B, 0xF5, 0xD1, 0x30, 0xBD, 0x00, 0xB5, 0x00, 0x20, 0xE7, 0xF7, 0xD6, 0xFE, 0x03, 0x48, 0x01, 0x68, 0x03, 0x29, 0x04, 0xBF, 0x04, 0x21, 0x01, 0x60, 0x00, 0xBD, 0xC0, 0x46, 0x4C, 0x57, 0x02, 0x00, 0x03, 0x4A, 0x12, 0x68, 0x01, 0x2A, 0x04, 0xBF, 0x02, 0x48, 0x63, 0x21, 0xF1, 0xF7, 0x76, 0xB9, 0x50, 0x57, 0x02, 0x00, 0x02, 0x20, 0x01, 0x00, 0x6C, 0x5D, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + +uint16_t fw_length = 5700; diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/ntpTest/ntpTest.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/ntpTest/ntpTest.ino new file mode 100755 index 0000000000..0be8585f15 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/examples/ntpTest/ntpTest.ino @@ -0,0 +1,217 @@ +/*************************************************** + This is an example for the Adafruit CC3000 Wifi Breakout & Shield + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Kevin Townsend & Limor Fried & Rick Lesniak for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +/* + +This example does a test of the SNTP (Simple Network Time Protocol) client: +* Initialization +* SSID Scan +* AP connection +* DHCP printout +* SNTP time synchronization +* Extract and print current time and date information + +*/ + +#include +#include +#include +//#include "utility/NetTime.h" +#include +#include "utility/debug.h" +#include "utility/sntp.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); // you can change this clock speed but DI + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + +//Arguments to SNTP client constructor: +// 1 - Primary Network Time Server URL (can be NULL) +// 2 - Secondary Network Time Server URL (also can be NULL) +// 3 - Local UTC offset in minutes (US Eastern Time is UTC - 5:00 +// 4 - Local UTC offset in minutes for Daylight Savings Time (US Eastern DST is UTC - 4:00 +// 5 - Enable Daylight Savings Time adjustment (not implemented yet) +// +sntp mysntp = sntp(NULL, "time.nist.gov", (short)(-5 * 60), (short)(-4 * 60), true); + +// Type SNTP_Timestamp is 64-bit NTP time. High-order 32-bits is seconds since 1/1/1900 +// Low order 32-bits is fractional seconds +SNTP_Timestamp_t now; + +// Type NetTime_t contains NTP time broken out to human-oriented values: +// uint16_t millis; ///< Milliseconds after the second (0..999) +// uint8_t sec; ///< Seconds after the minute (0..59) +// uint8_t min; ///< Minutes after the hour (0..59) +// uint8_t hour; ///< Hours since midnight (0..23) +// uint8_t mday; ///< Day of the month (1..31) +// uint8_t mon; ///< Months since January (0..11) +// uint16_t year; ///< Year. +// uint8_t wday; ///< Days since Sunday (0..6) +// uint8_t yday; ///< Days since January 1 (0..365) +// bool isdst; ///< Daylight savings time flag, currently not supported +NetTime_t timeExtract; + +#define pF(string_pointer) (reinterpret_cast(pgm_read_word(string_pointer))) + +const prog_char janStr[] PROGMEM = "January"; +const prog_char febStr[] PROGMEM = "February"; +const prog_char marStr[] PROGMEM = "March"; +const prog_char aprStr[] PROGMEM = "April"; +const prog_char mayStr[] PROGMEM = "May"; +const prog_char junStr[] PROGMEM = "June"; +const prog_char julStr[] PROGMEM = "July"; +const prog_char augStr[] PROGMEM = "August"; +const prog_char sepStr[] PROGMEM = "September"; +const prog_char octStr[] PROGMEM = "October"; +const prog_char novStr[] PROGMEM = "November"; +const prog_char decStr[] PROGMEM = "December"; + +PROGMEM const char* const monthStrs[] = { janStr, febStr, marStr, aprStr, mayStr, junStr, + julStr, augStr, sepStr, octStr, novStr, decStr}; + +const prog_char sunStr[] PROGMEM = "Sunday"; +const prog_char monStr[] PROGMEM = "Monday"; +const prog_char tueStr[] PROGMEM = "Tuesday"; +const prog_char wedStr[] PROGMEM = "Wednesday"; +const prog_char thuStr[] PROGMEM = "Thursday"; +const prog_char friStr[] PROGMEM = "Friday"; +const prog_char satStr[] PROGMEM = "Saturday"; + +PROGMEM const char* const dayStrs[] = { sunStr, monStr, tueStr, wedStr, + thuStr, friStr, satStr}; + + +/**************************************************************************/ +/*! + @brief Sets up the HW and the CC3000 module (called automatically + on startup) +*/ +/**************************************************************************/ +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); + + + /* Initialise the module */ + Serial.println(F("\nInitialising the CC3000 ...")); + if (!cc3000.begin()) + { + Serial.println(F("Unable to initialise the CC3000! Check your wiring?")); + while(1); + } + + /* Optional: Update the Mac Address to a known value */ +/* + uint8_t macAddress[6] = { 0x08, 0x00, 0x28, 0x01, 0x79, 0xB7 }; + if (!cc3000.setMacAddress(macAddress)) + { + Serial.println(F("Failed trying to update the MAC address")); + while(1); + } +*/ + + uint16_t firmware = checkFirmwareVersion(); + if (firmware < 0x113) { + Serial.println(F("Wrong firmware version!")); + for(;;); + } + + /* Delete any old connection data on the module */ + Serial.println(F("\nDeleting old connection profiles")); + if (!cc3000.deleteProfiles()) { + Serial.println(F("Failed!")); + while(1); + } + + /* Attempt to connect to an access point */ + char *ssid = WLAN_SSID; /* Max 32 chars */ + Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid); + + /* NOTE: Secure connections are not available in 'Tiny' mode! */ + if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + while(1); + } + + Serial.println(F("Connected!")); + + /* Wait for DHCP to complete */ + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) + { + delay(100); // ToDo: Insert a DHCP timeout! + } + + Serial.println(F("UpdateNTPTime")); + mysntp.UpdateNTPTime(); + + Serial.println(F("Current local time is:")); + mysntp.ExtractNTPTime(mysntp.NTPGetTime(&now, true), &timeExtract); + + Serial.print(timeExtract.hour); Serial.print(F(":")); Serial.print(timeExtract.min); Serial.print(F(":"));Serial.print(timeExtract.sec); Serial.print(F("."));Serial.println(timeExtract.millis); + Serial.print(pF(&dayStrs[timeExtract.wday])); Serial.print(F(", ")); Serial.print(pF(&monthStrs[timeExtract.mon])); Serial.print(F(" ")); Serial.print(timeExtract.mday); Serial.print(F(", "));Serial.println(timeExtract.year); + Serial.print(F("Day of year: ")); Serial.println(timeExtract.yday + 1); + + /* You need to make sure to clean up after yourself or the CC3000 can freak out */ + /* the next time you try to connect ... */ + Serial.println(F("\n\nClosing the connection")); + cc3000.disconnect(); +} + +void loop(void) +{ + delay(1000); +} + + +/**************************************************************************/ +/*! + @brief Tries to read the CC3000's internal firmware patch ID +*/ +/**************************************************************************/ +uint16_t checkFirmwareVersion(void) +{ + uint8_t major, minor; + uint16_t version; + +#ifndef CC3000_TINY_DRIVER + if(!cc3000.getFirmwareVersion(&major, &minor)) + { + Serial.println(F("Unable to retrieve the firmware version!\r\n")); + version = 0; + } + else + { + Serial.print(F("Firmware V. : ")); + Serial.print(major); Serial.print(F(".")); Serial.println(minor); + version = major; version <<= 8; version |= minor; + } +#endif + return version; +} + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/license.txt b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/license.txt new file mode 100755 index 0000000000..5496c03557 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/license.txt @@ -0,0 +1,20 @@ +===== + +Copyright (c) 2013-2014 +Limor Fried, Kevin Townsend for Adafruit Industries & Tony DiCola (tony@tonydicola.com) + +Adafruit invests time and resources providing this open source code, +please support Adafruit and open-source hardware by purchasing +products from Adafruit! + +All rights reserved. + +===== + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/Client_fastrprint/Client_fastrprint.ino b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/Client_fastrprint/Client_fastrprint.ino new file mode 100755 index 0000000000..caa59dfc76 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/Client_fastrprint/Client_fastrprint.ino @@ -0,0 +1,199 @@ +/*************************************************** + Client_fastrprint test + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Tony DiCola, based on code example code written by + Limor Fried & Kevin Townsend for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +#include +#include +#include +#include +#include "utility/debug.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIV2); // you can change this clock speed + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" + +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + +// Test server configuration +const uint8_t SERVER_IP[4] = { 192, 168, 1, 101 }; +const uint16_t SERVER_PORT = 9000; + +#define ASSERT_EQ(expected, actual) { \ + if (actual != expected) { \ + Serial.print("FAILURE: Expected "); \ + Serial.print(actual); \ + Serial.print(" to equal "); \ + Serial.println(expected); \ + } \ +} + +#define TEST_FASTRPRINT(message, client) { \ + Serial.print("Testing fastrprint with char* input: "); \ + Serial.println(message); \ + unsigned long n = client.fastrprint(message); \ + ASSERT_EQ(sizeof(message)-1, n); \ +} + +#define TEST_FASTRPRINTLN(message, client) { \ + Serial.print("Testing fastrprintln with char* input: "); \ + Serial.println(message); \ + unsigned long n = client.fastrprintln(message); \ + ASSERT_EQ(sizeof(message)+1, n); \ +} + +#define TEST_FASTRPRINT_F(message, client) { \ + Serial.print("Testing fastrprint with flash string input: "); \ + Serial.println(F(message)); \ + unsigned long n = client.fastrprint(F(message)); \ + ASSERT_EQ(sizeof(message)-1, n); \ +} + +#define TEST_FASTRPRINTLN_F(message, client) { \ + Serial.print("Testing fastrprintln with flash string input: "); \ + Serial.println(F(message)); \ + unsigned long n = client.fastrprintln(F(message)); \ + ASSERT_EQ(sizeof(message)+1, n); \ +} + +// Run the test +void runTest(void) { + // Make two connections to the server running listener.py + Serial.println(F("Connecting to server...")); + Adafruit_CC3000_Client client1 = cc3000.connectTCP(cc3000.IP2U32(SERVER_IP[0], SERVER_IP[1], SERVER_IP[2], SERVER_IP[3]), + SERVER_PORT); + if (!client1.connected()) { + Serial.println(F("Couldn't connect to server! Make sure listener.py is running on the server.")); + while(1); + } + Adafruit_CC3000_Client client2 = cc3000.connectTCP(cc3000.IP2U32(SERVER_IP[0], SERVER_IP[1], SERVER_IP[2], SERVER_IP[3]), + SERVER_PORT); + if (!client2.connected()) { + Serial.println(F("Couldn't connect to server! Make sure listener.py is running on the server.")); + while(1); + } + Serial.println(F("Connected!")); + + // Start the test + Serial.print(F("Free RAM: ")); Serial.println(getFreeRam(), DEC); + Serial.println(F("Starting tests...")); + unsigned long start = millis(); + + // Test character strings + TEST_FASTRPRINT("Fastrprint string.", client1); + TEST_FASTRPRINT("Fastrprint with a large (>32 character) character string!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", client1); + TEST_FASTRPRINTLN("Fastrprintln string.", client1); + TEST_FASTRPRINTLN("Fastrprintln with a large (>32 character) character string!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", client1); + + // Test flash strings + TEST_FASTRPRINT_F("Fastrprint flash.", client1); + TEST_FASTRPRINT_F("Fastrprint with a large (>32 character) flash string!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", client1); + TEST_FASTRPRINTLN_F("Fastrprintln flash.", client1); + TEST_FASTRPRINTLN_F("Fastrprintln with a large (>32 character) flash string!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", client1); + + // Test empty strings + TEST_FASTRPRINT("", client1); + TEST_FASTRPRINTLN("", client1); + TEST_FASTRPRINT_F("", client1); + TEST_FASTRPRINTLN_F("", client1); + + // Test printing to multiple clients + TEST_FASTRPRINT("This is a message for client 1.", client1); + TEST_FASTRPRINT("This is a message for client 2.", client2); + TEST_FASTRPRINT_F("This is a flash message for client 1.", client1); + TEST_FASTRPRINT_F("This is a flash message for client 2.", client2); + TEST_FASTRPRINT_F("This is a large (>32 character) flash message for client 1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", client1); + TEST_FASTRPRINT_F("This is a large (>32 character) flash message for client 2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", client2); + + unsigned long finish = millis(); + Serial.println(F("Tests finished!")); + Serial.print(F("Free RAM: ")); Serial.println(getFreeRam(), DEC); + Serial.print(F("Time taken to run test (MS): ")); Serial.println(finish - start, DEC); + + client1.close(); + client2.close(); + cc3000.disconnect(); +} + +// Set up the HW and the CC3000 module (called automatically on startup) +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + /* Initialise the module */ + Serial.println(F("\nInitializing...")); + if (!cc3000.begin()) + { + Serial.println(F("Couldn't begin()! Check your wiring?")); + while(1); + } + + if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + while(1); + } + + Serial.println(F("Connected!")); + + /* Wait for DHCP to complete */ + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) + { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (! displayConnectionDetails()) { + delay(1000); + } + + runTest(); +} + +void loop(void) +{ + delay(1000); +} + +// Tries to read the IP address and other connection details +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/README.md b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/README.md new file mode 100755 index 0000000000..5d3bdaeb40 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/README.md @@ -0,0 +1,27 @@ +Adafruit CC3000 Library Tests +============================= + +This folder is meant to contain tests that are written to verify the CC3000 library. Consumers +of the library probably want to ignore the contents of this folder. + +Files: +------ + +- listener.py + + Python script to run a TCP socket server which listens by default on port 9000 (but can be + changed by specifying a different port in the first command line parameter), accepts any + connections and echos all received data to standard output. This is required for running some + of the tests. In general you'll want to run listener.py with stdout directed to a file and then + run the test sketch on the CC3000 to capture what is output. Compare the output of test runs + before and after making a change/bugfix to the library and diff the results to ensure no + unexpected changes in functionality. + +Tests: +------ + +- Client\_fastrprint + + Manual test to verify the fastrprint and fastrprintln functions of the client library. Must + update the sketch to connect to your wireless network and set the SERVER_IP value to the IP + of a server running listener.py. \ No newline at end of file diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/listener.py b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/listener.py new file mode 100755 index 0000000000..5d0a5312ab --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/tests/listener.py @@ -0,0 +1,45 @@ +# Adafruit CC3000 Library Test Listener +# Created by Tony DiCola (tony@tonydicola.com) +# Released with the same license as the Adafruit CC3000 library (BSD) + +# Create a simple server to listen by default on port 9000 (or on the port specified in +# the first command line parameter), accept any connections and print all data received +# to standard output. Must be terminated by hitting ctrl-c to kill the process! + +from socket import * +import sys +import threading + +SERVER_PORT = 9000 +if len(sys.argv) > 1: + SERVER_PORT = sys.argv[1] + +# Create listening socket +server = socket(AF_INET, SOCK_STREAM) + +# Ignore waiting for the socket to close if it's already open. See the python socket +# doc for more info (very bottom of http://docs.python.org/2/library/socket.html). +server.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) + +# Listen on any network interface for the specified port +server.bind(('', SERVER_PORT)) +server.listen(5) + +# Worker process to print all data received to standard output. +def process_connection(client): + while True: + data = client.recv(1024) + sys.stdout.write(data) # Don't use print because it appends spaces and newlines + sys.stdout.flush() + if not data: + break + client.close() + +try: + # Wait for connections and spawn worker threads to process them. + while True: + client, address = server.accept() + thread = threading.Thread(target=process_connection, args=(client,)) + thread.start() +except: + server.close() \ No newline at end of file diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/cc3000_common.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/cc3000_common.cpp new file mode 100755 index 0000000000..e258b75214 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/cc3000_common.cpp @@ -0,0 +1,195 @@ +/***************************************************************************** +* +* cc3000_common.c.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +//***************************************************************************** +// +//! \addtogroup common_api +//! @{ +// +//***************************************************************************** +/****************************************************************************** + * + * Include files + * + *****************************************************************************/ +#include "cc3000_common.h" +#include "socket.h" +#include "wlan.h" +#include "evnt_handler.h" +#include "debug.h" +#include + +//***************************************************************************** +// +//! __error__ +//! +//! @param pcFilename - file name, where error occurred +//! @param ulLine - line number, where error occurred +//! +//! @return none +//! +//! @brief stub function for ASSERT macro +// +//***************************************************************************** +void +__error__(char *pcFilename, unsigned long ulLine) +{ + //TODO full up function +} + + + +//***************************************************************************** +// +//! UINT32_TO_STREAM_f +//! +//! @param p pointer to the new stream +//! @param u32 pointer to the 32 bit +//! +//! @return pointer to the new stream +//! +//! @brief This function is used for copying 32 bit to stream +//! while converting to little endian format. +// +//***************************************************************************** + +uint8_t* UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32) +{ + *(p)++ = (uint8_t)(u32); + *(p)++ = (uint8_t)((u32) >> 8); + *(p)++ = (uint8_t)((u32) >> 16); + *(p)++ = (uint8_t)((u32) >> 24); + return p; +} + +//***************************************************************************** +// +//! UINT16_TO_STREAM_f +//! +//! @param p pointer to the new stream +//! @param u32 pointer to the 16 bit +//! +//! @return pointer to the new stream +//! +//! @brief This function is used for copying 16 bit to stream +//! while converting to little endian format. +// +//***************************************************************************** + +uint8_t* UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16) +{ + *(p)++ = (uint8_t)(u16); + *(p)++ = (uint8_t)((u16) >> 8); + return p; +} + +//***************************************************************************** +// +//! STREAM_TO_UINT16_f +//! +//! @param p pointer to the stream +//! @param offset offset in the stream +//! +//! @return pointer to the new 16 bit +//! +//! @brief This function is used for copying received stream to +//! 16 bit in little endian format. +// +//***************************************************************************** + +uint16_t STREAM_TO_UINT16_f(char* cp, uint16_t offset) +{ + uint8_t *p = (uint8_t *)cp; + /* + DEBUGPRINT_F("Stream2u16: "); + DEBUGPRINT_HEX(cp[offset+1]); + DEBUGPRINT_F(" + "); + DEBUGPRINT_HEX(cp[offset]); + DEBUGPRINT_F("\n\r"); + */ + + return (uint16_t)((uint16_t) + ((uint16_t)(*(p + offset + 1)) << 8) + + (uint16_t)(*(p + offset))); +} + +//***************************************************************************** +// +//! STREAM_TO_UINT32_f +//! +//! @param p pointer to the stream +//! @param offset offset in the stream +//! +//! @return pointer to the new 32 bit +//! +//! @brief This function is used for copying received stream to +//! 32 bit in little endian format. +// +//***************************************************************************** + +uint32_t STREAM_TO_UINT32_f(char * cp, uint16_t offset) +{ + uint8_t *p = (uint8_t *)cp; + + /* + DEBUGPRINT_F("\tStream2u32: "); + DEBUGPRINT_HEX(cp[offset+3]); DEBUGPRINT_F(" + "); + DEBUGPRINT_HEX(cp[offset+2]); DEBUGPRINT_F(" + "); + DEBUGPRINT_HEX(cp[offset+1]); DEBUGPRINT_F(" + "); + DEBUGPRINT_HEX(cp[offset]); + DEBUGPRINT_F("\n\r"); + */ + + return (uint32_t)((uint32_t)((uint32_t) + (*(p + offset + 3)) << 24) + (uint32_t)((uint32_t) + (*(p + offset + 2)) << 16) + (uint32_t)((uint32_t) + (*(p + offset + 1)) << 8) + (uint32_t)(*(p + offset))); +} + + + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/cc3000_common.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/cc3000_common.h new file mode 100755 index 0000000000..9e71c0e628 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/cc3000_common.h @@ -0,0 +1,385 @@ +/***************************************************************************** +* +* cc3000_common.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef __COMMON_H__ +#define __COMMON_H__ + +//****************************************************************************** +// Include files +//****************************************************************************** +#include +#include +#include + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" { +#endif + +//***************************************************************************** +// ERROR CODES +//***************************************************************************** +#define ESUCCESS 0 +#define EFAIL -1 +#define EERROR EFAIL + +//***************************************************************************** +// COMMON DEFINES +//***************************************************************************** +#define ERROR_SOCKET_INACTIVE -57 + +#define WLAN_ENABLE (1) +#define WLAN_DISABLE (0) + +#define MAC_ADDR_LEN (6) + +#define SP_PORTION_SIZE (32) + +// #define CC3000_TINY_DRIVER + +/*Defines for minimal and maximal RX buffer size. This size includes the spi + header and hci header. + The maximal buffer size derives from: + MTU + HCI header + SPI header + sendto() agrs size + The minimum buffer size derives from: + HCI header + SPI header + max args size + + This buffer is used for receiving events and data. + The packet can not be longer than MTU size and CC3000 does not support + fragmentation. Note that the same buffer is used for reception of the data + and events from CC3000. That is why the minimum is defined. + The calculation for the actual size of buffer for reception is: + Given the maximal data size MAX_DATA that is expected to be received by + application, the required buffer is: + Using recv() or recvfrom(): + + max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen + + ucArgsize + 1) + + Using gethostbyname() with minimal buffer size will limit the host name + returned to 99 bytes only. + The 1 is used for the overrun detection + + Buffer size increased to 130 following the add_profile() with WEP security + which requires TX buffer size of 130 bytes: + HEADERS_SIZE_EVNT + WLAN_ADD_PROFILE_WEP_PARAM_LEN + MAX SSID LEN + 4 * MAX KEY LEN = 130 + MAX SSID LEN = 32 + MAX SSID LEN = 13 (with add_profile only ascii key setting is supported, + therfore maximum key size is 13) +*/ + +#define CC3000_MINIMAL_RX_SIZE (130 + 1) +#define CC3000_MAXIMAL_RX_SIZE (1519 + 1) + +/*Defines for minimal and maximal TX buffer size. + This buffer is used for sending events and data. + The packet can not be longer than MTU size and CC3000 does not support + fragmentation. Note that the same buffer is used for transmission of the data + and commands. That is why the minimum is defined. + The calculation for the actual size of buffer for transmission is: + Given the maximal data size MAX_DATA, the required buffer is: + Using Sendto(): + + max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE + + SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1) + + Using Send(): + + max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE + + HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1) + + The 1 is used for the overrun detection */ + +#define CC3000_MINIMAL_TX_SIZE (130 + 1) +#define CC3000_MAXIMAL_TX_SIZE (1519 + 1) + +//TX and RX buffer sizes, allow to receive and transmit maximum data at length 8. +#ifdef CC3000_TINY_DRIVER +#define TINY_CC3000_MAXIMAL_RX_SIZE 44 +#define TINY_CC3000_MAXIMAL_TX_SIZE 59 +#endif + +/*In order to determine your preferred buffer size, + change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between + the minimal and maximal specified above. + Note that the buffers are allocated by SPI. + In case you change the size of those buffers, you might need also to change + the linker file, since for example on MSP430 FRAM devices the buffers are + allocated in the FRAM section that is allocated manually and not by IDE. +*/ + +#ifndef CC3000_TINY_DRIVER + + #define CC3000_RX_BUFFER_SIZE (CC3000_MINIMAL_RX_SIZE) + #define CC3000_TX_BUFFER_SIZE (CC3000_MINIMAL_TX_SIZE) + +//if defined TINY DRIVER we use smaller RX and TX buffer in order to minimize RAM consumption +#else + #define CC3000_RX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_RX_SIZE) + #define CC3000_TX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_TX_SIZE) + +#endif + +//***************************************************************************** +// Compound Types +//***************************************************************************** +#ifdef __AVR__ +typedef unsigned long time_t; /* KTown: Updated to be compatible with Arduino Time.h */ +#else +typedef long time_t; +#endif +typedef unsigned long clock_t; +typedef long suseconds_t; + +typedef struct timeval timeval; + +struct timeval +{ + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* microseconds */ +}; + +typedef char *(*tFWPatches)(unsigned long *usLength); + +typedef char *(*tDriverPatches)(unsigned long *usLength); + +typedef char *(*tBootLoaderPatches)(unsigned long *usLength); + +typedef void (*tWlanCB)(long event_type, char * data, unsigned char length ); + +typedef long (*tWlanReadInteruptPin)(void); + +typedef void (*tWlanInterruptEnable)(void); + +typedef void (*tWlanInterruptDisable)(void); + +typedef void (*tWriteWlanPin)(unsigned char val); + +typedef struct +{ + unsigned short usRxEventOpcode; + unsigned short usEventOrDataReceived; + unsigned char *pucReceivedData; + unsigned char *pucTxCommandBuffer; + + tFWPatches sFWPatches; + tDriverPatches sDriverPatches; + tBootLoaderPatches sBootLoaderPatches; + tWlanCB sWlanCB; + tWlanReadInteruptPin ReadWlanInterruptPin; + tWlanInterruptEnable WlanInterruptEnable; + tWlanInterruptDisable WlanInterruptDisable; + tWriteWlanPin WriteWlanPin; + + signed long slTransmitDataError; + unsigned short usNumberOfFreeBuffers; + unsigned short usSlBufferLength; + unsigned short usBufferSize; + unsigned short usRxDataPending; + + unsigned long NumberOfSentPackets; + unsigned long NumberOfReleasedPackets; + + unsigned char InformHostOnTxComplete; +}sSimplLinkInformation; + +extern volatile sSimplLinkInformation tSLInformation; + + +//***************************************************************************** +// Prototypes for the APIs. +//***************************************************************************** + + + +//***************************************************************************** +// +//! SimpleLinkWaitEvent +//! +//! @param usOpcode command operation code +//! @param pRetParams command return parameters +//! +//! @return none +//! +//! @brief Wait for event, pass it to the hci_event_handler and +//! update the event opcode in a global variable. +// +//***************************************************************************** + +extern void SimpleLinkWaitEvent(unsigned short usOpcode, void *pRetParams); + +//***************************************************************************** +// +//! SimpleLinkWaitData +//! +//! @param pBuf data buffer +//! @param from from information +//! @param fromlen from information length +//! +//! @return none +//! +//! @brief Wait for data, pass it to the hci_event_handler +//! and update in a global variable that there is +//! data to read. +// +//***************************************************************************** + +extern void SimpleLinkWaitData(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen); + +//***************************************************************************** +// +//! UINT32_TO_STREAM_f +//! +//! \param p pointer to the new stream +//! \param u32 pointer to the 32 bit +//! +//! \return pointer to the new stream +//! +//! \brief This function is used for copying 32 bit to stream +//! while converting to little endian format. +// +//***************************************************************************** + +extern uint8_t* UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32); + +//***************************************************************************** +// +//! UINT16_TO_STREAM_f +//! +//! \param p pointer to the new stream +//! \param u32 pointer to the 16 bit +//! +//! \return pointer to the new stream +//! +//! \brief This function is used for copying 16 bit to stream +//! while converting to little endian format. +// +//***************************************************************************** + +extern uint8_t* UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16); + +//***************************************************************************** +// +//! STREAM_TO_UINT16_f +//! +//! \param p pointer to the stream +//! \param offset offset in the stream +//! +//! \return pointer to the new 16 bit +//! +//! \brief This function is used for copying received stream to +//! 16 bit in little endian format. +// +//***************************************************************************** + +extern uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset); + +//***************************************************************************** +// +//! STREAM_TO_UINT32_f +//! +//! \param p pointer to the stream +//! \param offset offset in the stream +//! +//! \return pointer to the new 32 bit +//! +//! \brief This function is used for copying received stream to +//! 32 bit in little endian format. +// +//***************************************************************************** + +extern uint32_t STREAM_TO_UINT32_f(char* p, uint16_t offset); + + +//***************************************************************************** +// +//! cc3k_int_poll +//! +//! \brief checks if the interrupt pin is low +//! just in case the hardware missed a falling edge +//! function is in ccspi.cpp +// +//***************************************************************************** + +extern void cc3k_int_poll(); + + + +//***************************************************************************** +// COMMON MACROs +//***************************************************************************** + + +//This macro is used for copying 8 bit to stream while converting to little endian format. +#define UINT8_TO_STREAM(_p, _val) {*(_p)++ = (_val);} +//This macro is used for copying 16 bit to stream while converting to little endian format. +#define UINT16_TO_STREAM(_p, _u16) (UINT16_TO_STREAM_f(_p, _u16)) +//This macro is used for copying 32 bit to stream while converting to little endian format. +#define UINT32_TO_STREAM(_p, _u32) (UINT32_TO_STREAM_f(_p, _u32)) +//This macro is used for copying a specified value length bits (l) to stream while converting to little endian format. +#define ARRAY_TO_STREAM(p, a, l) {register short _i; for (_i = 0; _i < l; _i++) *(p)++ = ((uint8_t *) a)[_i];} +//This macro is used for copying received stream to 8 bit in little endian format. +#define STREAM_TO_UINT8(_p, _offset, _u8) {_u8 = (uint8_t)(*(_p + _offset));} +//This macro is used for copying received stream to 16 bit in little endian format. +#define STREAM_TO_UINT16(_p, _offset, _u16) {_u16 = STREAM_TO_UINT16_f(_p, _offset);} +//This macro is used for copying received stream to 32 bit in little endian format. +#define STREAM_TO_UINT32(_p, _offset, _u32) {_u32 = STREAM_TO_UINT32_f(_p, _offset);} +#define STREAM_TO_STREAM(p, a, l) {register short _i; for (_i = 0; _i < l; _i++) *(a)++= ((uint8_t *) p)[_i];} + + + + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // __COMMON_H__ diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/debug.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/debug.cpp new file mode 100755 index 0000000000..4be46a2e15 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/debug.cpp @@ -0,0 +1,124 @@ +/**************************************************************************/ +/*! + @file Adafruit_CC3000.cpp + @author KTOWN (Kevin Townsend Adafruit Industries) + @license BSD (see license.txt) + + This is a library for the Adafruit CC3000 WiFi breakout board + This library works with the Adafruit CC3000 breakout + ----> https://www.adafruit.com/products/1469 + + Check out the links above for our tutorials and wiring diagrams + These chips use SPI to communicate. + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + @section HISTORY + + v1.0 - Initial release +*/ +/**************************************************************************/ + +#include "debug.h" + +/**************************************************************************/ +/*! + @brief This function will display the number of bytes currently free + in RAM ... useful for debugging! +*/ +/**************************************************************************/ + +#if defined (__arm__) && defined (__SAM3X8E__) // Arduino Due +// should use uinstd.h to define sbrk but on Arduino Due this causes a conflict +extern "C" char* sbrk(int incr); +int getFreeRam(void) { + char top; + return &top - reinterpret_cast(sbrk(0)); +} +#else // AVR +int getFreeRam(void) +{ + extern int __bss_end; + extern int *__brkval; + int free_memory; + if((int)__brkval == 0) { + free_memory = ((int)&free_memory) - ((int)&__bss_end); + } + else { + free_memory = ((int)&free_memory) - ((int)__brkval); + } + + return free_memory; +} +#endif + +void displayFreeRam(void) +{ + if (CC3KPrinter == 0) { + return; + } + CC3KPrinter->print(F("Free RAM: ")); + CC3KPrinter->print(getFreeRam()); + CC3KPrinter->println(F(" bytes")); +} + +void uart_putchar(char c) { + if (CC3KPrinter != 0) { + CC3KPrinter->write(c); + } +} + +void printDec(uint8_t h) { + uart_putchar((h / 100) + '0'); + h %= 100; + uart_putchar((h / 10) + '0'); + h %= 10; + uart_putchar(h + '0'); +} + + +void printHex(uint8_t h) { + uint8_t d = h >> 4; + if (d >= 10) { + uart_putchar(d - 10 + 'A'); + } else { + uart_putchar(d + '0'); + } + h &= 0xF; + if (h >= 10) { + uart_putchar(h - 10 + 'A'); + } else { + uart_putchar(h + '0'); + } +} + +void printHex16(uint16_t h) { + uart_putchar('0'); + uart_putchar('x'); + DEBUGPRINT_HEX(h >> 8); + DEBUGPRINT_HEX(h); +} + + +void printDec16(uint16_t h) { + uart_putchar((h / 10000) + '0'); + h %= 10000; + uart_putchar((h / 1000) + '0'); + h %= 1000; + uart_putchar((h / 100) + '0'); + h %= 100; + uart_putchar((h / 10) + '0'); + h %= 10; + uart_putchar(h + '0'); +} + + +void DEBUGPRINT(const prog_char *fstr) +{ + char c; + if(!fstr) return; + while((c = pgm_read_byte(fstr++))) + uart_putchar(c); +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/debug.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/debug.h new file mode 100755 index 0000000000..18ac19fc03 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/debug.h @@ -0,0 +1,67 @@ +/**************************************************************************/ +/*! + @file Adafruit_CC3000.cpp + @author KTOWN (Kevin Townsend for Adafruit Industries) + @license BSD (see license.txt) + + This is a library for the Adafruit CC3000 WiFi breakout board + This library works with the Adafruit CC3000 breakout + ----> https://www.adafruit.com/products/1469 + + Check out the links above for our tutorials and wiring diagrams + These chips use SPI to communicate. + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + @section HISTORY + + v1.0 - Initial release +*/ +/**************************************************************************/ + +#include + +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +#if (GCC_VERSION >= 40702) || !defined(prog_char) +typedef char PROGMEM prog_char; +#endif + +#ifndef _CC3000_DEBUG +#define _CC3000_DEBUG + +#define DEBUG_MODE (0) + +int getFreeRam(void); +void displayFreeRam(void); +void uart_putchar(char c); +void printHex(uint8_t h); +void printHex16(uint16_t h); +void DEBUGPRINT(const prog_char *fstr); +void printDec(uint8_t h); +void printDec16(uint16_t h); + +#ifndef FLASHIFY +#define FLASHIFY(s) ({static const char c[] __attribute__ ((progmem)) = s;c;}) +#endif + +#define PRINT_F(__s) DEBUGPRINT(FLASHIFY(__s)) + +#if (DEBUG_MODE != 0) +#define DEBUGPRINT_F(__s) DEBUGPRINT(FLASHIFY(__s)) +#define DEBUGPRINT_DEC(x) printDec(x) +#define DEBUGPRINT_DEC16(x) printDec16(x) +#define DEBUGPRINT_HEX(x) printHex(x) +#define DEBUGPRINT_HEX16(x) printHex16(x) +#else +#define DEBUGPRINT_F(__s) /* do nothing! */ +#define DEBUGPRINT_DEC(x) +#define DEBUGPRINT_DEC16(x) +#define DEBUGPRINT_HEX(x) +#define DEBUGPRINT_HEX16(x) +#endif + +extern Print* CC3KPrinter; + +#endif diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/evnt_handler.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/evnt_handler.cpp new file mode 100755 index 0000000000..0305571e5d --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/evnt_handler.cpp @@ -0,0 +1,871 @@ +/***************************************************************************** +* +* evnt_handler.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +//***************************************************************************** +// +//! \addtogroup evnt_handler_api +//! @{ +// +//****************************************************************************** + +//****************************************************************************** +// INCLUDE FILES +//****************************************************************************** + +#include "cc3000_common.h" +#include "string.h" +#include "hci.h" +#include "evnt_handler.h" +#include "wlan.h" +#include "socket.h" +#include "netapp.h" +#include "../ccspi.h" +#include "debug.h" + + + +//***************************************************************************** +// COMMON DEFINES +//***************************************************************************** + +#define FLOW_CONTROL_EVENT_HANDLE_OFFSET (0) +#define FLOW_CONTROL_EVENT_BLOCK_MODE_OFFSET (1) +#define FLOW_CONTROL_EVENT_FREE_BUFFS_OFFSET (2) +#define FLOW_CONTROL_EVENT_SIZE (4) + +#define BSD_RSP_PARAMS_SOCKET_OFFSET (0) +#define BSD_RSP_PARAMS_STATUS_OFFSET (4) + +#define GET_HOST_BY_NAME_RETVAL_OFFSET (0) +#define GET_HOST_BY_NAME_ADDR_OFFSET (4) + +#define ACCEPT_SD_OFFSET (0) +#define ACCEPT_RETURN_STATUS_OFFSET (4) +#define ACCEPT_ADDRESS__OFFSET (8) + +#define SL_RECEIVE_SD_OFFSET (0) +#define SL_RECEIVE_NUM_BYTES_OFFSET (4) +#define SL_RECEIVE__FLAGS__OFFSET (8) + + +#define SELECT_STATUS_OFFSET (0) +#define SELECT_READFD_OFFSET (4) +#define SELECT_WRITEFD_OFFSET (8) +#define SELECT_EXFD_OFFSET (12) + + +#define NETAPP_IPCONFIG_IP_OFFSET (0) +#define NETAPP_IPCONFIG_SUBNET_OFFSET (4) +#define NETAPP_IPCONFIG_GW_OFFSET (8) +#define NETAPP_IPCONFIG_DHCP_OFFSET (12) +#define NETAPP_IPCONFIG_DNS_OFFSET (16) +#define NETAPP_IPCONFIG_MAC_OFFSET (20) +#define NETAPP_IPCONFIG_SSID_OFFSET (26) + +#define NETAPP_IPCONFIG_IP_LENGTH (4) +#define NETAPP_IPCONFIG_MAC_LENGTH (6) +#define NETAPP_IPCONFIG_SSID_LENGTH (32) + + +#define NETAPP_PING_PACKETS_SENT_OFFSET (0) +#define NETAPP_PING_PACKETS_RCVD_OFFSET (4) +#define NETAPP_PING_MIN_RTT_OFFSET (8) +#define NETAPP_PING_MAX_RTT_OFFSET (12) +#define NETAPP_PING_AVG_RTT_OFFSET (16) + +#define GET_SCAN_RESULTS_TABlE_COUNT_OFFSET (0) +#define GET_SCAN_RESULTS_SCANRESULT_STATUS_OFFSET (4) +#define GET_SCAN_RESULTS_ISVALID_TO_SSIDLEN_OFFSET (8) +#define GET_SCAN_RESULTS_FRAME_TIME_OFFSET (10) +#define GET_SCAN_RESULTS_SSID_MAC_LENGTH (38) + + + +//***************************************************************************** +// GLOBAL VARAIABLES +//***************************************************************************** + +unsigned long socket_active_status = SOCKET_STATUS_INIT_VAL; + + +//***************************************************************************** +// Prototypes for the static functions +//***************************************************************************** + +static long hci_event_unsol_flowcontrol_handler(char *pEvent); + +static void update_socket_active_status(char *resp_params); + + +//***************************************************************************** +// +//! hci_unsol_handle_patch_request +//! +//! @param event_hdr event header +//! +//! @return none +//! +//! @brief Handle unsolicited event from type patch request +// +//***************************************************************************** +void hci_unsol_handle_patch_request(char *event_hdr) +{ + char *params = (char *)(event_hdr) + HCI_EVENT_HEADER_SIZE; + unsigned long ucLength = 0; + char *patch; + + switch (*params) + { + case HCI_EVENT_PATCHES_DRV_REQ: + + if (tSLInformation.sDriverPatches) + { + patch = tSLInformation.sDriverPatches(&ucLength); + + if (patch) + { + hci_patch_send(HCI_EVENT_PATCHES_DRV_REQ, + tSLInformation.pucTxCommandBuffer, patch, ucLength); + return; + } + } + + // Send 0 length Patches response event + hci_patch_send(HCI_EVENT_PATCHES_DRV_REQ, + tSLInformation.pucTxCommandBuffer, 0, 0); + break; + + case HCI_EVENT_PATCHES_FW_REQ: + + if (tSLInformation.sFWPatches) + { + patch = tSLInformation.sFWPatches(&ucLength); + + // Build and send a patch + if (patch) + { + hci_patch_send(HCI_EVENT_PATCHES_FW_REQ, + tSLInformation.pucTxCommandBuffer, patch, ucLength); + return; + } + } + + // Send 0 length Patches response event + hci_patch_send(HCI_EVENT_PATCHES_FW_REQ, + tSLInformation.pucTxCommandBuffer, 0, 0); + break; + + case HCI_EVENT_PATCHES_BOOTLOAD_REQ: + + if (tSLInformation.sBootLoaderPatches) + { + patch = tSLInformation.sBootLoaderPatches(&ucLength); + + if (patch) + { + hci_patch_send(HCI_EVENT_PATCHES_BOOTLOAD_REQ, + tSLInformation.pucTxCommandBuffer, patch, ucLength); + return; + } + } + + // Send 0 length Patches response event + hci_patch_send(HCI_EVENT_PATCHES_BOOTLOAD_REQ, + tSLInformation.pucTxCommandBuffer, 0, 0); + break; + } +} + + + +//***************************************************************************** +// +//! hci_event_handler +//! +//! @param pRetParams incoming data buffer +//! @param from from information (in case of data received) +//! @param fromlen from information length (in case of data received) +//! +//! @return none +//! +//! @brief Parse the incoming events packets and issues corresponding +//! event handler from global array of handlers pointers +// +//***************************************************************************** + + +unsigned char * +hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen) +{ + unsigned char *pucReceivedData, ucArgsize; + unsigned short usLength; + unsigned char *pucReceivedParams; + unsigned short usReceivedEventOpcode = 0; + unsigned long retValue32; + unsigned char * RecvParams; + unsigned char *RetParams; + + while (1) + { + cc3k_int_poll(); + + if (tSLInformation.usEventOrDataReceived != 0) + { + + pucReceivedData = (tSLInformation.pucReceivedData); + + if (*pucReceivedData == HCI_TYPE_EVNT) + { + // Event Received + STREAM_TO_UINT16((char *)pucReceivedData, + HCI_EVENT_OPCODE_OFFSET, + usReceivedEventOpcode); + pucReceivedParams = pucReceivedData + HCI_EVENT_HEADER_SIZE; + RecvParams = pucReceivedParams; + RetParams = (unsigned char *)pRetParams; + + // In case unsolicited event received - here the handling finished + if (hci_unsol_event_handler((char *)pucReceivedData) == 0) + { + STREAM_TO_UINT8(pucReceivedData, HCI_DATA_LENGTH_OFFSET, usLength); + + switch(usReceivedEventOpcode) + { + case HCI_CMND_READ_BUFFER_SIZE: + { + STREAM_TO_UINT8((char *)pucReceivedParams, 0, + tSLInformation.usNumberOfFreeBuffers); + STREAM_TO_UINT16((char *)pucReceivedParams, 1, + tSLInformation.usSlBufferLength); + } + break; + + case HCI_CMND_WLAN_CONFIGURE_PATCH: + case HCI_NETAPP_DHCP: + case HCI_NETAPP_PING_SEND: + case HCI_NETAPP_PING_STOP: + case HCI_NETAPP_ARP_FLUSH: + case HCI_NETAPP_SET_DEBUG_LEVEL: + case HCI_NETAPP_SET_TIMERS: + case HCI_EVNT_NVMEM_READ: + case HCI_EVNT_NVMEM_CREATE_ENTRY: + case HCI_CMND_NVMEM_WRITE_PATCH: + case HCI_NETAPP_PING_REPORT: + case HCI_EVNT_MDNS_ADVERTISE: + + STREAM_TO_UINT8(pucReceivedData, HCI_EVENT_STATUS_OFFSET + ,*(unsigned char *)pRetParams); + break; + + case HCI_CMND_SETSOCKOPT: + case HCI_CMND_WLAN_CONNECT: + case HCI_CMND_WLAN_IOCTL_STATUSGET: + case HCI_EVNT_WLAN_IOCTL_ADD_PROFILE: + case HCI_CMND_WLAN_IOCTL_DEL_PROFILE: + case HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY: + case HCI_CMND_WLAN_IOCTL_SET_SCANPARAM: + case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START: + case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP: + case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX: + case HCI_CMND_EVENT_MASK: + case HCI_EVNT_WLAN_DISCONNECT: + case HCI_EVNT_SOCKET: + case HCI_EVNT_BIND: + case HCI_CMND_LISTEN: + case HCI_EVNT_CLOSE_SOCKET: + case HCI_EVNT_CONNECT: + case HCI_EVNT_NVMEM_WRITE: + + STREAM_TO_UINT32((char *)pucReceivedParams,0 + ,*(unsigned long *)pRetParams); + break; + + case HCI_EVNT_READ_SP_VERSION: + + STREAM_TO_UINT8(pucReceivedData, HCI_EVENT_STATUS_OFFSET + ,*(unsigned char *)pRetParams); + pRetParams = ((char *)pRetParams) + 1; + STREAM_TO_UINT32((char *)pucReceivedParams, 0, retValue32); + UINT32_TO_STREAM((unsigned char *)pRetParams, retValue32); + break; + + case HCI_EVNT_BSD_GETHOSTBYNAME: + + STREAM_TO_UINT32((char *)pucReceivedParams + ,GET_HOST_BY_NAME_RETVAL_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams + ,GET_HOST_BY_NAME_ADDR_OFFSET,*(unsigned long *)pRetParams); + break; + + case HCI_EVNT_ACCEPT: + { + STREAM_TO_UINT32((char *)pucReceivedParams,ACCEPT_SD_OFFSET + ,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams + ,ACCEPT_RETURN_STATUS_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + + //This argument returns in network order + memcpy((unsigned char *)pRetParams, + pucReceivedParams + ACCEPT_ADDRESS__OFFSET, sizeof(sockaddr)); + break; + } + + case HCI_EVNT_RECV: + case HCI_EVNT_RECVFROM: + { + STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE__FLAGS__OFFSET,*(unsigned long *)pRetParams); + tBsdReadReturnParams *tread = (tBsdReadReturnParams *)pRetParams; + if(((tBsdReadReturnParams *)pRetParams)->iNumberOfBytes == ERROR_SOCKET_INACTIVE) + { + set_socket_active_status(((tBsdReadReturnParams *)pRetParams)->iSocketDescriptor,SOCKET_STATUS_INACTIVE); + } + break; + } + + case HCI_EVNT_SEND: + case HCI_EVNT_SENDTO: + { + STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + + break; + } + + case HCI_EVNT_SELECT: + { + STREAM_TO_UINT32((char *)pucReceivedParams,SELECT_STATUS_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams,SELECT_READFD_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams,SELECT_WRITEFD_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams,SELECT_EXFD_OFFSET,*(unsigned long *)pRetParams); + break; + } + + case HCI_CMND_GETSOCKOPT: + + STREAM_TO_UINT8(pucReceivedData, HCI_EVENT_STATUS_OFFSET,((tBsdGetSockOptReturnParams *)pRetParams)->iStatus); + //This argument returns in network order + memcpy((unsigned char *)pRetParams, pucReceivedParams, 4); + break; + + case HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS: + + STREAM_TO_UINT32((char *)pucReceivedParams,GET_SCAN_RESULTS_TABlE_COUNT_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT32((char *)pucReceivedParams,GET_SCAN_RESULTS_SCANRESULT_STATUS_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 4; + STREAM_TO_UINT16((char *)pucReceivedParams,GET_SCAN_RESULTS_ISVALID_TO_SSIDLEN_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 2; + STREAM_TO_UINT16((char *)pucReceivedParams,GET_SCAN_RESULTS_FRAME_TIME_OFFSET,*(unsigned long *)pRetParams); + pRetParams = ((char *)pRetParams) + 2; + memcpy((unsigned char *)pRetParams, (char *)(pucReceivedParams + GET_SCAN_RESULTS_FRAME_TIME_OFFSET + 2), GET_SCAN_RESULTS_SSID_MAC_LENGTH); + break; + + case HCI_CMND_SIMPLE_LINK_START: + break; + + case HCI_NETAPP_IPCONFIG: + + //Read IP address + STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + RecvParams += 4; + + //Read subnet + STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + RecvParams += 4; + + //Read default GW + STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + RecvParams += 4; + + //Read DHCP server + STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + RecvParams += 4; + + //Read DNS server + STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH); + RecvParams += 4; + + //Read Mac address + STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_MAC_LENGTH); + RecvParams += 6; + + //Read SSID + STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_SSID_LENGTH); + + } + } + + if (usReceivedEventOpcode == tSLInformation.usRxEventOpcode) + { + tSLInformation.usRxEventOpcode = 0; + } + } + else + { + pucReceivedParams = pucReceivedData; + STREAM_TO_UINT8((char *)pucReceivedData, HCI_PACKET_ARGSIZE_OFFSET, ucArgsize); + + STREAM_TO_UINT16((char *)pucReceivedData, HCI_PACKET_LENGTH_OFFSET, usLength); + + // Data received: note that the only case where from and from length + // are not null is in recv from, so fill the args accordingly + if (from) + { + STREAM_TO_UINT32((char *)(pucReceivedData + HCI_DATA_HEADER_SIZE), BSD_RECV_FROM_FROMLEN_OFFSET, *(unsigned long *)fromlen); + memcpy(from, (pucReceivedData + HCI_DATA_HEADER_SIZE + BSD_RECV_FROM_FROM_OFFSET) ,*fromlen); + } + + memcpy(pRetParams, pucReceivedParams + HCI_DATA_HEADER_SIZE + ucArgsize, + usLength - ucArgsize); + + tSLInformation.usRxDataPending = 0; + } + + tSLInformation.usEventOrDataReceived = 0; + + SpiResumeSpi(); + + // Since we are going to TX - we need to handle this event after the + // ResumeSPi since we need interrupts + if ((*pucReceivedData == HCI_TYPE_EVNT) && + (usReceivedEventOpcode == HCI_EVNT_PATCHES_REQ)) + { + hci_unsol_handle_patch_request((char *)pucReceivedData); + } + + if ((tSLInformation.usRxEventOpcode == 0) && (tSLInformation.usRxDataPending == 0)) + { + return NULL; + } + } + } + +} + +//***************************************************************************** +// +//! hci_unsol_event_handler +//! +//! @param event_hdr event header +//! +//! @return 1 if event supported and handled +//! 0 if event is not supported +//! +//! @brief Handle unsolicited events +// +//***************************************************************************** +long +hci_unsol_event_handler(char *event_hdr) +{ + char * data = NULL; + long event_type; + unsigned long NumberOfReleasedPackets; + unsigned long NumberOfSentPackets; + + STREAM_TO_UINT16(event_hdr, HCI_EVENT_OPCODE_OFFSET,event_type); + + DEBUGPRINT_F("\tHCI_UNSOL_EVT: "); + DEBUGPRINT_HEX16(event_type); + + if (event_type & HCI_EVNT_UNSOL_BASE) + { + switch(event_type) + { + + case HCI_EVNT_DATA_UNSOL_FREE_BUFF: + { + hci_event_unsol_flowcontrol_handler(event_hdr); + + NumberOfReleasedPackets = tSLInformation.NumberOfReleasedPackets; + NumberOfSentPackets = tSLInformation.NumberOfSentPackets; + + if (NumberOfReleasedPackets == NumberOfSentPackets) + { + if (tSLInformation.InformHostOnTxComplete) + { + tSLInformation.sWlanCB(HCI_EVENT_CC3000_CAN_SHUT_DOWN, NULL, 0); + } + } + return 1; + + } + } + } + + if(event_type & HCI_EVNT_WLAN_UNSOL_BASE) + { + switch(event_type) + { + case HCI_EVNT_WLAN_KEEPALIVE: + case HCI_EVNT_WLAN_UNSOL_CONNECT: + case HCI_EVNT_WLAN_UNSOL_DISCONNECT: + case HCI_EVNT_WLAN_UNSOL_INIT: + case HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE: + + if( tSLInformation.sWlanCB ) + { + tSLInformation.sWlanCB(event_type, 0, 0); + } + break; + + case HCI_EVNT_WLAN_UNSOL_DHCP: + { + unsigned char params[NETAPP_IPCONFIG_MAC_OFFSET + 1]; // extra byte is for the status + unsigned char *recParams = params; + + data = (char*)(event_hdr) + HCI_EVENT_HEADER_SIZE; + + //Read IP address + STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + data += 4; + //Read subnet + STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + data += 4; + //Read default GW + STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + data += 4; + //Read DHCP server + STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + data += 4; + //Read DNS server + STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH); + // read the status + STREAM_TO_UINT8(event_hdr, HCI_EVENT_STATUS_OFFSET, *recParams); + + + if( tSLInformation.sWlanCB ) + { + tSLInformation.sWlanCB(event_type, (char *)params, sizeof(params)); + } + } + break; + + case HCI_EVNT_WLAN_ASYNC_PING_REPORT: + { + netapp_pingreport_args_t params; + data = (char*)(event_hdr) + HCI_EVENT_HEADER_SIZE; + STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_SENT_OFFSET, params.packets_sent); + STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_RCVD_OFFSET, params.packets_received); + STREAM_TO_UINT32(data, NETAPP_PING_MIN_RTT_OFFSET, params.min_round_time); + STREAM_TO_UINT32(data, NETAPP_PING_MAX_RTT_OFFSET, params.max_round_time); + STREAM_TO_UINT32(data, NETAPP_PING_AVG_RTT_OFFSET, params.avg_round_time); + + if( tSLInformation.sWlanCB ) + { + tSLInformation.sWlanCB(event_type, (char *)¶ms, sizeof(params)); + } + } + break; + case HCI_EVNT_BSD_TCP_CLOSE_WAIT: + { + DEBUGPRINT_F("\tTCP Close Wait\n\r"); + uint8_t socketnum; + data = (char*)(event_hdr) + HCI_EVENT_HEADER_SIZE; + /* + printHex(data[0]); PRINT_F("\t"); + printHex(data[1]); PRINT_F("\t"); + printHex(data[2]); PRINT_F("\t"); + printHex(data[3]); PRINT_F("\t"); + printHex(data[4]); PRINT_F("\t"); + printHex(data[5]); PRINT_F("\t"); + */ + socketnum = data[0]; + //STREAM_TO_UINT16(data, 0, socketnum); + if( tSLInformation.sWlanCB ) + { + tSLInformation.sWlanCB(event_type, (char *)&socketnum, 1); + } + } + break; + + //'default' case which means "event not supported" + default: + return (0); + } + return(1); + } + + if ((event_type == HCI_EVNT_SEND) || (event_type == HCI_EVNT_SENDTO) + || (event_type == HCI_EVNT_WRITE)) + { + char *pArg; + long status; + + DEBUGPRINT_F("\tSEND event response\n\r"); + + pArg = M_BSD_RESP_PARAMS_OFFSET(event_hdr); + STREAM_TO_UINT32(pArg, BSD_RSP_PARAMS_STATUS_OFFSET,status); + + if (ERROR_SOCKET_INACTIVE == status) + { + // The only synchronous event that can come from SL device in form of + // command complete is "Command Complete" on data sent, in case SL device + // was unable to transmit + STREAM_TO_UINT8(event_hdr, HCI_EVENT_STATUS_OFFSET, tSLInformation.slTransmitDataError); + update_socket_active_status(M_BSD_RESP_PARAMS_OFFSET(event_hdr)); + + return (1); + } + else + return (0); + } + + return(0); +} + +//***************************************************************************** +// +//! hci_unsolicited_event_handler +//! +//! @param None +//! +//! @return ESUCCESS if successful, EFAIL if an error occurred +//! +//! @brief Parse the incoming unsolicited event packets and issues +//! corresponding event handler. +// +//***************************************************************************** +long +hci_unsolicited_event_handler(void) +{ + unsigned long res = 0; + unsigned char *pucReceivedData; + + if (tSLInformation.usEventOrDataReceived != 0) + { + pucReceivedData = (tSLInformation.pucReceivedData); + + if (*pucReceivedData == HCI_TYPE_EVNT) + { + + // In case unsolicited event received - here the handling finished + if (hci_unsol_event_handler((char *)pucReceivedData) == 1) + { + + // There was an unsolicited event received - we can release the buffer + // and clean the event received + tSLInformation.usEventOrDataReceived = 0; + + res = 1; + SpiResumeSpi(); + } + } + } + + return res; +} + +//***************************************************************************** +// +//! set_socket_active_status +//! +//! @param Sd +//! @param Status +//! @return none +//! +//! @brief Check if the socket ID and status are valid and set +//! accordingly the global socket status +// +//***************************************************************************** +void set_socket_active_status(long Sd, long Status) +{ + if(M_IS_VALID_SD(Sd) && M_IS_VALID_STATUS(Status)) + { + socket_active_status &= ~(1 << Sd); /* clean socket's mask */ + socket_active_status |= (Status << Sd); /* set new socket's mask */ + } +} + + +//***************************************************************************** +// +//! hci_event_unsol_flowcontrol_handler +//! +//! @param pEvent pointer to the string contains parameters for IPERF +//! @return ESUCCESS if successful, EFAIL if an error occurred +//! +//! @brief Called in case unsolicited event from type +//! HCI_EVNT_DATA_UNSOL_FREE_BUFF has received. +//! Keep track on the number of packets transmitted and update the +//! number of free buffer in the SL device. +// +//***************************************************************************** +long +hci_event_unsol_flowcontrol_handler(char *pEvent) +{ + + long temp, value; + unsigned short i; + unsigned short pusNumberOfHandles=0; + char *pReadPayload; + + STREAM_TO_UINT16((char *)pEvent,HCI_EVENT_HEADER_SIZE,pusNumberOfHandles); + pReadPayload = ((char *)pEvent + + HCI_EVENT_HEADER_SIZE + sizeof(pusNumberOfHandles)); + temp = 0; + + for(i = 0; i < pusNumberOfHandles ; i++) + { + STREAM_TO_UINT16(pReadPayload, FLOW_CONTROL_EVENT_FREE_BUFFS_OFFSET, value); + temp += value; + pReadPayload += FLOW_CONTROL_EVENT_SIZE; + } + + tSLInformation.usNumberOfFreeBuffers += temp; + tSLInformation.NumberOfReleasedPackets += temp; + + return(ESUCCESS); +} + +//***************************************************************************** +// +//! get_socket_active_status +//! +//! @param Sd Socket IS +//! @return Current status of the socket. +//! +//! @brief Retrieve socket status +// +//***************************************************************************** + +long +get_socket_active_status(long Sd) +{ + if(M_IS_VALID_SD(Sd)) + { + return (socket_active_status & (1 << Sd)) ? SOCKET_STATUS_INACTIVE : SOCKET_STATUS_ACTIVE; + } + return SOCKET_STATUS_INACTIVE; +} + +//***************************************************************************** +// +//! update_socket_active_status +//! +//! @param resp_params Socket IS +//! @return Current status of the socket. +//! +//! @brief Retrieve socket status +// +//***************************************************************************** +void +update_socket_active_status(char *resp_params) +{ + long status, sd; + + STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_SOCKET_OFFSET,sd); + STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_STATUS_OFFSET,status); + + if(ERROR_SOCKET_INACTIVE == status) + { + set_socket_active_status(sd, SOCKET_STATUS_INACTIVE); + } +} + + +//***************************************************************************** +// +//! SimpleLinkWaitEvent +//! +//! @param usOpcode command operation code +//! @param pRetParams command return parameters +//! +//! @return none +//! +//! @brief Wait for event, pass it to the hci_event_handler and +//! update the event opcode in a global variable. +// +//***************************************************************************** + +void +SimpleLinkWaitEvent(unsigned short usOpcode, void *pRetParams) +{ + // In the blocking implementation the control to caller will be returned only + // after the end of current transaction + tSLInformation.usRxEventOpcode = usOpcode; + hci_event_handler(pRetParams, 0, 0); +} + +//***************************************************************************** +// +//! SimpleLinkWaitData +//! +//! @param pBuf data buffer +//! @param from from information +//! @param fromlen from information length +//! +//! @return none +//! +//! @brief Wait for data, pass it to the hci_event_handler +//! and update in a global variable that there is +//! data to read. +// +//***************************************************************************** + +void +SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, + unsigned char *fromlen) +{ + // In the blocking implementation the control to caller will be returned only + // after the end of current transaction, i.e. only after data will be received + tSLInformation.usRxDataPending = 1; + hci_event_handler(pBuf, from, fromlen); +} + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/evnt_handler.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/evnt_handler.h new file mode 100755 index 0000000000..1391752bd8 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/evnt_handler.h @@ -0,0 +1,175 @@ +/***************************************************************************** +* +* evnt_handler.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef __EVENT_HANDLER_H__ +#define __EVENT_HANDLER_H__ + +#include "hci.h" +#include "socket.h" + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" { +#endif + +//***************************************************************************** +// +// Prototypes for the APIs. +// +//***************************************************************************** + +//***************************************************************************** +// +//! hci_event_handler +//! +//! @param pRetParams incoming data buffer +//! @param from from information (in case of data received) +//! @param fromlen from information length (in case of data received) +//! +//! @return none +//! +//! @brief Parse the incoming events packets and issues corresponding +//! event handler from global array of handlers pointers +// +//***************************************************************************** +extern unsigned char *hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen); + +//***************************************************************************** +// +//! hci_unsol_event_handler +//! +//! @param event_hdr event header +//! +//! @return 1 if event supported and handled +//! 0 if event is not supported +//! +//! @brief Handle unsolicited events +// +//***************************************************************************** +extern long hci_unsol_event_handler(char *event_hdr); + +//***************************************************************************** +// +//! hci_unsolicited_event_handler +//! +//! @param None +//! +//! @return ESUCCESS if successful, EFAIL if an error occurred +//! +//! @brief Parse the incoming unsolicited event packets and issues +//! corresponding event handler. +// +//***************************************************************************** +extern long hci_unsolicited_event_handler(void); + +#define M_BSD_RESP_PARAMS_OFFSET(hci_event_hdr)((char *)(hci_event_hdr) + HCI_EVENT_HEADER_SIZE) + +#define SOCKET_STATUS_ACTIVE 0 +#define SOCKET_STATUS_INACTIVE 1 +/* Init socket_active_status = 'all ones': init all sockets with SOCKET_STATUS_INACTIVE. + Will be changed by 'set_socket_active_status' upon 'connect' and 'accept' calls */ +#define SOCKET_STATUS_INIT_VAL 0xFFFF +#define M_IS_VALID_SD(sd) ((0 <= (sd)) && ((sd) <= 7)) +#define M_IS_VALID_STATUS(status) (((status) == SOCKET_STATUS_ACTIVE)||((status) == SOCKET_STATUS_INACTIVE)) + +extern unsigned long socket_active_status; + +extern void set_socket_active_status(long Sd, long Status); +extern long get_socket_active_status(long Sd); + +typedef struct _bsd_accept_return_t +{ + long iSocketDescriptor; + long iStatus; + sockaddr tSocketAddress; + +} tBsdReturnParams; + + +typedef struct _bsd_read_return_t +{ + long iSocketDescriptor; + long iNumberOfBytes; + unsigned long uiFlags; +} tBsdReadReturnParams; + +#define BSD_RECV_FROM_FROMLEN_OFFSET (4) +#define BSD_RECV_FROM_FROM_OFFSET (16) + + +typedef struct _bsd_select_return_t +{ + long iStatus; + unsigned long uiRdfd; + unsigned long uiWrfd; + unsigned long uiExfd; +} tBsdSelectRecvParams; + + +typedef struct _bsd_getsockopt_return_t +{ + unsigned char ucOptValue[4]; + char iStatus; +} tBsdGetSockOptReturnParams; + +typedef struct _bsd_gethostbyname_return_t +{ + long retVal; + long outputAddress; +} tBsdGethostbynameParams; + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // __EVENT_HANDLER_H__ + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/hci.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/hci.cpp new file mode 100755 index 0000000000..fee4492038 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/hci.cpp @@ -0,0 +1,239 @@ +/***************************************************************************** +* +* hci.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ + +//***************************************************************************** +// +//! \addtogroup hci_app +//! @{ +// +//***************************************************************************** + +#include "cc3000_common.h" +#include "hci.h" +#include "../ccspi.h" +#include "evnt_handler.h" +#include "wlan.h" + +#define SL_PATCH_PORTION_SIZE (1000) + + +//***************************************************************************** +// +//! hci_command_send +//! +//! @param usOpcode command operation code +//! @param pucBuff pointer to the command's arguments buffer +//! @param ucArgsLength length of the arguments +//! +//! @return none +//! +//! @brief Initiate an HCI command. +// +//***************************************************************************** +unsigned short +hci_command_send(unsigned short usOpcode, unsigned char *pucBuff, + unsigned char ucArgsLength) +{ + unsigned char *stream; + + stream = (pucBuff + SPI_HEADER_SIZE); + + UINT8_TO_STREAM(stream, HCI_TYPE_CMND); + stream = UINT16_TO_STREAM(stream, usOpcode); + UINT8_TO_STREAM(stream, ucArgsLength); + + //Update the opcode of the event we will be waiting for + SpiWrite(pucBuff, ucArgsLength + SIMPLE_LINK_HCI_CMND_HEADER_SIZE); + + return(0); +} + +//***************************************************************************** +// +//! hci_data_send +//! +//! @param usOpcode command operation code +//! @param ucArgs pointer to the command's arguments buffer +//! @param usArgsLength length of the arguments +//! @param ucTail pointer to the data buffer +//! @param usTailLength buffer length +//! +//! @return none +//! +//! @brief Initiate an HCI data write operation +// +//***************************************************************************** +long +hci_data_send(unsigned char ucOpcode, + unsigned char *ucArgs, + unsigned short usArgsLength, + unsigned short usDataLength, + const unsigned char *ucTail, + unsigned short usTailLength) +{ + unsigned char *stream; + + stream = ((ucArgs) + SPI_HEADER_SIZE); + + UINT8_TO_STREAM(stream, HCI_TYPE_DATA); + UINT8_TO_STREAM(stream, ucOpcode); + UINT8_TO_STREAM(stream, usArgsLength); + stream = UINT16_TO_STREAM(stream, usArgsLength + usDataLength + usTailLength); + + // Send the packet over the SPI + SpiWrite(ucArgs, SIMPLE_LINK_HCI_DATA_HEADER_SIZE + usArgsLength + usDataLength + usTailLength); + + return(ESUCCESS); +} + + +//***************************************************************************** +// +//! hci_data_command_send +//! +//! @param usOpcode command operation code +//! @param pucBuff pointer to the data buffer +//! @param ucArgsLength arguments length +//! @param ucDataLength data length +//! +//! @return none +//! +//! @brief Prepeare HCI header and initiate an HCI data write operation +// +//***************************************************************************** +void hci_data_command_send(unsigned short usOpcode, unsigned char *pucBuff, + unsigned char ucArgsLength,unsigned short ucDataLength) +{ + unsigned char *stream = (pucBuff + SPI_HEADER_SIZE); + + UINT8_TO_STREAM(stream, HCI_TYPE_DATA); + UINT8_TO_STREAM(stream, usOpcode); + UINT8_TO_STREAM(stream, ucArgsLength); + stream = UINT16_TO_STREAM(stream, ucArgsLength + ucDataLength); + + // Send the command over SPI on data channel + SpiWrite(pucBuff, ucArgsLength + ucDataLength + SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE); + + return; +} + +//***************************************************************************** +// +//! hci_patch_send +//! +//! @param usOpcode command operation code +//! @param pucBuff pointer to the command's arguments buffer +//! @param patch pointer to patch content buffer +//! @param usDataLength data length +//! +//! @return none +//! +//! @brief Prepeare HCI header and initiate an HCI patch write operation +// +//***************************************************************************** +void +hci_patch_send(unsigned char ucOpcode, unsigned char *pucBuff, char *patch, unsigned short usDataLength) +{ + unsigned char *data_ptr = (pucBuff + SPI_HEADER_SIZE); + unsigned short usTransLength; + unsigned char *stream = (pucBuff + SPI_HEADER_SIZE); + + UINT8_TO_STREAM(stream, HCI_TYPE_PATCH); + UINT8_TO_STREAM(stream, ucOpcode); + stream = UINT16_TO_STREAM(stream, usDataLength + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE); + + if (usDataLength <= SL_PATCH_PORTION_SIZE) + { + UINT16_TO_STREAM(stream, usDataLength); + stream = UINT16_TO_STREAM(stream, usDataLength); + memcpy((pucBuff + SPI_HEADER_SIZE) + HCI_PATCH_HEADER_SIZE, patch, usDataLength); + + // Update the opcode of the event we will be waiting for + SpiWrite(pucBuff, usDataLength + HCI_PATCH_HEADER_SIZE); + } + else + { + + usTransLength = (usDataLength/SL_PATCH_PORTION_SIZE); + UINT16_TO_STREAM(stream, usDataLength + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE + usTransLength*SIMPLE_LINK_HCI_PATCH_HEADER_SIZE); + stream = UINT16_TO_STREAM(stream, SL_PATCH_PORTION_SIZE); + memcpy(pucBuff + SPI_HEADER_SIZE + HCI_PATCH_HEADER_SIZE, patch, SL_PATCH_PORTION_SIZE); + usDataLength -= SL_PATCH_PORTION_SIZE; + patch += SL_PATCH_PORTION_SIZE; + + // Update the opcode of the event we will be waiting for + SpiWrite(pucBuff, SL_PATCH_PORTION_SIZE + HCI_PATCH_HEADER_SIZE); + + while (usDataLength) + { + cc3k_int_poll(); + + if (usDataLength <= SL_PATCH_PORTION_SIZE) + { + usTransLength = usDataLength; + usDataLength = 0; + + } + else + { + usTransLength = SL_PATCH_PORTION_SIZE; + usDataLength -= usTransLength; + } + + *(unsigned short *)data_ptr = usTransLength; + memcpy(data_ptr + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE, patch, usTransLength); + patch += usTransLength; + + // Update the opcode of the event we will be waiting for + SpiWrite((unsigned char *)data_ptr, usTransLength + sizeof(usTransLength)); + } + } +} + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +// +//***************************************************************************** diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/hci.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/hci.h new file mode 100755 index 0000000000..3466a9cfe6 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/hci.h @@ -0,0 +1,336 @@ +/***************************************************************************** +* +* hci.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef __HCI_H__ +#define __HCI_H__ + +#include "cc3000_common.h" + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" { +#endif + + +#define SPI_HEADER_SIZE (5) +#define SIMPLE_LINK_HCI_CMND_HEADER_SIZE (4) +#define HEADERS_SIZE_CMD (SPI_HEADER_SIZE + SIMPLE_LINK_HCI_CMND_HEADER_SIZE) +#define SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE (5) +#define SIMPLE_LINK_HCI_DATA_HEADER_SIZE (5) +#define SIMPLE_LINK_HCI_PATCH_HEADER_SIZE (2) + + +//***************************************************************************** +// +// Values that can be used as HCI Commands and HCI Packet header defines +// +//***************************************************************************** +#define HCI_TYPE_CMND 0x1 +#define HCI_TYPE_DATA 0x2 +#define HCI_TYPE_PATCH 0x3 +#define HCI_TYPE_EVNT 0x4 + + +#define HCI_EVENT_PATCHES_DRV_REQ (1) +#define HCI_EVENT_PATCHES_FW_REQ (2) +#define HCI_EVENT_PATCHES_BOOTLOAD_REQ (3) + + +#define HCI_CMND_WLAN_BASE (0x0000) +#define HCI_CMND_WLAN_CONNECT 0x0001 +#define HCI_CMND_WLAN_DISCONNECT 0x0002 +#define HCI_CMND_WLAN_IOCTL_SET_SCANPARAM 0x0003 +#define HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY 0x0004 +#define HCI_CMND_WLAN_IOCTL_ADD_PROFILE 0x0005 +#define HCI_CMND_WLAN_IOCTL_DEL_PROFILE 0x0006 +#define HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS 0x0007 +#define HCI_CMND_EVENT_MASK 0x0008 +#define HCI_CMND_WLAN_IOCTL_STATUSGET 0x0009 +#define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START 0x000A +#define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP 0x000B +#define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX 0x000C +#define HCI_CMND_WLAN_CONFIGURE_PATCH 0x000D + + +#define HCI_CMND_SOCKET_BASE 0x1000 +#define HCI_CMND_SOCKET 0x1001 +#define HCI_CMND_BIND 0x1002 +#define HCI_CMND_RECV 0x1004 +#define HCI_CMND_ACCEPT 0x1005 +#define HCI_CMND_LISTEN 0x1006 +#define HCI_CMND_CONNECT 0x1007 +#define HCI_CMND_BSD_SELECT 0x1008 +#define HCI_CMND_SETSOCKOPT 0x1009 +#define HCI_CMND_GETSOCKOPT 0x100A +#define HCI_CMND_CLOSE_SOCKET 0x100B +#define HCI_CMND_RECVFROM 0x100D +#define HCI_CMND_GETHOSTNAME 0x1010 +#define HCI_CMND_MDNS_ADVERTISE 0x1011 + + +#define HCI_DATA_BASE 0x80 + +#define HCI_CMND_SEND (0x01 + HCI_DATA_BASE) +#define HCI_CMND_SENDTO (0x03 + HCI_DATA_BASE) +#define HCI_DATA_BSD_RECVFROM (0x04 + HCI_DATA_BASE) +#define HCI_DATA_BSD_RECV (0x05 + HCI_DATA_BASE) + + +#define HCI_CMND_NVMEM_CBASE (0x0200) + + +#define HCI_CMND_NVMEM_CREATE_ENTRY (0x0203) +#define HCI_CMND_NVMEM_SWAP_ENTRY (0x0205) +#define HCI_CMND_NVMEM_READ (0x0201) +#define HCI_CMND_NVMEM_WRITE (0x0090) +#define HCI_CMND_NVMEM_WRITE_PATCH (0x0204) +#define HCI_CMND_READ_SP_VERSION (0x0207) + +#define HCI_CMND_READ_BUFFER_SIZE 0x400B +#define HCI_CMND_SIMPLE_LINK_START 0x4000 + +#define HCI_CMND_NETAPP_BASE 0x2000 + +#define HCI_NETAPP_DHCP (0x0001 + HCI_CMND_NETAPP_BASE) +#define HCI_NETAPP_PING_SEND (0x0002 + HCI_CMND_NETAPP_BASE) +#define HCI_NETAPP_PING_REPORT (0x0003 + HCI_CMND_NETAPP_BASE) +#define HCI_NETAPP_PING_STOP (0x0004 + HCI_CMND_NETAPP_BASE) +#define HCI_NETAPP_IPCONFIG (0x0005 + HCI_CMND_NETAPP_BASE) +#define HCI_NETAPP_ARP_FLUSH (0x0006 + HCI_CMND_NETAPP_BASE) +#define HCI_NETAPP_SET_DEBUG_LEVEL (0x0008 + HCI_CMND_NETAPP_BASE) +#define HCI_NETAPP_SET_TIMERS (0x0009 + HCI_CMND_NETAPP_BASE) + + + + + + +//***************************************************************************** +// +// Values that can be used as HCI Events defines +// +//***************************************************************************** +#define HCI_EVNT_WLAN_BASE 0x0000 +#define HCI_EVNT_WLAN_CONNECT 0x0001 +#define HCI_EVNT_WLAN_DISCONNECT \ + 0x0002 +#define HCI_EVNT_WLAN_IOCTL_ADD_PROFILE \ + 0x0005 + + +#define HCI_EVNT_SOCKET HCI_CMND_SOCKET +#define HCI_EVNT_BIND HCI_CMND_BIND +#define HCI_EVNT_RECV HCI_CMND_RECV +#define HCI_EVNT_ACCEPT HCI_CMND_ACCEPT +#define HCI_EVNT_LISTEN HCI_CMND_LISTEN +#define HCI_EVNT_CONNECT HCI_CMND_CONNECT +#define HCI_EVNT_SELECT HCI_CMND_BSD_SELECT +#define HCI_EVNT_CLOSE_SOCKET HCI_CMND_CLOSE_SOCKET +#define HCI_EVNT_RECVFROM HCI_CMND_RECVFROM +#define HCI_EVNT_SETSOCKOPT HCI_CMND_SETSOCKOPT +#define HCI_EVNT_GETSOCKOPT HCI_CMND_GETSOCKOPT +#define HCI_EVNT_BSD_GETHOSTBYNAME HCI_CMND_GETHOSTNAME +#define HCI_EVNT_MDNS_ADVERTISE HCI_CMND_MDNS_ADVERTISE + +#define HCI_EVNT_SEND 0x1003 +#define HCI_EVNT_WRITE 0x100E +#define HCI_EVNT_SENDTO 0x100F + +#define HCI_EVNT_PATCHES_REQ 0x1000 + +#define HCI_EVNT_UNSOL_BASE 0x4000 + +#define HCI_EVNT_WLAN_UNSOL_BASE (0x8000) + +#define HCI_EVNT_WLAN_UNSOL_CONNECT (0x0001 + HCI_EVNT_WLAN_UNSOL_BASE) +#define HCI_EVNT_WLAN_UNSOL_DISCONNECT (0x0002 + HCI_EVNT_WLAN_UNSOL_BASE) +#define HCI_EVNT_WLAN_UNSOL_INIT (0x0004 + HCI_EVNT_WLAN_UNSOL_BASE) +#define HCI_EVNT_WLAN_TX_COMPLETE (0x0008 + HCI_EVNT_WLAN_UNSOL_BASE) +#define HCI_EVNT_WLAN_UNSOL_DHCP (0x0010 + HCI_EVNT_WLAN_UNSOL_BASE) +#define HCI_EVNT_WLAN_ASYNC_PING_REPORT (0x0040 + HCI_EVNT_WLAN_UNSOL_BASE) +#define HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE (0x0080 + HCI_EVNT_WLAN_UNSOL_BASE) +#define HCI_EVNT_WLAN_KEEPALIVE (0x0200 + HCI_EVNT_WLAN_UNSOL_BASE) +#define HCI_EVNT_BSD_TCP_CLOSE_WAIT (0x0800 + HCI_EVNT_WLAN_UNSOL_BASE) + +#define HCI_EVNT_DATA_UNSOL_FREE_BUFF \ + 0x4100 + +#define HCI_EVNT_NVMEM_CREATE_ENTRY \ + HCI_CMND_NVMEM_CREATE_ENTRY +#define HCI_EVNT_NVMEM_SWAP_ENTRY HCI_CMND_NVMEM_SWAP_ENTRY + +#define HCI_EVNT_NVMEM_READ HCI_CMND_NVMEM_READ +#define HCI_EVNT_NVMEM_WRITE (0x0202) + +#define HCI_EVNT_READ_SP_VERSION \ + HCI_CMND_READ_SP_VERSION + +#define HCI_EVNT_INPROGRESS 0xFFFF + + +#define HCI_DATA_RECVFROM 0x84 +#define HCI_DATA_RECV 0x85 +#define HCI_DATA_NVMEM 0x91 + +#define HCI_EVENT_CC3000_CAN_SHUT_DOWN 0x99 + +//***************************************************************************** +// +// Prototypes for the structures for APIs. +// +//***************************************************************************** + +#define HCI_DATA_HEADER_SIZE (5) +#define HCI_EVENT_HEADER_SIZE (5) +#define HCI_DATA_CMD_HEADER_SIZE (5) +#define HCI_PATCH_HEADER_SIZE (6) + +#define HCI_PACKET_TYPE_OFFSET (0) +#define HCI_PACKET_ARGSIZE_OFFSET (2) +#define HCI_PACKET_LENGTH_OFFSET (3) + + +#define HCI_EVENT_OPCODE_OFFSET (1) +#define HCI_EVENT_LENGTH_OFFSET (3) +#define HCI_EVENT_STATUS_OFFSET (4) +#define HCI_DATA_LENGTH_OFFSET (3) + + + + +//***************************************************************************** +// +// Prototypes for the APIs. +// +//***************************************************************************** + +//***************************************************************************** +// +//! hci_command_send +//! +//! @param usOpcode command operation code +//! @param pucBuff pointer to the command's arguments buffer +//! @param ucArgsLength length of the arguments +//! +//! @return none +//! +//! @brief Initiate an HCI command. +// +//***************************************************************************** +extern unsigned short hci_command_send(unsigned short usOpcode, + unsigned char *ucArgs, + unsigned char ucArgsLength); + + +//***************************************************************************** +// +//! hci_data_send +//! +//! @param usOpcode command operation code +//! @param ucArgs pointer to the command's arguments buffer +//! @param usArgsLength length of the arguments +//! @param ucTail pointer to the data buffer +//! @param usTailLength buffer length +//! +//! @return none +//! +//! @brief Initiate an HCI data write operation +// +//***************************************************************************** +extern long hci_data_send(unsigned char ucOpcode, + unsigned char *ucArgs, + unsigned short usArgsLength, + unsigned short usDataLength, + const unsigned char *ucTail, + unsigned short usTailLength); + + +//***************************************************************************** +// +//! hci_data_command_send +//! +//! @param usOpcode command operation code +//! @param pucBuff pointer to the data buffer +//! @param ucArgsLength arguments length +//! @param ucDataLength data length +//! +//! @return none +//! +//! @brief Prepare HCI header and initiate an HCI data write operation +// +//***************************************************************************** +extern void hci_data_command_send(unsigned short usOpcode, unsigned char *pucBuff, + unsigned char ucArgsLength, unsigned short ucDataLength); + +//***************************************************************************** +// +//! hci_patch_send +//! +//! @param usOpcode command operation code +//! @param pucBuff pointer to the command's arguments buffer +//! @param patch pointer to patch content buffer +//! @param usDataLength data length +//! +//! @return none +//! +//! @brief Prepare HCI header and initiate an HCI patch write operation +// +//***************************************************************************** +extern void hci_patch_send(unsigned char ucOpcode, unsigned char *pucBuff, char *patch, unsigned short usDataLength); + + + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // __HCI_H__ diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/host_driver_version.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/host_driver_version.h new file mode 100755 index 0000000000..c218704a2e --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/host_driver_version.h @@ -0,0 +1,55 @@ +/***************************************************************************** +* +* host_driver_version.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef __HOST_DRIVER_VERSION_H__ +#define __HOST_DRIVER_VERSION_H__ + +#define DRIVER_VERSION_NUMBER 13 + + + +#endif // __VERSION_H__ + + + + + + + + + + + + + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/netapp.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/netapp.cpp new file mode 100755 index 0000000000..a0dbbf11de --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/netapp.cpp @@ -0,0 +1,476 @@ +/***************************************************************************** +* +* netapp.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#include +#include "netapp.h" +#include "hci.h" +#include "socket.h" +#include "evnt_handler.h" +#include "nvmem.h" + +#define MIN_TIMER_VAL_SECONDS 20 +#define MIN_TIMER_SET(t) if ((0 != t) && (t < MIN_TIMER_VAL_SECONDS)) \ + { \ + t = MIN_TIMER_VAL_SECONDS; \ + } + + +#define NETAPP_DHCP_PARAMS_LEN (20) +#define NETAPP_SET_TIMER_PARAMS_LEN (20) +#define NETAPP_SET_DEBUG_LEVEL_PARAMS_LEN (4) +#define NETAPP_PING_SEND_PARAMS_LEN (16) + + +//***************************************************************************** +// +//! netapp_config_mac_adrress +//! +//! @param mac device mac address, 6 bytes. Saved: yes +//! +//! @return return on success 0, otherwise error. +//! +//! @brief Configure device MAC address and store it in NVMEM. +//! The value of the MAC address configured through the API will +//! be stored in CC3000 non volatile memory, thus preserved +//! over resets. +// +//***************************************************************************** +long netapp_config_mac_adrress(unsigned char * mac) +{ + return nvmem_set_mac_address(mac); +} + +//***************************************************************************** +// +//! netapp_dhcp +//! +//! @param aucIP device mac address, 6 bytes. Saved: yes +//! @param aucSubnetMask device mac address, 6 bytes. Saved: yes +//! @param aucDefaultGateway device mac address, 6 bytes. Saved: yes +//! @param aucDNSServer device mac address, 6 bytes. Saved: yes +//! +//! @return return on success 0, otherwise error. +//! +//! @brief netapp_dhcp is used to configure the network interface, +//! static or dynamic (DHCP).\n In order to activate DHCP mode, +//! aucIP, aucSubnetMask, aucDefaultGateway must be 0. +//! The default mode of CC3000 is DHCP mode. +//! Note that the configuration is saved in non volatile memory +//! and thus preserved over resets. +//! +//! @note If the mode is altered a reset of CC3000 device is required +//! in order to apply changes.\nAlso note that asynchronous event +//! of DHCP_EVENT, which is generated when an IP address is +//! allocated either by the DHCP server or due to static +//! allocation is generated only upon a connection to the +//! AP was established. +//! +//***************************************************************************** +long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,unsigned long *aucDefaultGateway, unsigned long *aucDNSServer) +{ + signed char scRet; + unsigned char *ptr; + unsigned char *args; + + scRet = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + ARRAY_TO_STREAM(args,aucIP,4); + ARRAY_TO_STREAM(args,aucSubnetMask,4); + ARRAY_TO_STREAM(args,aucDefaultGateway,4); + args = UINT32_TO_STREAM(args, 0); + ARRAY_TO_STREAM(args,aucDNSServer,4); + + // Initiate a HCI command + hci_command_send(HCI_NETAPP_DHCP, ptr, NETAPP_DHCP_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_NETAPP_DHCP, &scRet); + + return(scRet); +} + + +//***************************************************************************** +// +//! netapp_timeout_values +//! +//! @param aucDHCP DHCP lease time request, also impact +//! the DHCP renew timeout. Range: [0-0xffffffff] seconds, +//! 0 or 0xffffffff == infinity lease timeout. +//! Resolution:10 seconds. Influence: only after +//! reconnecting to the AP. +//! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds. +//! The parameter is saved into the CC3000 NVMEM. +//! The default value on CC3000 is 14400 seconds. +//! +//! @param aucARP ARP refresh timeout, if ARP entry is not updated by +//! incoming packet, the ARP entry will be deleted by +//! the end of the timeout. +//! Range: [0-0xffffffff] seconds, 0 == infinity ARP timeout +//! Resolution: 10 seconds. Influence: on runtime. +//! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds +//! The parameter is saved into the CC3000 NVMEM. +//! The default value on CC3000 is 3600 seconds. +//! +//! @param aucKeepalive Keepalive event sent by the end of keepalive timeout +//! Range: [0-0xffffffff] seconds, 0 == infinity timeout +//! Resolution: 10 seconds. +//! Influence: on runtime. +//! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec +//! The parameter is saved into the CC3000 NVMEM. +//! The default value on CC3000 is 10 seconds. +//! +//! @param aucInactivity Socket inactivity timeout, socket timeout is +//! refreshed by incoming or outgoing packet, by the +//! end of the socket timeout the socket will be closed +//! Range: [0-0xffffffff] sec, 0 == infinity timeout. +//! Resolution: 10 seconds. Influence: on runtime. +//! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec +//! The parameter is saved into the CC3000 NVMEM. +//! The default value on CC3000 is 60 seconds. +//! +//! @return return on success 0, otherwise error. +//! +//! @brief Set new timeout values. Function set new timeout values for: +//! DHCP lease timeout, ARP refresh timeout, keepalive event +//! timeout and socket inactivity timeout +//! +//! @note If a parameter set to non zero value which is less than 20s, +//! it will be set automatically to 20s. +//! +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long +netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,unsigned long *aucKeepalive, unsigned long *aucInactivity) +{ + signed char scRet; + unsigned char *ptr; + unsigned char *args; + + scRet = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Set minimal values of timers + MIN_TIMER_SET(*aucDHCP) + MIN_TIMER_SET(*aucARP) + MIN_TIMER_SET(*aucKeepalive) + MIN_TIMER_SET(*aucInactivity) + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, *aucDHCP); + args = UINT32_TO_STREAM(args, *aucARP); + args = UINT32_TO_STREAM(args, *aucKeepalive); + args = UINT32_TO_STREAM(args, *aucInactivity); + + // Initiate a HCI command + hci_command_send(HCI_NETAPP_SET_TIMERS, ptr, NETAPP_SET_TIMER_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_NETAPP_SET_TIMERS, &scRet); + + return(scRet); +} +#endif + + +//***************************************************************************** +// +//! netapp_ping_send +//! +//! @param ip destination IP address +//! @param pingAttempts number of echo requests to send +//! @param pingSize send buffer size which may be up to 1400 bytes +//! @param pingTimeout Time to wait for a response,in milliseconds. +//! +//! @return return on success 0, otherwise error. +//! +//! @brief send ICMP ECHO_REQUEST to network hosts +//! +//! @note If an operation finished successfully asynchronous ping report +//! event will be generated. The report structure is as defined +//! by structure netapp_pingreport_args_t. +//! +//! @warning Calling this function while a previous Ping Requests are in +//! progress will stop the previous ping request. +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long +netapp_ping_send(uint32_t *ip, uint32_t ulPingAttempts, uint32_t ulPingSize, uint32_t ulPingTimeout) +{ + signed char scRet; + unsigned char *ptr, *args; + + scRet = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, *ip); + args = UINT32_TO_STREAM(args, ulPingAttempts); + args = UINT32_TO_STREAM(args, ulPingSize); + args = UINT32_TO_STREAM(args, ulPingTimeout); + + /* + if (CC3KPrinter != 0) + { + for(uint8_t i=0; i<4+4+4+4; i++) { + CC3KPrinter->print(" 0x"); CC3KPrinter->( (ptr + HEADERS_SIZE_CMD)[i], HEX); + } + } + */ + + // Initiate a HCI command + hci_command_send(HCI_NETAPP_PING_SEND, ptr, NETAPP_PING_SEND_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_NETAPP_PING_SEND, &scRet); + + return(scRet); +} +#endif + +//***************************************************************************** +// +//! netapp_ping_report +//! +//! @param none +//! +//! @return none +//! +//! @brief Request for ping status. This API triggers the CC3000 to send +//! asynchronous events: HCI_EVNT_WLAN_ASYNC_PING_REPORT. +//! This event will carry the report structure: +//! netapp_pingreport_args_t. This structure is filled in with ping +//! results up till point of triggering API. +//! netapp_pingreport_args_t:\n packets_sent - echo sent, +//! packets_received - echo reply, min_round_time - minimum +//! round time, max_round_time - max round time, +//! avg_round_time - average round time +//! +//! @note When a ping operation is not active, the returned structure +//! fields are 0. +//! +//***************************************************************************** + + +#ifndef CC3000_TINY_DRIVER +void netapp_ping_report() +{ + unsigned char *ptr; + ptr = tSLInformation.pucTxCommandBuffer; + signed char scRet; + + scRet = EFAIL; + + // Initiate a HCI command + hci_command_send(HCI_NETAPP_PING_REPORT, ptr, 0); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_NETAPP_PING_REPORT, &scRet); +} +#endif + +//***************************************************************************** +// +//! netapp_ping_stop +//! +//! @param none +//! +//! @return On success, zero is returned. On error, -1 is returned. +//! +//! @brief Stop any ping request. +//! +//! +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long netapp_ping_stop() +{ + signed char scRet; + unsigned char *ptr; + + scRet = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + + // Initiate a HCI command + hci_command_send(HCI_NETAPP_PING_STOP, ptr, 0); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_NETAPP_PING_STOP, &scRet); + + return(scRet); +} +#endif + +//***************************************************************************** +// +//! netapp_ipconfig +//! +//! @param[out] ipconfig This argument is a pointer to a +//! tNetappIpconfigRetArgs structure. This structure is +//! filled in with the network interface configuration. +//! tNetappIpconfigRetArgs:\n aucIP - ip address, +//! aucSubnetMask - mask, aucDefaultGateway - default +//! gateway address, aucDHCPServer - dhcp server address +//! aucDNSServer - dns server address, uaMacAddr - mac +//! address, uaSSID - connected AP ssid +//! +//! @return none +//! +//! @brief Obtain the CC3000 Network interface information. +//! Note that the information is available only after the WLAN +//! connection was established. Calling this function before +//! associated, will cause non-defined values to be returned. +//! +//! @note The function is useful for figuring out the IP Configuration of +//! the device when DHCP is used and for figuring out the SSID of +//! the Wireless network the device is associated with. +//! +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +void netapp_ipconfig( tNetappIpconfigRetArgs * ipconfig ) +{ + unsigned char *ptr; + + ptr = tSLInformation.pucTxCommandBuffer; + + // Initiate a HCI command + hci_command_send(HCI_NETAPP_IPCONFIG, ptr, 0); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_NETAPP_IPCONFIG, ipconfig ); + +} +#else +void netapp_ipconfig( tNetappIpconfigRetArgs * ipconfig ) +{ + +} +#endif + +//***************************************************************************** +// +//! netapp_arp_flush +//! +//! @param none +//! +//! @return none +//! +//! @brief Flushes ARP table +//! +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long netapp_arp_flush(void) +{ + signed char scRet; + unsigned char *ptr; + + scRet = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + + // Initiate a HCI command + hci_command_send(HCI_NETAPP_ARP_FLUSH, ptr, 0); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_NETAPP_ARP_FLUSH, &scRet); + + return(scRet); +} +#endif + +//***************************************************************************** +// +//! netapp_set_debug_level +//! +//! @param[in] level debug level. Bitwise [0-8], +//! 0(disable)or 1(enable).\n Bitwise map: 0 - Critical +//! message, 1 information message, 2 - core messages, 3 - +//! HCI messages, 4 - Network stack messages, 5 - wlan +//! messages, 6 - wlan driver messages, 7 - epprom messages, +//! 8 - general messages. Default: 0x13f. Saved: no +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Debug messages sent via the UART debug channel, this function +//! enable/disable the debug level +//! +//***************************************************************************** + + +#ifndef CC3000_TINY_DRIVER +long netapp_set_debug_level(unsigned long ulLevel) +{ + signed char scRet; + unsigned char *ptr, *args; + + scRet = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // + // Fill in temporary command buffer + // + args = UINT32_TO_STREAM(args, ulLevel); + + + // + // Initiate a HCI command + // + hci_command_send(HCI_NETAPP_SET_DEBUG_LEVEL, ptr, NETAPP_SET_DEBUG_LEVEL_PARAMS_LEN); + + // + // Wait for command complete event + // + SimpleLinkWaitEvent(HCI_NETAPP_SET_DEBUG_LEVEL, &scRet); + + return(scRet); + +} +#endif diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/netapp.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/netapp.h new file mode 100755 index 0000000000..bb5007b411 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/netapp.h @@ -0,0 +1,353 @@ +/***************************************************************************** +* +* netapp.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef __NETAPP_H__ +#define __NETAPP_H__ + +#include + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" { +#endif + +//***************************************************************************** +// +//! \addtogroup netapp_api +//! @{ +// +//***************************************************************************** + +typedef struct _netapp_dhcp_ret_args_t +{ + unsigned char aucIP[4]; + unsigned char aucSubnetMask[4]; + unsigned char aucDefaultGateway[4]; + unsigned char aucDHCPServer[4]; + unsigned char aucDNSServer[4]; +}tNetappDhcpParams; + +typedef struct _netapp_ipconfig_ret_args_t +{ + unsigned char aucIP[4]; + unsigned char aucSubnetMask[4]; + unsigned char aucDefaultGateway[4]; + unsigned char aucDHCPServer[4]; + unsigned char aucDNSServer[4]; + unsigned char uaMacAddr[6]; + unsigned char uaSSID[32]; +}tNetappIpconfigRetArgs; + + +/*Ping send report parameters*/ +typedef struct _netapp_pingreport_args +{ + unsigned long packets_sent; + unsigned long packets_received; + unsigned long min_round_time; + unsigned long max_round_time; + unsigned long avg_round_time; +} netapp_pingreport_args_t; + + +//***************************************************************************** +// +//! netapp_config_mac_adrress +//! +//! @param mac device mac address, 6 bytes. Saved: yes +//! +//! @return return on success 0, otherwise error. +//! +//! @brief Configure device MAC address and store it in NVMEM. +//! The value of the MAC address configured through the API will +//! be stored in CC3000 non volatile memory, thus preserved +//! over resets. +// +//***************************************************************************** +extern long netapp_config_mac_adrress( unsigned char *mac ); + +//***************************************************************************** +// +//! netapp_dhcp +//! +//! @param aucIP device mac address, 6 bytes. Saved: yes +//! @param aucSubnetMask device mac address, 6 bytes. Saved: yes +//! @param aucDefaultGateway device mac address, 6 bytes. Saved: yes +//! @param aucDNSServer device mac address, 6 bytes. Saved: yes +//! +//! @return return on success 0, otherwise error. +//! +//! @brief netapp_dhcp is used to configure the network interface, +//! static or dynamic (DHCP).\n In order to activate DHCP mode, +//! aucIP, aucSubnetMask, aucDefaultGateway must be 0. +//! The default mode of CC3000 is DHCP mode. +//! Note that the configuration is saved in non volatile memory +//! and thus preserved over resets. +//! +//! @note If the mode is altered a reset of CC3000 device is required +//! in order to apply changes.\nAlso note that asynchronous event +//! of DHCP_EVENT, which is generated when an IP address is +//! allocated either by the DHCP server or due to static +//! allocation is generated only upon a connection to the +//! AP was established. +//! +//***************************************************************************** +extern long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,unsigned long *aucDefaultGateway, unsigned long *aucDNSServer); + + + +//***************************************************************************** +// +//! netapp_timeout_values +//! +//! @param aucDHCP DHCP lease time request, also impact +//! the DHCP renew timeout. Range: [0-0xffffffff] seconds, +//! 0 or 0xffffffff == infinity lease timeout. +//! Resolution:10 seconds. Influence: only after +//! reconnecting to the AP. +//! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds. +//! The parameter is saved into the CC3000 NVMEM. +//! The default value on CC3000 is 14400 seconds. +//! +//! @param aucARP ARP refresh timeout, if ARP entry is not updated by +//! incoming packet, the ARP entry will be deleted by +//! the end of the timeout. +//! Range: [0-0xffffffff] seconds, 0 == infinity ARP timeout +//! Resolution: 10 seconds. Influence: on runtime. +//! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds +//! The parameter is saved into the CC3000 NVMEM. +//! The default value on CC3000 is 3600 seconds. +//! +//! @param aucKeepalive Keepalive event sent by the end of keepalive timeout +//! Range: [0-0xffffffff] seconds, 0 == infinity timeout +//! Resolution: 10 seconds. +//! Influence: on runtime. +//! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec +//! The parameter is saved into the CC3000 NVMEM. +//! The default value on CC3000 is 10 seconds. +//! +//! @param aucInactivity Socket inactivity timeout, socket timeout is +//! refreshed by incoming or outgoing packet, by the +//! end of the socket timeout the socket will be closed +//! Range: [0-0xffffffff] sec, 0 == infinity timeout. +//! Resolution: 10 seconds. Influence: on runtime. +//! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec +//! The parameter is saved into the CC3000 NVMEM. +//! The default value on CC3000 is 60 seconds. +//! +//! @return return on success 0, otherwise error. +//! +//! @brief Set new timeout values. Function set new timeout values for: +//! DHCP lease timeout, ARP refresh timeout, keepalive event +//! timeout and socket inactivity timeout +//! +//! @note If a parameter set to non zero value which is less than 20s, +//! it will be set automatically to 20s. +//! +//***************************************************************************** + #ifndef CC3000_TINY_DRIVER +extern long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,unsigned long *aucKeepalive, unsigned long *aucInactivity); +#endif + +//***************************************************************************** +// +//! netapp_ping_send +//! +//! @param ip destination IP address +//! @param pingAttempts number of echo requests to send +//! @param pingSize send buffer size which may be up to 1400 bytes +//! @param pingTimeout Time to wait for a response,in milliseconds. +//! +//! @return return on success 0, otherwise error. +//! +//! @brief send ICMP ECHO_REQUEST to network hosts +//! +//! @note If an operation finished successfully asynchronous ping report +//! event will be generated. The report structure is as defined +//! by structure netapp_pingreport_args_t. +//! +//! @warning Calling this function while a previous Ping Requests are in +//! progress will stop the previous ping request. +//***************************************************************************** + + #ifndef CC3000_TINY_DRIVER +extern long netapp_ping_send(uint32_t *ip, uint32_t ulPingAttempts, uint32_t ulPingSize, uint32_t ulPingTimeout); +#endif + +//***************************************************************************** +// +//! netapp_ping_stop +//! +//! @param none +//! +//! @return On success, zero is returned. On error, -1 is returned. +//! +//! @brief Stop any ping request. +//! +//! +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +extern long netapp_ping_stop(); +#endif +//***************************************************************************** +// +//! netapp_ping_report +//! +//! @param none +//! +//! @return none +//! +//! @brief Request for ping status. This API triggers the CC3000 to send +//! asynchronous events: HCI_EVNT_WLAN_ASYNC_PING_REPORT. +//! This event will carry the report structure: +//! netapp_pingreport_args_t. This structure is filled in with ping +//! results up till point of triggering API. +//! netapp_pingreport_args_t:\n packets_sent - echo sent, +//! packets_received - echo reply, min_round_time - minimum +//! round time, max_round_time - max round time, +//! avg_round_time - average round time +//! +//! @note When a ping operation is not active, the returned structure +//! fields are 0. +//! +//***************************************************************************** +#ifndef CC3000_TINY_DRIVER +extern void netapp_ping_report(); +#endif + + +//***************************************************************************** +// +//! netapp_ipconfig +//! +//! @param[out] ipconfig This argument is a pointer to a +//! tNetappIpconfigRetArgs structure. This structure is +//! filled in with the network interface configuration. +//! tNetappIpconfigRetArgs:\n aucIP - ip address, +//! aucSubnetMask - mask, aucDefaultGateway - default +//! gateway address, aucDHCPServer - dhcp server address +//! aucDNSServer - dns server address, uaMacAddr - mac +//! address, uaSSID - connected AP ssid +//! +//! @return none +//! +//! @brief Obtain the CC3000 Network interface information. +//! Note that the information is available only after the WLAN +//! connection was established. Calling this function before +//! associated, will cause non-defined values to be returned. +//! +//! @note The function is useful for figuring out the IP Configuration of +//! the device when DHCP is used and for figuring out the SSID of +//! the Wireless network the device is associated with. +//! +//***************************************************************************** + +extern void netapp_ipconfig( tNetappIpconfigRetArgs * ipconfig ); + + +//***************************************************************************** +// +//! netapp_arp_flush +//! +//! @param none +//! +//! @return none +//! +//! @brief Flushes ARP table +//! +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +extern long netapp_arp_flush(); +#endif + + +//***************************************************************************** +// +//! netapp_set_debug_level +//! +//! @param[in] level debug level. Bitwise [0-8], +//! 0(disable)or 1(enable).\n Bitwise map: 0 - Critical +//! message, 1 information message, 2 - core messages, 3 - +//! HCI messages, 4 - Network stack messages, 5 - wlan +//! messages, 6 - wlan driver messages, 7 - epprom messages, +//! 8 - general messages. Default: 0x13f. Saved: no +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Debug messages sent via the UART debug channel, this function +//! enable/disable the debug level +//! +//***************************************************************************** + + +#ifndef CC3000_TINY_DRIVER +long netapp_set_debug_level(unsigned long ulLevel); +#endif +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** + + + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif // __cplusplus + +extern Print* CC3KPrinter; + +#endif // __NETAPP_H__ + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/nvmem.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/nvmem.cpp new file mode 100755 index 0000000000..7d4a43428d --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/nvmem.cpp @@ -0,0 +1,376 @@ +/***************************************************************************** +* +* nvmem.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ + +//***************************************************************************** +// +//! \addtogroup nvmem_api +//! @{ +// +//***************************************************************************** + +#include +#include +#include + +#ifdef __AVR__ + #include +#endif + +#include "nvmem.h" +#include "hci.h" +#include "socket.h" +#include "evnt_handler.h" +#include "debug.h" + +//***************************************************************************** +// +// Prototypes for the structures for APIs. +// +//***************************************************************************** + +#define NVMEM_READ_PARAMS_LEN (12) +#define NVMEM_CREATE_PARAMS_LEN (8) +#define NVMEM_WRITE_PARAMS_LEN (16) + +//***************************************************************************** +// +//! nvmem_read +//! +//! @param ulFileId nvmem file id:\n +//! NVMEM_NVS_FILEID, NVMEM_NVS_SHADOW_FILEID, +//! NVMEM_WLAN_CONFIG_FILEID, NVMEM_WLAN_CONFIG_SHADOW_FILEID, +//! NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID, +//! NVMEM_MAC_FILEID, NVMEM_FRONTEND_VARS_FILEID, +//! NVMEM_IP_CONFIG_FILEID, NVMEM_IP_CONFIG_SHADOW_FILEID, +//! NVMEM_BOOTLOADER_SP_FILEID, NVMEM_RM_FILEID, +//! and user files 12-15. +//! @param ulLength number of bytes to read +//! @param ulOffset ulOffset in file from where to read +//! @param buff output buffer pointer +//! +//! @return number of bytes read, otherwise error. +//! +//! @brief Reads data from the file referred by the ulFileId parameter. +//! Reads data from file ulOffset till length. Err if the file can't +//! be used, is invalid, or if the read is out of bounds. +//! +//***************************************************************************** + +signed long +nvmem_read(unsigned long ulFileId, unsigned long ulLength, unsigned long ulOffset, unsigned char *buff) +{ + unsigned char ucStatus = 0xFF; + unsigned char *ptr; + unsigned char *args; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, ulFileId); + args = UINT32_TO_STREAM(args, ulLength); + args = UINT32_TO_STREAM(args, ulOffset); + + // Initiate a HCI command + hci_command_send(HCI_CMND_NVMEM_READ, ptr, NVMEM_READ_PARAMS_LEN); + SimpleLinkWaitEvent(HCI_CMND_NVMEM_READ, &ucStatus); + + // In case there is data - read it - even if an error code is returned + // Note: It is the user responsibility to ignore the data in case of an error code + + // Wait for the data in a synchronous way. Here we assume that the buffer is + // big enough to store also parameters of nvmem + + SimpleLinkWaitData(buff, 0, 0); + + return(ucStatus); +} + +//***************************************************************************** +// +//! nvmem_write +//! +//! @param ulFileId nvmem file id:\n +//! NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID, +//! NVMEM_MAC_FILEID, NVMEM_BOOTLOADER_SP_FILEID, +//! and user files 12-15. +//! @param ulLength number of bytes to write +//! @param ulEntryOffset offset in file to start write operation from +//! @param buff data to write +//! +//! @return on success 0, error otherwise. +//! +//! @brief Write data to nvmem. +//! writes data to file referred by the ulFileId parameter. +//! Writes data to file ulOffset till ulLength.The file id will be +//! marked invalid till the write is done. The file entry doesn't +//! need to be valid - only allocated. +//! +//***************************************************************************** + +signed long +nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long + ulEntryOffset, unsigned char *buff) +{ + long iRes; + unsigned char *ptr; + unsigned char *args; + + iRes = EFAIL; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, ulFileId); + args = UINT32_TO_STREAM(args, 12); + args = UINT32_TO_STREAM(args, ulLength); + args = UINT32_TO_STREAM(args, ulEntryOffset); + + memcpy((ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE + + NVMEM_WRITE_PARAMS_LEN),buff,ulLength); +#if (DEBUG_MODE == 1) + PRINT_F("Writing:\t"); + for (uint8_t i=0; i= SP_PORTION_SIZE)) + { + for (uint8_t i=0; i https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef __NVRAM_H__ +#define __NVRAM_H__ + +#include "cc3000_common.h" + + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" { +#endif + + +//***************************************************************************** +// +//! \addtogroup nvmem_api +//! @{ +// +//***************************************************************************** + +/**************************************************************************** +** +** Definitions for File IDs +** +****************************************************************************/ +/* NVMEM file ID - system files*/ +#define NVMEM_NVS_FILEID (0) +#define NVMEM_NVS_SHADOW_FILEID (1) +#define NVMEM_WLAN_CONFIG_FILEID (2) +#define NVMEM_WLAN_CONFIG_SHADOW_FILEID (3) +#define NVMEM_WLAN_DRIVER_SP_FILEID (4) +#define NVMEM_WLAN_FW_SP_FILEID (5) +#define NVMEM_MAC_FILEID (6) +#define NVMEM_FRONTEND_VARS_FILEID (7) +#define NVMEM_IP_CONFIG_FILEID (8) +#define NVMEM_IP_CONFIG_SHADOW_FILEID (9) +#define NVMEM_BOOTLOADER_SP_FILEID (10) +#define NVMEM_RM_FILEID (11) + +/* NVMEM file ID - user files*/ +#define NVMEM_AES128_KEY_FILEID (12) +#define NVMEM_SHARED_MEM_FILEID (13) + +/* max entry in order to invalid nvmem */ +#define NVMEM_MAX_ENTRY (16) + + +//***************************************************************************** +// +//! nvmem_read +//! +//! @param ulFileId nvmem file id:\n +//! NVMEM_NVS_FILEID, NVMEM_NVS_SHADOW_FILEID, +//! NVMEM_WLAN_CONFIG_FILEID, NVMEM_WLAN_CONFIG_SHADOW_FILEID, +//! NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID, +//! NVMEM_MAC_FILEID, NVMEM_FRONTEND_VARS_FILEID, +//! NVMEM_IP_CONFIG_FILEID, NVMEM_IP_CONFIG_SHADOW_FILEID, +//! NVMEM_BOOTLOADER_SP_FILEID, NVMEM_RM_FILEID, +//! and user files 12-15. +//! @param ulLength number of bytes to read +//! @param ulOffset ulOffset in file from where to read +//! @param buff output buffer pointer +//! +//! @return number of bytes read, otherwise error. +//! +//! @brief Reads data from the file referred by the ulFileId parameter. +//! Reads data from file ulOffset till length. Err if the file can't +//! be used, is invalid, or if the read is out of bounds. +//! +//***************************************************************************** + +extern signed long nvmem_read(unsigned long file_id, unsigned long length, unsigned long offset, unsigned char *buff); + +//***************************************************************************** +// +//! nvmem_write +//! +//! @param ulFileId nvmem file id:\n +//! NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID, +//! NVMEM_MAC_FILEID, NVMEM_BOOTLOADER_SP_FILEID, +//! and user files 12-15. +//! @param ulLength number of bytes to write +//! @param ulEntryOffset offset in file to start write operation from +//! @param buff data to write +//! +//! @return on success 0, error otherwise. +//! +//! @brief Write data to nvmem. +//! writes data to file referred by the ulFileId parameter. +//! Writes data to file ulOffset till ulLength.The file id will be +//! marked invalid till the write is done. The file entry doesn't +//! need to be valid - only allocated. +//! +//***************************************************************************** + +extern signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long ulEntryOffset, unsigned char *buff); + + +//***************************************************************************** +// +//! nvmem_set_mac_address +//! +//! @param mac mac address to be set +//! +//! @return on success 0, error otherwise. +//! +//! @brief Write MAC address to EEPROM. +//! mac address as appears over the air (OUI first) +//! +//***************************************************************************** +extern unsigned char nvmem_set_mac_address(unsigned char *mac); + + +//***************************************************************************** +// +//! nvmem_get_mac_address +//! +//! @param[out] mac mac address +//! +//! @return on success 0, error otherwise. +//! +//! @brief Read MAC address from EEPROM. +//! mac address as appears over the air (OUI first) +//! +//***************************************************************************** +extern unsigned char nvmem_get_mac_address(unsigned char *mac); + + +//***************************************************************************** +// +//! nvmem_write_patch +//! +//! @param ulFileId nvmem file id:\n +//! NVMEM_WLAN_DRIVER_SP_FILEID, NVMEM_WLAN_FW_SP_FILEID, +//! @param spLength number of bytes to write +//! @param spData SP data to write +//! +//! @return on success 0, error otherwise. +//! +//! @brief program a patch to a specific file ID. +//! The SP data is assumed to be organized in 2-dimensional. +//! Each line is SP_PORTION_SIZE bytes long. Actual programming is +//! applied in SP_PORTION_SIZE bytes portions. +//! +//***************************************************************************** +extern unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const unsigned char *spData); + + +//***************************************************************************** +// +//! nvmem_read_sp_version +//! +//! @param[out] patchVer first number indicates package ID and the second +//! number indicates package build number +//! +//! @return on success 0, error otherwise. +//! +//! @brief Read patch version. read package version (WiFi FW patch, +//! driver-supplicant-NS patch, bootloader patch) +//! +//***************************************************************************** +#ifndef CC3000_TINY_DRIVER +extern unsigned char nvmem_read_sp_version(unsigned char* patchVer); +#endif + +//***************************************************************************** +// +//! nvmem_create_entry +//! +//! @param ulFileId nvmem file Id:\n +//! * NVMEM_AES128_KEY_FILEID: 12 +//! * NVMEM_SHARED_MEM_FILEID: 13 +//! * and fileIDs 14 and 15 +//! @param ulNewLen entry ulLength +//! +//! @return on success 0, error otherwise. +//! +//! @brief Create new file entry and allocate space on the NVMEM. +//! Applies only to user files. +//! Modify the size of file. +//! If the entry is unallocated - allocate it to size +//! ulNewLen (marked invalid). +//! If it is allocated then deallocate it first. +//! To just mark the file as invalid without resizing - +//! set ulNewLen=0. +//! +//***************************************************************************** +extern int8_t nvmem_create_entry(unsigned long file_id, unsigned long newlen); + + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** + + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** + + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // __NVRAM_H__ diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/security.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/security.cpp new file mode 100755 index 0000000000..77aa945cc6 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/security.cpp @@ -0,0 +1,533 @@ +/***************************************************************************** +* +* security.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ + +//***************************************************************************** +// +//! \addtogroup security_api +//! @{ +// +//***************************************************************************** + +#include "security.h" + +#ifndef CC3000_UNENCRYPTED_SMART_CONFIG +// foreward sbox +const unsigned char sbox[256] = { +//0 1 2 3 4 5 6 7 8 9 A B C D E F +0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, //0 +0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, //1 +0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, //2 +0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, //3 +0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, //4 +0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, //5 +0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, //6 +0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, //7 +0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, //8 +0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, //9 +0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, //A +0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, //B +0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, //C +0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, //D +0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, //E +0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; //F +// inverse sbox +const unsigned char rsbox[256] = +{ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb +, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb +, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e +, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25 +, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92 +, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84 +, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06 +, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b +, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73 +, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e +, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b +, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4 +, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f +, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef +, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61 +, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d }; +// round constant +const unsigned char Rcon[11] = { + 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36}; + + +unsigned char expandedKey[176]; + +//***************************************************************************** +// +//! expandKey +//! +//! @param key AES128 key - 16 bytes +//! @param expandedKey expanded AES128 key +//! +//! @return none +//! +//! @brief expend a 16 bytes key for AES128 implementation +//! +//***************************************************************************** + +void expandKey(unsigned char *expandedKey, + unsigned char *key) +{ + unsigned short ii, buf1; + for (ii=0;ii<16;ii++) + expandedKey[ii] = key[ii]; + for (ii=1;ii<11;ii++){ + buf1 = expandedKey[ii*16 - 4]; + expandedKey[ii*16 + 0] = sbox[expandedKey[ii*16 - 3]]^expandedKey[(ii-1)*16 + 0]^Rcon[ii]; + expandedKey[ii*16 + 1] = sbox[expandedKey[ii*16 - 2]]^expandedKey[(ii-1)*16 + 1]; + expandedKey[ii*16 + 2] = sbox[expandedKey[ii*16 - 1]]^expandedKey[(ii-1)*16 + 2]; + expandedKey[ii*16 + 3] = sbox[buf1 ]^expandedKey[(ii-1)*16 + 3]; + expandedKey[ii*16 + 4] = expandedKey[(ii-1)*16 + 4]^expandedKey[ii*16 + 0]; + expandedKey[ii*16 + 5] = expandedKey[(ii-1)*16 + 5]^expandedKey[ii*16 + 1]; + expandedKey[ii*16 + 6] = expandedKey[(ii-1)*16 + 6]^expandedKey[ii*16 + 2]; + expandedKey[ii*16 + 7] = expandedKey[(ii-1)*16 + 7]^expandedKey[ii*16 + 3]; + expandedKey[ii*16 + 8] = expandedKey[(ii-1)*16 + 8]^expandedKey[ii*16 + 4]; + expandedKey[ii*16 + 9] = expandedKey[(ii-1)*16 + 9]^expandedKey[ii*16 + 5]; + expandedKey[ii*16 +10] = expandedKey[(ii-1)*16 +10]^expandedKey[ii*16 + 6]; + expandedKey[ii*16 +11] = expandedKey[(ii-1)*16 +11]^expandedKey[ii*16 + 7]; + expandedKey[ii*16 +12] = expandedKey[(ii-1)*16 +12]^expandedKey[ii*16 + 8]; + expandedKey[ii*16 +13] = expandedKey[(ii-1)*16 +13]^expandedKey[ii*16 + 9]; + expandedKey[ii*16 +14] = expandedKey[(ii-1)*16 +14]^expandedKey[ii*16 +10]; + expandedKey[ii*16 +15] = expandedKey[(ii-1)*16 +15]^expandedKey[ii*16 +11]; + } + +} + +//***************************************************************************** +// +//! galois_mul2 +//! +//! @param value argument to multiply +//! +//! @return multiplied argument +//! +//! @brief multiply by 2 in the galois field +//! +//***************************************************************************** + +unsigned char galois_mul2(unsigned char value) +{ + if (value>>7) + { + value = value << 1; + return (value^0x1b); + } else + return value<<1; +} + +//***************************************************************************** +// +//! aes_encr +//! +//! @param[in] expandedKey expanded AES128 key +//! @param[in/out] state 16 bytes of plain text and cipher text +//! +//! @return none +//! +//! @brief internal implementation of AES128 encryption. +//! straight forward aes encryption implementation +//! first the group of operations +//! - addRoundKey +//! - subbytes +//! - shiftrows +//! - mixcolums +//! is executed 9 times, after this addroundkey to finish the 9th +//! round, after that the 10th round without mixcolums +//! no further subfunctions to save cycles for function calls +//! no structuring with "for (....)" to save cycles. +//! +//! +//***************************************************************************** + +void aes_encr(unsigned char *state, unsigned char *expandedKey) +{ + unsigned char buf1, buf2, buf3, round; + + for (round = 0; round < 9; round ++){ + // addroundkey, sbox and shiftrows + // row 0 + state[ 0] = sbox[(state[ 0] ^ expandedKey[(round*16) ])]; + state[ 4] = sbox[(state[ 4] ^ expandedKey[(round*16) + 4])]; + state[ 8] = sbox[(state[ 8] ^ expandedKey[(round*16) + 8])]; + state[12] = sbox[(state[12] ^ expandedKey[(round*16) + 12])]; + // row 1 + buf1 = state[1] ^ expandedKey[(round*16) + 1]; + state[ 1] = sbox[(state[ 5] ^ expandedKey[(round*16) + 5])]; + state[ 5] = sbox[(state[ 9] ^ expandedKey[(round*16) + 9])]; + state[ 9] = sbox[(state[13] ^ expandedKey[(round*16) + 13])]; + state[13] = sbox[buf1]; + // row 2 + buf1 = state[2] ^ expandedKey[(round*16) + 2]; + buf2 = state[6] ^ expandedKey[(round*16) + 6]; + state[ 2] = sbox[(state[10] ^ expandedKey[(round*16) + 10])]; + state[ 6] = sbox[(state[14] ^ expandedKey[(round*16) + 14])]; + state[10] = sbox[buf1]; + state[14] = sbox[buf2]; + // row 3 + buf1 = state[15] ^ expandedKey[(round*16) + 15]; + state[15] = sbox[(state[11] ^ expandedKey[(round*16) + 11])]; + state[11] = sbox[(state[ 7] ^ expandedKey[(round*16) + 7])]; + state[ 7] = sbox[(state[ 3] ^ expandedKey[(round*16) + 3])]; + state[ 3] = sbox[buf1]; + + // mixcolums ////////// + // col1 + buf1 = state[0] ^ state[1] ^ state[2] ^ state[3]; + buf2 = state[0]; + buf3 = state[0]^state[1]; buf3=galois_mul2(buf3); state[0] = state[0] ^ buf3 ^ buf1; + buf3 = state[1]^state[2]; buf3=galois_mul2(buf3); state[1] = state[1] ^ buf3 ^ buf1; + buf3 = state[2]^state[3]; buf3=galois_mul2(buf3); state[2] = state[2] ^ buf3 ^ buf1; + buf3 = state[3]^buf2; buf3=galois_mul2(buf3); state[3] = state[3] ^ buf3 ^ buf1; + // col2 + buf1 = state[4] ^ state[5] ^ state[6] ^ state[7]; + buf2 = state[4]; + buf3 = state[4]^state[5]; buf3=galois_mul2(buf3); state[4] = state[4] ^ buf3 ^ buf1; + buf3 = state[5]^state[6]; buf3=galois_mul2(buf3); state[5] = state[5] ^ buf3 ^ buf1; + buf3 = state[6]^state[7]; buf3=galois_mul2(buf3); state[6] = state[6] ^ buf3 ^ buf1; + buf3 = state[7]^buf2; buf3=galois_mul2(buf3); state[7] = state[7] ^ buf3 ^ buf1; + // col3 + buf1 = state[8] ^ state[9] ^ state[10] ^ state[11]; + buf2 = state[8]; + buf3 = state[8]^state[9]; buf3=galois_mul2(buf3); state[8] = state[8] ^ buf3 ^ buf1; + buf3 = state[9]^state[10]; buf3=galois_mul2(buf3); state[9] = state[9] ^ buf3 ^ buf1; + buf3 = state[10]^state[11]; buf3=galois_mul2(buf3); state[10] = state[10] ^ buf3 ^ buf1; + buf3 = state[11]^buf2; buf3=galois_mul2(buf3); state[11] = state[11] ^ buf3 ^ buf1; + // col4 + buf1 = state[12] ^ state[13] ^ state[14] ^ state[15]; + buf2 = state[12]; + buf3 = state[12]^state[13]; buf3=galois_mul2(buf3); state[12] = state[12] ^ buf3 ^ buf1; + buf3 = state[13]^state[14]; buf3=galois_mul2(buf3); state[13] = state[13] ^ buf3 ^ buf1; + buf3 = state[14]^state[15]; buf3=galois_mul2(buf3); state[14] = state[14] ^ buf3 ^ buf1; + buf3 = state[15]^buf2; buf3=galois_mul2(buf3); state[15] = state[15] ^ buf3 ^ buf1; + + } + // 10th round without mixcols + state[ 0] = sbox[(state[ 0] ^ expandedKey[(round*16) ])]; + state[ 4] = sbox[(state[ 4] ^ expandedKey[(round*16) + 4])]; + state[ 8] = sbox[(state[ 8] ^ expandedKey[(round*16) + 8])]; + state[12] = sbox[(state[12] ^ expandedKey[(round*16) + 12])]; + // row 1 + buf1 = state[1] ^ expandedKey[(round*16) + 1]; + state[ 1] = sbox[(state[ 5] ^ expandedKey[(round*16) + 5])]; + state[ 5] = sbox[(state[ 9] ^ expandedKey[(round*16) + 9])]; + state[ 9] = sbox[(state[13] ^ expandedKey[(round*16) + 13])]; + state[13] = sbox[buf1]; + // row 2 + buf1 = state[2] ^ expandedKey[(round*16) + 2]; + buf2 = state[6] ^ expandedKey[(round*16) + 6]; + state[ 2] = sbox[(state[10] ^ expandedKey[(round*16) + 10])]; + state[ 6] = sbox[(state[14] ^ expandedKey[(round*16) + 14])]; + state[10] = sbox[buf1]; + state[14] = sbox[buf2]; + // row 3 + buf1 = state[15] ^ expandedKey[(round*16) + 15]; + state[15] = sbox[(state[11] ^ expandedKey[(round*16) + 11])]; + state[11] = sbox[(state[ 7] ^ expandedKey[(round*16) + 7])]; + state[ 7] = sbox[(state[ 3] ^ expandedKey[(round*16) + 3])]; + state[ 3] = sbox[buf1]; + // last addroundkey + state[ 0]^=expandedKey[160]; + state[ 1]^=expandedKey[161]; + state[ 2]^=expandedKey[162]; + state[ 3]^=expandedKey[163]; + state[ 4]^=expandedKey[164]; + state[ 5]^=expandedKey[165]; + state[ 6]^=expandedKey[166]; + state[ 7]^=expandedKey[167]; + state[ 8]^=expandedKey[168]; + state[ 9]^=expandedKey[169]; + state[10]^=expandedKey[170]; + state[11]^=expandedKey[171]; + state[12]^=expandedKey[172]; + state[13]^=expandedKey[173]; + state[14]^=expandedKey[174]; + state[15]^=expandedKey[175]; +} + +//***************************************************************************** +// +//! aes_decr +//! +//! @param[in] expandedKey expanded AES128 key +//! @param[in\out] state 16 bytes of cipher text and plain text +//! +//! @return none +//! +//! @brief internal implementation of AES128 decryption. +//! straight forward aes decryption implementation +//! the order of substeps is the exact reverse of decryption +//! inverse functions: +//! - addRoundKey is its own inverse +//! - rsbox is inverse of sbox +//! - rightshift instead of leftshift +//! - invMixColumns = barreto + mixColumns +//! no further subfunctions to save cycles for function calls +//! no structuring with "for (....)" to save cycles +//! +//***************************************************************************** + +void aes_decr(unsigned char *state, unsigned char *expandedKey) +{ + unsigned char buf1, buf2, buf3; + signed char round; + round = 9; + + // initial addroundkey + state[ 0]^=expandedKey[160]; + state[ 1]^=expandedKey[161]; + state[ 2]^=expandedKey[162]; + state[ 3]^=expandedKey[163]; + state[ 4]^=expandedKey[164]; + state[ 5]^=expandedKey[165]; + state[ 6]^=expandedKey[166]; + state[ 7]^=expandedKey[167]; + state[ 8]^=expandedKey[168]; + state[ 9]^=expandedKey[169]; + state[10]^=expandedKey[170]; + state[11]^=expandedKey[171]; + state[12]^=expandedKey[172]; + state[13]^=expandedKey[173]; + state[14]^=expandedKey[174]; + state[15]^=expandedKey[175]; + + // 10th round without mixcols + state[ 0] = rsbox[state[ 0]] ^ expandedKey[(round*16) ]; + state[ 4] = rsbox[state[ 4]] ^ expandedKey[(round*16) + 4]; + state[ 8] = rsbox[state[ 8]] ^ expandedKey[(round*16) + 8]; + state[12] = rsbox[state[12]] ^ expandedKey[(round*16) + 12]; + // row 1 + buf1 = rsbox[state[13]] ^ expandedKey[(round*16) + 1]; + state[13] = rsbox[state[ 9]] ^ expandedKey[(round*16) + 13]; + state[ 9] = rsbox[state[ 5]] ^ expandedKey[(round*16) + 9]; + state[ 5] = rsbox[state[ 1]] ^ expandedKey[(round*16) + 5]; + state[ 1] = buf1; + // row 2 + buf1 = rsbox[state[ 2]] ^ expandedKey[(round*16) + 10]; + buf2 = rsbox[state[ 6]] ^ expandedKey[(round*16) + 14]; + state[ 2] = rsbox[state[10]] ^ expandedKey[(round*16) + 2]; + state[ 6] = rsbox[state[14]] ^ expandedKey[(round*16) + 6]; + state[10] = buf1; + state[14] = buf2; + // row 3 + buf1 = rsbox[state[ 3]] ^ expandedKey[(round*16) + 15]; + state[ 3] = rsbox[state[ 7]] ^ expandedKey[(round*16) + 3]; + state[ 7] = rsbox[state[11]] ^ expandedKey[(round*16) + 7]; + state[11] = rsbox[state[15]] ^ expandedKey[(round*16) + 11]; + state[15] = buf1; + + for (round = 8; round >= 0; round--){ + // barreto + //col1 + buf1 = galois_mul2(galois_mul2(state[0]^state[2])); + buf2 = galois_mul2(galois_mul2(state[1]^state[3])); + state[0] ^= buf1; state[1] ^= buf2; state[2] ^= buf1; state[3] ^= buf2; + //col2 + buf1 = galois_mul2(galois_mul2(state[4]^state[6])); + buf2 = galois_mul2(galois_mul2(state[5]^state[7])); + state[4] ^= buf1; state[5] ^= buf2; state[6] ^= buf1; state[7] ^= buf2; + //col3 + buf1 = galois_mul2(galois_mul2(state[8]^state[10])); + buf2 = galois_mul2(galois_mul2(state[9]^state[11])); + state[8] ^= buf1; state[9] ^= buf2; state[10] ^= buf1; state[11] ^= buf2; + //col4 + buf1 = galois_mul2(galois_mul2(state[12]^state[14])); + buf2 = galois_mul2(galois_mul2(state[13]^state[15])); + state[12] ^= buf1; state[13] ^= buf2; state[14] ^= buf1; state[15] ^= buf2; + // mixcolums ////////// + // col1 + buf1 = state[0] ^ state[1] ^ state[2] ^ state[3]; + buf2 = state[0]; + buf3 = state[0]^state[1]; buf3=galois_mul2(buf3); state[0] = state[0] ^ buf3 ^ buf1; + buf3 = state[1]^state[2]; buf3=galois_mul2(buf3); state[1] = state[1] ^ buf3 ^ buf1; + buf3 = state[2]^state[3]; buf3=galois_mul2(buf3); state[2] = state[2] ^ buf3 ^ buf1; + buf3 = state[3]^buf2; buf3=galois_mul2(buf3); state[3] = state[3] ^ buf3 ^ buf1; + // col2 + buf1 = state[4] ^ state[5] ^ state[6] ^ state[7]; + buf2 = state[4]; + buf3 = state[4]^state[5]; buf3=galois_mul2(buf3); state[4] = state[4] ^ buf3 ^ buf1; + buf3 = state[5]^state[6]; buf3=galois_mul2(buf3); state[5] = state[5] ^ buf3 ^ buf1; + buf3 = state[6]^state[7]; buf3=galois_mul2(buf3); state[6] = state[6] ^ buf3 ^ buf1; + buf3 = state[7]^buf2; buf3=galois_mul2(buf3); state[7] = state[7] ^ buf3 ^ buf1; + // col3 + buf1 = state[8] ^ state[9] ^ state[10] ^ state[11]; + buf2 = state[8]; + buf3 = state[8]^state[9]; buf3=galois_mul2(buf3); state[8] = state[8] ^ buf3 ^ buf1; + buf3 = state[9]^state[10]; buf3=galois_mul2(buf3); state[9] = state[9] ^ buf3 ^ buf1; + buf3 = state[10]^state[11]; buf3=galois_mul2(buf3); state[10] = state[10] ^ buf3 ^ buf1; + buf3 = state[11]^buf2; buf3=galois_mul2(buf3); state[11] = state[11] ^ buf3 ^ buf1; + // col4 + buf1 = state[12] ^ state[13] ^ state[14] ^ state[15]; + buf2 = state[12]; + buf3 = state[12]^state[13]; buf3=galois_mul2(buf3); state[12] = state[12] ^ buf3 ^ buf1; + buf3 = state[13]^state[14]; buf3=galois_mul2(buf3); state[13] = state[13] ^ buf3 ^ buf1; + buf3 = state[14]^state[15]; buf3=galois_mul2(buf3); state[14] = state[14] ^ buf3 ^ buf1; + buf3 = state[15]^buf2; buf3=galois_mul2(buf3); state[15] = state[15] ^ buf3 ^ buf1; + + // addroundkey, rsbox and shiftrows + // row 0 + state[ 0] = rsbox[state[ 0]] ^ expandedKey[(round*16) ]; + state[ 4] = rsbox[state[ 4]] ^ expandedKey[(round*16) + 4]; + state[ 8] = rsbox[state[ 8]] ^ expandedKey[(round*16) + 8]; + state[12] = rsbox[state[12]] ^ expandedKey[(round*16) + 12]; + // row 1 + buf1 = rsbox[state[13]] ^ expandedKey[(round*16) + 1]; + state[13] = rsbox[state[ 9]] ^ expandedKey[(round*16) + 13]; + state[ 9] = rsbox[state[ 5]] ^ expandedKey[(round*16) + 9]; + state[ 5] = rsbox[state[ 1]] ^ expandedKey[(round*16) + 5]; + state[ 1] = buf1; + // row 2 + buf1 = rsbox[state[ 2]] ^ expandedKey[(round*16) + 10]; + buf2 = rsbox[state[ 6]] ^ expandedKey[(round*16) + 14]; + state[ 2] = rsbox[state[10]] ^ expandedKey[(round*16) + 2]; + state[ 6] = rsbox[state[14]] ^ expandedKey[(round*16) + 6]; + state[10] = buf1; + state[14] = buf2; + // row 3 + buf1 = rsbox[state[ 3]] ^ expandedKey[(round*16) + 15]; + state[ 3] = rsbox[state[ 7]] ^ expandedKey[(round*16) + 3]; + state[ 7] = rsbox[state[11]] ^ expandedKey[(round*16) + 7]; + state[11] = rsbox[state[15]] ^ expandedKey[(round*16) + 11]; + state[15] = buf1; + } + +} + +//***************************************************************************** +// +//! aes_encrypt +//! +//! @param[in] key AES128 key of size 16 bytes +//! @param[in\out] state 16 bytes of plain text and cipher text +//! +//! @return none +//! +//! @brief AES128 encryption: +//! Given AES128 key and 16 bytes plain text, cipher text of 16 bytes +//! is computed. The AES implementation is in mode ECB (Electronic +//! Code Book). +//! +//! +//***************************************************************************** + +void aes_encrypt(unsigned char *state, + unsigned char *key) +{ + // expand the key into 176 bytes + expandKey(expandedKey, key); + aes_encr(state, expandedKey); +} + +//***************************************************************************** +// +//! aes_decrypt +//! +//! @param[in] key AES128 key of size 16 bytes +//! @param[in\out] state 16 bytes of cipher text and plain text +//! +//! @return none +//! +//! @brief AES128 decryption: +//! Given AES128 key and 16 bytes cipher text, plain text of 16 bytes +//! is computed The AES implementation is in mode ECB +//! (Electronic Code Book). +//! +//! +//***************************************************************************** + +void aes_decrypt(unsigned char *state, + unsigned char *key) +{ + expandKey(expandedKey, key); // expand the key into 176 bytes + aes_decr(state, expandedKey); +} + +//***************************************************************************** +// +//! aes_read_key +//! +//! @param[out] key AES128 key of size 16 bytes +//! +//! @return on success 0, error otherwise. +//! +//! @brief Reads AES128 key from EEPROM +//! Reads the AES128 key from fileID #12 in EEPROM +//! returns an error if the key does not exist. +//! +//! +//***************************************************************************** + +signed long aes_read_key(unsigned char *key) +{ + signed long returnValue; + + returnValue = nvmem_read(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE, 0, key); + + return returnValue; +} + +//***************************************************************************** +// +//! aes_write_key +//! +//! @param[out] key AES128 key of size 16 bytes +//! +//! @return on success 0, error otherwise. +//! +//! @brief writes AES128 key from EEPROM +//! Writes the AES128 key to fileID #12 in EEPROM +//! +//! +//***************************************************************************** + +signed long aes_write_key(unsigned char *key) +{ + signed long returnValue; + + returnValue = nvmem_write(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE, 0, key); + + return returnValue; +} + +#endif //CC3000_UNENCRYPTED_SMART_CONFIG + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/security.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/security.h new file mode 100755 index 0000000000..02214272e7 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/security.h @@ -0,0 +1,135 @@ +/***************************************************************************** +* +* security.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef __SECURITY__ +#define __SECURITY__ + +#include "nvmem.h" + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" { +#endif + + +#define AES128_KEY_SIZE 16 + +#ifndef CC3000_UNENCRYPTED_SMART_CONFIG + + +//***************************************************************************** +// +//! aes_encrypt +//! +//! @param[in] key AES128 key of size 16 bytes +//! @param[in\out] state 16 bytes of plain text and cipher text +//! +//! @return none +//! +//! @brief AES128 encryption: +//! Given AES128 key and 16 bytes plain text, cipher text of 16 bytes +//! is computed. The AES implementation is in mode ECB (Electronic +//! Code Book). +//! +//! +//***************************************************************************** +extern void aes_encrypt(unsigned char *state, unsigned char *key); + +//***************************************************************************** +// +//! aes_decrypt +//! +//! @param[in] key AES128 key of size 16 bytes +//! @param[in\out] state 16 bytes of cipher text and plain text +//! +//! @return none +//! +//! @brief AES128 decryption: +//! Given AES128 key and 16 bytes cipher text, plain text of 16 bytes +//! is computed The AES implementation is in mode ECB +//! (Electronic Code Book). +//! +//! +//***************************************************************************** +extern void aes_decrypt(unsigned char *state, unsigned char *key); + + +//***************************************************************************** +// +//! aes_read_key +//! +//! @param[out] key AES128 key of size 16 bytes +//! +//! @return on success 0, error otherwise. +//! +//! @brief Reads AES128 key from EEPROM +//! Reads the AES128 key from fileID #12 in EEPROM +//! returns an error if the key does not exist. +//! +//! +//***************************************************************************** +extern signed long aes_read_key(unsigned char *key); + +//***************************************************************************** +// +//! aes_write_key +//! +//! @param[out] key AES128 key of size 16 bytes +//! +//! @return on success 0, error otherwise. +//! +//! @brief writes AES128 key from EEPROM +//! Writes the AES128 key to fileID #12 in EEPROM +//! +//! +//***************************************************************************** +extern signed long aes_write_key(unsigned char *key); + +#endif //CC3000_UNENCRYPTED_SMART_CONFIG + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/sntp.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/sntp.cpp new file mode 100755 index 0000000000..52612c1235 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/sntp.cpp @@ -0,0 +1,673 @@ +// +// +// + +#include "sntp.h" + +//Lists of pool servers + + +const char* ntp_us_pool_list[] = { "0.us.pool.ntp.org", + "1.us.pool.ntp.org", + "2.us.pool.ntp.org", + "3.us.pool.ntp.org", + "0.north-america.pool.ntp.org", + "1.north-america.pool.ntp.org", + "2.north-america.pool.ntp.org", + "3.north-america.pool.ntp.org", + NULL + }; + +const char* ntp_global_pool_list[] = { "0.pool.ntp.org", + "1.pool.ntp.org", + "2.pool.ntp.org", + "pool.ntp.org", + NULL + }; + +// ExtractNTPTime - convert ntp seconds into calendar time +// Notes: +// - 1900 was NOT a leap-year. +// - This routine deals with the overflow of the 32-bit seconds value, +// which will happen on 02/07/2036 at 06:28:16. +// + +#define SECS_DAY (24L * 60 * 60) /* number of seconds in a day */ +#define BASE_YEAR (1900) /* NTP time starts at 1/1/1900 00:00:00 */ + +#define FIX_PT_DAYS_YEAR ((365L * 256) + (256 / 4)) +// It may not look that way, but this is (365.25 * 256) +// That is, it's (365 * 256) + (0.25 * 256) = (365.25 * 256). Why are we doing this? +// There are 365 days in a year. After you factor out seconds in the current day, +// you're left with days since 1/1/1900. Dividing by 365 would therefore give you +// the number of years since 1900, if it wasn't for leap years. If you include +// leap-years, you get 365.25 days per year. So, we have to divide ntp days by 365.25 +// to get the proper year. Instead of doing a floating point divide by 365.25, we do +// fixed point arithmetic, placing the binary-point at 8 bits (i.e., 256 decimal). +//There's only one small fly in this ointment - 1900 was not a leap year. +// Fortunately, we can compensate by adding 1 to the NTP days, as if 1900 WAS a +// leap-year. When we divide days down to years, the extra day is lost in +// the roundoff. Problem solved. + +// days in each month: {jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec}; +char monthDays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + +#ifdef CLOCK_DEBUG + void dumpBlock1(char* buf, short len) /*rdl 2/16/2008*/ + { + uint8_t* offset = (uint8_t*)buf; + int16_t count = 0; + int lineCount = 0; + char ascii[17] = ""; + char* pAscii = ascii; + + delay(10); + if (CC3KPrinter != 0) { CC3KPrinter->print(F("Block: (addr ")); CC3KPrinter->print((uint16_t)buf, HEX); CC3KPrinter->print(F(", length ")); CC3KPrinter->print(len, HEX); } + // traceFn("Block: (addr %p, length 0x%04x)", buf, len); + + while (count < len) + { + if (CC3KPrinter != 0) { CC3KPrinter->println(); CC3KPrinter->print((uint16_t)offset,HEX); CC3KPrinter->print(F(": ")); } + // traceFn("\r\n %p: ", offset); + lineCount = 0; + pAscii = (char*)&ascii; + memset(ascii,' ',16); + while ((count < len) && (lineCount < 8)) + { + if ((*offset <= ' ') || (*offset == 0xFF)) *pAscii++ = '.'; else *pAscii++ = *offset; *pAscii++ = ' '; + if (CC3KPrinter != 0) { CC3KPrinter->print((*offset)>>4,HEX); CC3KPrinter->print((*offset++)&0x0F,HEX); CC3KPrinter->print(F(" ")); } + // traceFn("0x%02bx ", *offset++); + count++; + lineCount++; + } + while (lineCount++ < 8) + { + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" ")); } + // traceFn(" "); + } + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" | ")); CC3KPrinter->print(ascii); CC3KPrinter->print(F("|")); } + // traceFn(" | %s|", ascii); + delay(10); + } + if (CC3KPrinter != 0) { CC3KPrinter->println(); } + // traceFn("\r\n"); + } +#endif + +//Calculates (time / 2) for NTP timestamp values (64-bit fixed point, normalized to 32-bit) +// ORIGINAL VALUE OF time IS DESTROYED, and replaced with result of calculation. +// performs a signed divide +void NTPdiv2(SNTP_Timestamp_t* time) +{ + uint32_t carry = time->seconds & 1; //this bit will shift from 'seconds' to 'fraction' + time->fraction >>= 1; //divide 'fraction' by 2 + time->fraction |= carry << 31; //OR in the low bit of 'seconds' as the high bit of 'fraction + time->seconds >>= 1; //signed divide of 'seconds' by 2 +} + +//Calculates (time1 + time2) for NTP timestamp values (64-bit fixed point, normalized to 32-bit) +// ORIGINAL VALUE OF time2 IS DESTROYED, and replaced with result of calculation. +// Returns overflow +uint8_t AddNTPtime(SNTP_Timestamp_t* time1, SNTP_Timestamp_t* time2) +{ + uint8_t carry = ((time2->fraction>>1)+(time1->fraction>>1) & 0x80000000)>>31; + time2->fraction += time1->fraction; + time2->seconds += carry; + carry = ((time2->seconds>>1)+(time1->seconds>>1) & 0x80000000)>>31; + time2->seconds += time1->seconds; + return carry; //if there's still a carry, then we have an overflow. +} + +//Calculates (time2 - time1) for NTP timestamp values (64-bit fixed point, normalized to 32-bit) +// ORIGINAL VALUE OF time2 IS DESTROYED, and replaced with result of calculation. +// Returns underflow +uint8_t DiffNTPtime(SNTP_Timestamp_t* time1, SNTP_Timestamp_t* time2) +{ + uint8_t borrow = ((time2->fraction>>1)-(time1->fraction>>1) & 0x80000000)>>31; + time2->fraction -= time1->fraction; + time2->seconds -= borrow; + borrow = ((time2->seconds>>1)-(time1->seconds>>1) & 0x80000000)>>31; + time2->seconds -= time1->seconds; + return borrow; //if there's still a borrow, then we have an underflow. +} + +int sntp::GetSystemClockAsNTPTime(SNTP_Timestamp_t* ntpSystemTime) +{ + long systemMillis; + + if (ntpSystemTime) + { + ntpSystemTime->seconds = millis() / 1000; + systemMillis = millis() - (ntpSystemTime->seconds * 1000); + systemMillis = (systemMillis << 10) / 1000; + ntpSystemTime->fraction = systemMillis << 22; + } + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" GetSystemClockAsNTPTime: ")); CC3KPrinter->print(ntpSystemTime->seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(ntpSystemTime->fraction,HEX); } + #endif + return 0; +} + + +SNTP_Timestamp_t* sntp::NTPGetTime(SNTP_Timestamp_t* ntpTime, bool local) +{ + SNTP_Timestamp_t ntpSystemTime; + + if (ntpTime) + { + GetSystemClockAsNTPTime(&ntpSystemTime); + + *ntpTime = m_NTPReferenceTime; + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" NTPGetTime m_NTPReferenceTime: ")); CC3KPrinter->print(ntpTime->seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(ntpTime->fraction,HEX); } + #endif + + AddNTPtime(&ntpSystemTime, ntpTime); + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" NTPGetTime NTP Current UTC: ")); CC3KPrinter->print(ntpTime->seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(ntpTime->fraction,HEX); } + #endif + + if (local) //if true, add in local offset from UTC + { + AddNTPtime(m_cur_UTC_offset, ntpTime); + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" NTPGetTime NTP Current Local: ")); CC3KPrinter->print(ntpTime->seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(ntpTime->fraction,HEX); } + #endif + } + } + return ntpTime; +} + +SNTP_Timestamp_t* sntp::NTPSetTime(SNTP_Timestamp_t* ntpTime, bool local) +{ + SNTP_Timestamp_t ntpSystemTime; + + if (ntpTime) + { + if (local) + { + DiffNTPtime(m_cur_UTC_offset, ntpTime); //take out local offset to set clock as UTC + } + + GetSystemClockAsNTPTime(&ntpSystemTime); + + m_NTPReferenceTime = *ntpTime; + DiffNTPtime(&ntpSystemTime, &m_NTPReferenceTime); + + m_timeIsSet = true; + } + return ntpTime; +} + +NetTime_t *sntp::ExtractNTPTime(/*in*/ SNTP_Timestamp_t *ntpTime, /*out*/ NetTime_t *extractedTime) +{ + + uint32_t time = ntpTime->seconds; + uint32_t dayclock, dayno; + int year; + char month; + int day; + bool dateOverflow = (0 == (time & 0x80000000)); //32-bit counter overflowed? + + extractedTime->millis = ((ntpTime->fraction >>22) * 1000) >>10; + + dayclock = time % SECS_DAY; //seconds since midnight + dayno = time / SECS_DAY; //days since 1/1/1900 (or since 2/7/2036) + + #ifdef CLOCK_DEEP_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("dayclock = ")); CC3KPrinter->print(dayclock); CC3KPrinter->print(F("dayno = ")); CC3KPrinter->println(dayno); } + #endif + + if (dateOverflow) //if the date overflowed, we'll effectively add the overflowed bit + { // back into dayno and dayclock. They've got plenty of room for it now + dayclock = (dayclock + 23296); //new zero-point for dayclock is 06:28:16 + dayno += 49710; //new zero-point for dayno is 02/07/2036 + dayno += (dayclock / SECS_DAY); // PLUS 6:28:16, or 49710 days, 23296 seconds since 1/1/1900 00:00:00 + dayclock %= SECS_DAY; // get rid of any overflow (we already added it to dayno in previous line) + + #ifdef CLOCK_DEEP_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" date overflow: dayclock =")); CC3KPrinter->print(dayclock); CC3KPrinter->print(F("dayno = ")); CC3KPrinter->println(dayno); } + #endif + + } + + extractedTime->sec = dayclock % 60; //seconds in current minute + extractedTime->min = (dayclock % 3600) / 60; //minutes in current hour + extractedTime->hour = dayclock / 3600; //hours in current day + extractedTime->wday = (dayno + 1) % 7; //days since Sunday (0..6). Biased since 1/1/1900 was a thursday + + dayno += 1; //No leap-year in 1900, as there should have been. This throws off the + // calculation of year = dayno / 365.25. So we add one to line things back + // up again, just for the year calculation. + + dayno <<= 8; //fixed point arithmetic - multiply by 256 so we can do an integer divide by + year = (dayno / FIX_PT_DAYS_YEAR) + BASE_YEAR; // (365.25 * 256)instead of doing a floating-point divide by 365.25 + + #ifdef CLOCK_DEEP_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(year); CC3KPrinter->print(F(" = (")); CC3KPrinter->print(dayno); CC3KPrinter->print(F(" // ")); CC3KPrinter->print(FIX_PT_DAYS_YEAR); CC3KPrinter->print(F(") + ")); CC3KPrinter->println(BASE_YEAR); } + #endif + + extractedTime->year = year; + dayno = (dayno % FIX_PT_DAYS_YEAR) >> 8; + + extractedTime->yday = dayno; + + //if year is evenly divisible by 4, it's a leap-year, except for 1900. Change February days in table accordingly + monthDays[1] = ((0 == (year & 3)) && (1900 != year))? 29 : 28; + + //Now, we're going to loop through the month table, subtracting days from dayno until dayno goes negative + // that will give us the current month + day = (int)dayno; + month = 0; + while (0 <= day) + day-= monthDays[month++]; + + month -= 1; //we need to return month as zero-based. Phooey! + extractedTime->mon = month; + extractedTime->mday = day + monthDays[month] + 1; //Since we looped until days went negative, we need add back in days in current month + + extractedTime->isdst = 0; //currently ignored. + + #ifdef CLOCK_DEEP_DEBUG + dumpBlock1((char*)extractedTime, sizeof(NetTime_t)); + #endif + + return extractedTime; +} + +//bool GetGatewayAddress(char* gatewayAddr) +//{ + //bool success = false; + //tNetappIpconfigRetArgs ipconfig; + //netapp_ipconfig(&ipconfig); +// + ///* If byte 1 is 0 we don't have a valid address */ + //if (ipconfig.aucIP[3] != 0) + //{ + //snprintf(gatewayAddr, MAX_URL_NAME, "%d.%d.%d.%d",ipconfig.aucIP+11,ipconfig.aucIP+10,ipconfig.aucIP+9,ipconfig.aucIP+8); + //success = true; + //} + //return success; +//} + +sntp::sntp() +{ + m_localPool = ntp_us_pool_list; + m_globalPool = ntp_global_pool_list; + + m_NTPReferenceTime.seconds = 0X80000000; //initial base time for real-time clock (1/20/1968 03:14:08) + m_NTPReferenceTime.fraction = 0; + + m_std_UTC_offset.seconds = 0; //Local standard-time offset from UTC. Example: Eastern Standard is UTC - 5 hours + m_std_UTC_offset.fraction = 0; + m_dst_UTC_offset.seconds = 0; //Local daylight-savings-time offset from UTC. Ex: Eastern Daylght is UTC - 4 hours + m_dst_UTC_offset.fraction = 0; + m_cur_UTC_offset = &m_std_UTC_offset; //Current offset from UTC. Pointer to either std_UTC_offset or dst_UTC_offset + m_twelveHour = false; //use 12-hour time when true, 24-hour time when false + m_enable_dst = false; //enable daylight savings time + + //GetGatewayAddress((char*)&m_userServerStrings[1]); + //m_userServers[0] = (char*)&m_userServerStrings[1]; +} + +sntp::sntp(char* ntp_server_url1, char* ntp_server_url2, short local_utc_offset, short dst_utc_offset, bool enable_dst) +{ + int user_server_count = 0; + + sntp(); + + m_std_UTC_offset.seconds = (uint32_t)(60L * local_utc_offset); + m_dst_UTC_offset.seconds = (uint32_t)(60L * dst_utc_offset); + m_cur_UTC_offset = &m_dst_UTC_offset; + m_enable_dst = enable_dst; + if (ntp_server_url1) + { + strncpy((char*)&m_userServerStrings[user_server_count], ntp_server_url1, MAX_URL_NAME); + m_userServers[user_server_count] = (char*)&m_userServerStrings[user_server_count]; + user_server_count++; + } + if (ntp_server_url2) + { + strncpy((char*)&m_userServerStrings[user_server_count], ntp_server_url2, MAX_URL_NAME); + m_userServers[user_server_count] = (char*)&m_userServerStrings[user_server_count]; + user_server_count++; + } +} +sntp::sntp(char* ntp_server_url1, short local_utc_offset) +{ + sntp(ntp_server_url1, NULL, local_utc_offset, 0, false); +} +sntp::sntp(char* ntp_server_url1, char* ntp_server_url2, short local_utc_offset) +{ + sntp(ntp_server_url1, ntp_server_url2, local_utc_offset, 0, false); +} +sntp::sntp(char* ntp_server_url1, short local_utc_offset, short dst_utc_offset, bool enable_dst) +{ + sntp(ntp_server_url1, NULL, local_utc_offset, dst_utc_offset, enable_dst); +} + +//To spread the load of NTP client request, ntp.org maintains DNS servers that will return a list of +// available NTP servers from a pool. This routine gets a list of servers from the specified pool +// and returns it, along with a count of the servers in the list. +char sntp::GetNTPServerList(const char** ntp_pool_list, uint32_t* addrBuffer, int maxServerCount) +{ + uint32_t ntpServer= NULL; + const char **ntpPoolName; + uint8_t serverCount = 0; + + if ((ntp_pool_list) && (addrBuffer)) + { + ntpPoolName = ntp_pool_list; + while ((*ntpPoolName) && (!ntpServer)) + { + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("Checking NTP server/pool address ")); CC3KPrinter->println(*ntpPoolName); } + #endif + + gethostbyname(*ntpPoolName, strlen(*ntpPoolName), &ntpServer); + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" returns ntpServer: ")); CC3KPrinter->println(ntpServer,HEX); } + #endif + + ntpPoolName++; + } + if (ntpServer) + { + *addrBuffer = ntpServer; + serverCount += 1; + } + + } + return serverCount; +} + + +//Called by task to poll specific NTP server for current time. +bool sntp::SNTP_GetTime(int sntpSocket, uint32_t *ntpServerAddr) +{ + sockaddr_in socketAddr; + socklen_t sockLen; + int32_t recvTimeout = 30000; + int8_t byteCount; + SNTP_Timestamp_t tsDestination; + bool result = false; + SNTP_Message_t sntp_message; // sntp message buffer + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->println(F("SNTP_GetTime")); } + #endif + + // set the ntp server address and port + memset(&socketAddr, 0, sizeof(sockaddr_in)); + socketAddr.sin_family = AF_INET; + memcpy(&(socketAddr.sin_addr), ntpServerAddr, 4); + socketAddr.sin_port = htons(SNTP_PORT); + + //Prepare the outgoing ntp request packet + memset(&sntp_message, 0, sizeof(SNTP_Message_t)); //zero the outgoing message + sntp_message.mode = client; // NTP client request + sntp_message.VN = 3; // NTP version 3 + NTPGetTime(&sntp_message.tsTransmit, false); //transmitting at current UTC time + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("SNTP sendto server ")); CC3KPrinter->println(socketAddr.sin_addr.s_addr,HEX); } + dumpBlock1((char*)&sntp_message, sizeof(SNTP_Message_t)); + #endif + + sockLen = sizeof(sockaddr_in); + byteCount = sendto(sntpSocket, &sntp_message, sizeof(SNTP_Message_t), 0, (sockaddr*)&socketAddr, sockLen); + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("sendto transmitted ")); CC3KPrinter->print(byteCount,HEX); CC3KPrinter->println(F(" bytes")); } + #endif + + if (sizeof(SNTP_Message_t) == byteCount) + { + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->println(F("Waiting for response")); } + #endif + + setsockopt(sntpSocket, SOL_SOCKET, SOCKOPT_RECV_TIMEOUT, &recvTimeout, (socklen_t)sizeof(recvTimeout)); + sockLen = sizeof(sockaddr_in); + byteCount = recvfrom(sntpSocket, &sntp_message, sizeof(SNTP_Message_t), 0, (sockaddr*)&socketAddr, &sockLen); + + //tsDestination = UTC time when we received reply + NTPGetTime(&tsDestination, false); + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("SNTP received ")); CC3KPrinter->print(byteCount); CC3KPrinter->println(F(" bytes")); } + #endif + + //If we got a good response packet, go ahead and calculate the current time. + // This is done according the the following equation: + // ((Receive time - Originate Time) + (Transmit Time - Destination Time)) / 2 + if (sizeof(SNTP_Message_t) == byteCount) + { + //Change the byte order of the received timestamps to big-endian + sntp_message.tsReceive.seconds = htonl(sntp_message.tsReceive.seconds); + sntp_message.tsReceive.fraction = htonl(sntp_message.tsReceive.fraction); + sntp_message.tsTransmit.seconds = htonl(sntp_message.tsTransmit.seconds); + sntp_message.tsTransmit.fraction = htonl(sntp_message.tsTransmit.fraction); + //we don't use tsReference for anything, so don't bother swapping it. + // sntp_message.tsReference.seconds = htonl(sntp_message.tsReference.seconds); + // sntp_message.tsReference.fraction = htonl(sntp_message.tsReference.fraction); + + + #ifdef CLOCK_DEBUG + dumpBlock1((char*)&sntp_message, sizeof(SNTP_Message_t)); + if (CC3KPrinter != 0) { CC3KPrinter->println(F("Received at ")); } + dumpBlock1((char*)&tsDestination, sizeof(tsDestination)); + #endif + + //Formula is: correction = ((tsReceive-tsOriginate)/2) + ((tsTransmit-tsDestination)/2) + // + //Server received request at tsReceive, we sent request at tsOriginate + DiffNTPtime(&sntp_message.tsOriginate, &sntp_message.tsReceive); + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" (R - O): ")); CC3KPrinter->print(sntp_message.tsReceive.seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(sntp_message.tsReceive.fraction,HEX); } + #endif + NTPdiv2(&sntp_message.tsReceive); + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" (R - O)/2: ")); CC3KPrinter->print(sntp_message.tsReceive.seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(sntp_message.tsReceive.fraction,HEX); } + #endif + + //Server sent reply at tsTransmit, we received reply at tsDestination + DiffNTPtime(&tsDestination, &sntp_message.tsTransmit); + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" (T - D): ")); CC3KPrinter->print(sntp_message.tsTransmit.seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(sntp_message.tsTransmit.fraction,HEX); } + #endif + NTPdiv2(&sntp_message.tsTransmit); + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" (T - D)/2: ")); CC3KPrinter->print(sntp_message.tsTransmit.seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(sntp_message.tsTransmit.fraction,HEX); } + #endif + + //Correction is returned in tsTransmit + AddNTPtime(&sntp_message.tsReceive, &sntp_message.tsTransmit); + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" Offset: ")); CC3KPrinter->print(sntp_message.tsTransmit.seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(sntp_message.tsTransmit.fraction,HEX); } + #endif + + //Add correction to current ntp reference time + AddNTPtime(&sntp_message.tsTransmit, &m_NTPReferenceTime); //adjust NTP reference time + m_timeIsSet = true; + + #ifdef CLOCK_DEBUG + NTPGetTime(&tsDestination, false); //we'll display local time + if (CC3KPrinter != 0) { CC3KPrinter->print(F(" time is ")); CC3KPrinter->print(tsDestination.seconds,HEX); CC3KPrinter->print(F(".")); CC3KPrinter->println(tsDestination.fraction,HEX); } + #endif + + result = true; + } + } + return result; +} + +bool sntp::UpdateNTPTime() +{ + bool portIsBound = false; + int sntpSocket; + sockaddr_in socketAddr; + uint16_t localPort; + NTP_Pool_t ntp_pool_list; // list of NTP server pools + NTP_Server_List_t *pServerList; // pointer to list of ntp servers returned by a server pool + NTP_Server_List_t ntp_server_list; // local buffer for list of ntp servers returned by a server pool + uint8_t ntp_server_count; // number of ntp servers in ntp_server_list + bool checkLocal; // true if we haven't searched the local NTP server list. + bool checkGlobal; // true if we haven't searched the global NTP server list. + + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->println(F("sntp.update")); } + #endif + + sntpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (sntpSocket >= 0) //got one? + { + while (!portIsBound) + { //set up the sockAddr + + memset(&socketAddr, 0, sizeof(sockaddr_in)); //zero it + localPort = (uint16_t)random(0xC000, 0xFFFF); //generate random port number in range C000-FFFF + socketAddr.sin_family = AF_INET; //IP version 4 + socketAddr.sin_addr.s_addr = 0; //local socket address + socketAddr.sin_port = htons(localPort); //well-known NTP port number, assigned by IANA + // bind the socket to the local port + portIsBound = (0 == bind(sntpSocket, (sockaddr*)&socketAddr, sizeof(sockaddr_in))); + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("local: ")); CC3KPrinter->print(socketAddr.sin_addr.s_addr, HEX); CC3KPrinter->print(F(": ")); CC3KPrinter->println(socketAddr.sin_port, HEX); } + #endif + } + + if (portIsBound) + { + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("Init SNTP bind socket ")); CC3KPrinter->print(sntpSocket); CC3KPrinter->print(F("to port ")); CC3KPrinter->print(socketAddr.sin_port); CC3KPrinter->println(F(" succeeded")); } + #endif + + m_change_DST = 0; + m_timeIsSet = false; + + while (!m_timeIsSet) //stay here until we either get a time, or run out of servers + { + //start with user's NTP servers. These may not be pool servers, so they'll only get one IP address from DNS + ntp_pool_list = m_userServers; //start with user's ntp server list + m_localPool = ntp_us_pool_list; + m_globalPool = ntp_global_pool_list; + checkLocal = (NULL != m_localPool); // if that craps out, we'll try the local server-pool list + checkGlobal = (NULL != m_globalPool); //if that craps out, we'll try the global server-pool list + #ifdef CLOCK_DEEP_DEBUG + if (CC3KPrinter != 0) + { + CC3KPrinter->print(F("m_localPool: ")); CC3KPrinter->print(*m_localPool); CC3KPrinter->print(F("checkLocal: ")); CC3KPrinter->println(checkLocal); + CC3KPrinter->print(F("m_globalPool: ")); CC3KPrinter->print(*m_globalPool); CC3KPrinter->print(F("checkGlobal: ")); CC3KPrinter->println(checkGlobal); + } + #endif + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("try user's ntp server list: ")); CC3KPrinter->println((uint32_t)*ntp_pool_list); } + #endif + + memset(&ntp_server_list, 0, sizeof(NTP_Server_List_t)); + pServerList = &ntp_server_list; //server ip addresses returned here + + while ((!m_timeIsSet) && (pServerList)) + { + //try to get a server list. + ntp_server_count = GetNTPServerList(ntp_pool_list, (uint32_t*)pServerList, MAX_NTP_SERVERS); // Just returns if pServerList is NULL + #ifdef CLOCK_DEEP_DEBUG + dumpBlock1((char*)pServerList, ntp_server_count * sizeof(uint32_t)); + #endif + + int i = 0; + while ((!m_timeIsSet) && (i++ < ntp_server_count) && (pServerList)) + { + uint32_t serverAddr = htonl(*(uint32_t*)pServerList++); + m_timeIsSet = SNTP_GetTime(sntpSocket, &serverAddr); + } + + if (!m_timeIsSet) + { + pServerList = &ntp_server_list; //reset pServerList pointer + + if (checkLocal) + { + ntp_pool_list = m_localPool; //try local ntp server pool list ('local' means 'regional', e.g., US, North America, etc) + checkLocal = false; + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("try local ntp_pool_list: ")); CC3KPrinter->println((uint32_t)*ntp_pool_list); } + #endif + } + else + { + if (checkGlobal) + { + ntp_pool_list = m_globalPool; //now try global (i.e., default) ntp server pool list + checkGlobal = false; + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) { CC3KPrinter->print(F("try global ntp_pool_list: ")); CC3KPrinter->println((uint32_t)*ntp_pool_list); } + #endif + } + else + { + pServerList = NULL; //rats. came up empty. This will get us out of the loop + ntp_server_count = 0; + + } //else not checkGlobal + } //else not checkLocal + } //if (!m_timeIsSet) + } //while ((!m_timeIsSet) && (pServerList)) + + if (m_timeIsSet) + { +// //If necessary, make change to/from Daylight Savings Time +// // NOTE: m_change_DST will have been set on the previous iteration of the loop, so that +// // we update the time AFTER we wake up. This is because the timer will have been adjusted +// // to wake up when the time-change happens +// // 'm_change_DST' is tri-state: 0 or no change, +1 for spring change, -1 for fall change. +// UpdateDST(m_change_DST); +// +// //Now, see if the time change will happen before the next scheduled wake-up. +// // If so, shorten sleep-time so we wake up at the time-change +// TaskLock(&Clock.lock); +// m_change_DST = Check_DST(NTPGetTime(&m_tempTS, false), &m_sleepTime); //if necessary, shortens m_sleepTime so we wake up at the time-change +// TaskUnlock(&Clock.lock); // Also makes sure current DST settings are correct. +// +// strBufLen = 32; +// Trace("The time is now %s\r\n", FormatFullNTPtime(NTPGetTime(&m_tempTS, true), strBuf, &strBufLen, true)); +// +// + } + } // while (!m_timeIsSet) + closesocket(sntpSocket); + sntpSocket = -1; + } //if (portIsBound) + else //socket bind failed + { + if (CC3KPrinter != 0) { CC3KPrinter->print(F("Init SNTP bind socket ")); CC3KPrinter->print(sntpSocket); CC3KPrinter->print(F("to port ")); CC3KPrinter->print(SNTP_PORT); CC3KPrinter->println(F("failed")); } + closesocket(sntpSocket); + sntpSocket = -1; + } + } //if (sntpSocket >= 0) + else // didn't get a socket + { + if (CC3KPrinter != 0) { CC3KPrinter->println(F("Failed to get a socket")); } + } + #ifdef CLOCK_DEBUG + if (CC3KPrinter != 0) + { + CC3KPrinter->println(F("exit sntp.update")); + CC3KPrinter->print(F("m_std_UTC_offset.seconds: ")); CC3KPrinter->println(m_std_UTC_offset.seconds, HEX); + CC3KPrinter->print(F("m_dst_UTC_offset.seconds: ")); CC3KPrinter->println(m_dst_UTC_offset.seconds, HEX); + } + #endif + return m_timeIsSet; +} + + + +//sntp SNTP; + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/sntp.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/sntp.h new file mode 100755 index 0000000000..458219a28e --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/sntp.h @@ -0,0 +1,409 @@ +// sntp.h + +#ifndef _SNTP_h +#define _SNTP_h +// Notes on NTP packet format from IETF RFC-2030, SNTP Specification (http://www.ietf.org/rfc/rfc2030.txt?number=2030) : +// +//NTP Timestamp Format +// +// SNTP uses the standard NTP timestamp format described in RFC-1305 and +// previous versions of that document. In conformance with standard +// Internet practice, NTP data are specified as integer or fixed-point +// quantities, with bits numbered in big-endian fashion from 0 starting +// at the left, or high-order, position. Unless specified otherwise, all +// quantities are unsigned and may occupy the full field width with an +// implied 0 preceding bit 0. +// +// Since NTP timestamps are cherished data and, in fact, represent the +// main product of the protocol, a special timestamp format has been +// established. NTP timestamps are represented as a 64-bit unsigned +// fixed-point number, in seconds relative to 0h on 1 January 1900. The +// integer part is in the first 32 bits and the fraction part in the +// last 32 bits. In the fraction part, the non-significant low order can +// be set to 0. +// +// It is advisable to fill the non-significant low order bits of the +// timestamp with a random, unbiased bitstring, both to avoid +// systematic roundoff errors and as a means of loop detection and +// replay detection (see below). One way of doing this is to generate +// a random bitstring in a 64-bit word, then perform an arithmetic +// right shift a number of bits equal to the number of significant +// bits of the timestamp, then add the result to the original +// timestamp. +// +// +// +// +//Mills Informational [Page 6] +// +//RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996 +// +// +// This format allows convenient multiple-precision arithmetic and +// conversion to UDP/TIME representation (seconds), but does complicate +// the conversion to ICMP Timestamp message representation, which is in +// milliseconds. The maximum number that can be represented is +// 4,294,967,295 seconds with a precision of about 200 picoseconds, +// which should be adequate for even the most exotic requirements. +// +// 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Seconds | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Seconds Fraction (0-padded) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// Note that, since some time in 1968 (second 2,147,483,648) the most +// significant bit (bit 0 of the integer part) has been set and that the +// 64-bit field will overflow some time in 2036 (second 4,294,967,296). +// Should NTP or SNTP be in use in 2036, some external means will be +// necessary to qualify time relative to 1900 and time relative to 2036 +// (and other multiples of 136 years). There will exist a 200-picosecond +// interval, henceforth ignored, every 136 years when the 64-bit field +// will be 0, which by convention is interpreted as an invalid or +// unavailable timestamp. +// +// As the NTP timestamp format has been in use for the last 17 years, +// it remains a possibility that it will be in use 40 years from now +// when the seconds field overflows. As it is probably inappropriate +// to archive NTP timestamps before bit 0 was set in 1968, a +// convenient way to extend the useful life of NTP timestamps is the +// following convention: If bit 0 is set, the UTC time is in the +// range 1968-2036 and UTC time is reckoned from 0h 0m 0s UTC on 1 +// January 1900. If bit 0 is not set, the time is in the range 2036- +// 2104 and UTC time is reckoned from 6h 28m 16s UTC on 7 February +// 2036. Note that when calculating the correspondence, 2000 is not a +// leap year. Note also that leap seconds are not counted in the +// reckoning. +// +//4. NTP Message Format +// +// Both NTP and SNTP are clients of the User Datagram Protocol (UDP) +// [POS80], which itself is a client of the Internet Protocol (IP) +// [DAR81]. The structure of the IP and UDP headers is described in the +// cited specification documents and will not be detailed further here. +// The UDP port number assigned to NTP is 123, which should be used in +// both the Source Port and Destination Port fields in the UDP header. +// The remaining UDP header fields should be set as described in the +// specification. +// +// +// +//Mills Informational [Page 7] +// +//RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996 +// +// +// Below is a description of the NTP/SNTP Version 4 message format, +// which follows the IP and UDP headers. This format is identical to +// that described in RFC-1305, with the exception of the contents of the +// reference identifier field. The header fields are defined as follows: +// +// 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |LI | VN |Mode | Stratum | Poll | Precision | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Root Delay | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Root Dispersion | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Reference Identifier | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// | Reference Timestamp (64) | +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// | Originate Timestamp (64) | +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// | Receive Timestamp (64) | +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// | Transmit Timestamp (64) | +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Key Identifier (optional) (32) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// | | +// | Message Digest (optional) (128) | +// | | +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// As described in the next section, in SNTP most of these fields are +// initialized with pre-specified data. For completeness, the function +// of each field is briefly summarized below. +// +// +// Leap Indicator (LI): This is a two-bit code warning of an impending +// leap second to be inserted/deleted in the last minute of the current +// day, with bit 0 and bit 1, respectively, coded as follows: +// +// LI Value Meaning +// ------------------------------------------------------- +// 00 0 no warning +// 01 1 last minute has 61 seconds +// 10 2 last minute has 59 seconds) +// 11 3 alarm condition (clock not synchronized) +// +// Version Number (VN): This is a three-bit integer indicating the +// NTP/SNTP version number. The version number is 3 for Version 3 (IPv4 +// only) and 4 for Version 4 (IPv4, IPv6 and OSI). If necessary to +// distinguish between IPv4, IPv6 and OSI, the encapsulating context +// must be inspected. +// +// Mode: This is a three-bit integer indicating the mode, with values +// defined as follows: +// +// Mode Meaning +// ------------------------------------ +// 0 reserved +// 1 symmetric active +// 2 symmetric passive +// 3 client +// 4 server +// 5 broadcast +// 6 reserved for NTP control message +// 7 reserved for private use +// +// In unicast and anycast modes, the client sets this field to 3 +// (client) in the request and the server sets it to 4 (server) in the +// reply. In multicast mode, the server sets this field to 5 +// (broadcast). +// +// Stratum: This is a eight-bit unsigned integer indicating the stratum +// level of the local clock, with values defined as follows: +// +// Stratum Meaning +// ---------------------------------------------- +// 0 unspecified or unavailable +// 1 primary reference (e.g., radio clock) +// 2-15 secondary reference (via NTP or SNTP) +// 16-255 reserved +// +// +// Poll Interval: This is an eight-bit signed integer indicating the +// maximum interval between successive messages, in seconds to the +// nearest power of two. The values that can appear in this field +// presently range from 4 (16 s) to 14 (16284 s); however, most +// applications use only the sub-range 6 (64 s) to 10 (1024 s). +// +// Precision: This is an eight-bit signed integer indicating the +// precision of the local clock, in seconds to the nearest power of two. +// The values that normally appear in this field range from -6 for +// mains-frequency clocks to -20 for microsecond clocks found in some +// workstations. +// +// Root Delay: This is a 32-bit signed fixed-point number indicating the +// total roundtrip delay to the primary reference source, in seconds +// with fraction point between bits 15 and 16. Note that this variable +// can take on both positive and negative values, depending on the +// relative time and frequency offsets. The values that normally appear +// in this field range from negative values of a few milliseconds to +// positive values of several hundred milliseconds. +// +// Root Dispersion: This is a 32-bit unsigned fixed-point number +// indicating the nominal error relative to the primary reference +// source, in seconds with fraction point between bits 15 and 16. The +// values that normally appear in this field range from 0 to several +// hundred milliseconds. +// +// Reference Identifier: This is a 32-bit bitstring identifying the +// particular reference source. In the case of NTP Version 3 or Version +// 4 stratum-0 (unspecified) or stratum-1 (primary) servers, this is a +// four-character ASCII string, left justified and zero padded to 32 +// bits. In NTP Version 3 secondary servers, this is the 32-bit IPv4 +// address of the reference source. In NTP Version 4 secondary servers, +// this is the low order 32 bits of the latest transmit timestamp of the +// reference source. NTP primary (stratum 1) servers should set this +// field to a code identifying the external reference source according +// to the following list. If the external reference is one of those +// listed, the associated code should be used. Codes for sources not +// listed can be contrived as appropriate. +// +// +// Code External Reference Source +// ---------------------------------------------------------------- +// LOCL uncalibrated local clock used as a primary reference for +// a subnet without external means of synchronization +// PPS atomic clock or other pulse-per-second source +// individually calibrated to national standards +// ACTS NIST dialup modem service +// USNO USNO modem service +// PTB PTB (Germany) modem service +// TDF Allouis (France) Radio 164 kHz +// DCF Mainflingen (Germany) Radio 77.5 kHz +// MSF Rugby (UK) Radio 60 kHz +// WWV Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz +// WWVB Boulder (US) Radio 60 kHz +// WWVH Kaui Hawaii (US) Radio 2.5, 5, 10, 15 MHz +// CHU Ottawa (Canada) Radio 3330, 7335, 14670 kHz +// LORC LORAN-C radionavigation system +// OMEG OMEGA radionavigation system +// GPS Global Positioning Service +// GOES Geostationary Orbit Environment Satellite +// +// Reference Timestamp: This is the time at which the local clock was +// last set or corrected, in 64-bit timestamp format. +// +// Originate Timestamp: This is the time at which the request departed +// the client for the server, in 64-bit timestamp format. +// +// Receive Timestamp: This is the time at which the request arrived at +// the server, in 64-bit timestamp format. +// +// Transmit Timestamp: This is the time at which the reply departed the +// server for the client, in 64-bit timestamp format. +// +// Authenticator (optional): When the NTP authentication scheme is +// implemented, the Key Identifier and Message Digest fields contain the +// message authentication code (MAC) information defined in Appendix C +// of RFC-1305. + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "Arduino.h" +#else + #include "WProgram.h" +#endif + +#include "utility/socket.h" +#include "utility/netapp.h" + +//#define CLOCK_DEBUG +//#define CLOCK_DEEP_DEBUG +// +#define SNTP_PORT ((uint16_t)123) /* well-known NTP port number, assigned by IANA */ + +#define MAX_URL_NAME 31 + +#define MAX_NTP_SERVERS 2 + +#define NUMBER_OF_TIME_ZONES 34 + + +typedef enum SNTP_LI_t { no_warning = 0, + sixty_One, + fifty_Nine, + alarm + } SNTP_LI_t; + +typedef enum SNTP_Mode_t { reserved = 0, + sym_active, + sym_passive, + client, + server, + broadcast, + reserved_control, + reserved_private + } SNTP_Mode_t; + +typedef struct SNTP_Stratum_t +{ + uint8_t primary : 1; + uint8_t secondary : 3; + uint8_t reserved : 4; +}SNTP_Stratum_t; + +typedef struct SNTP_Timestamp_t +{ + uint32_t seconds; + int32_t fraction; +}SNTP_Timestamp_t; + +typedef struct SNTP_Message_t +{ + SNTP_Mode_t mode : 3; + uint8_t VN : 3; + SNTP_LI_t LI : 2; + SNTP_Stratum_t stratum; + char poll; + char precision; + long delay; + uint32_t dispersion; + uint32_t referenceID; + SNTP_Timestamp_t tsReference; + SNTP_Timestamp_t tsOriginate; + SNTP_Timestamp_t tsReceive; + SNTP_Timestamp_t tsTransmit; + // uint32_t key; //optional field - ignore + // uint8_t messageDigest[128]; //optional field - ignore +}SNTP_Message_t; + +typedef const char** NTP_Pool_t; //Name of NTP server pool +typedef uint32_t NTP_Server_List_t[MAX_NTP_SERVERS]; //list of ntp server addresses (as returned by NTP server pool) + +/** +* Structure for NTP calendar time. +* +*/ +typedef struct NetTime_t +{ + uint16_t millis; ///< Milliseconds after the second (0..999) + uint8_t sec; ///< Seconds after the minute (0..59) + uint8_t min; ///< Minutes after the hour (0..59) + uint8_t hour; ///< Hours since midnight (0..23) + uint8_t mday; ///< Day of the month (1..31) + uint8_t mon; ///< Months since January (0..11) + uint16_t year; ///< Year. + uint8_t wday; ///< Days since Sunday (0..6) + uint16_t yday; ///< Days since January 1 (0..365) + bool isdst; ///< Daylight savings time flag, currently not supported +}NetTime_t; + + +class sntp +{ + public: + sntp(); + sntp(char* ntp_server_url1, short local_utc_offset); + sntp(char* ntp_server_url1, char* ntp_server_url2, short local_utc_offset); + sntp(char* ntp_server_url1, short local_utc_offset, short dst_utc_offset, bool enable_dst); + sntp(char* ntp_server_url1, char* ntp_server_url2, short local_utc_offset, short dst_utc_offset, bool enable_dst); + + virtual ~sntp() {}; + + NetTime_t *ExtractNTPTime(/*in*/ SNTP_Timestamp_t *ntpTime, /*out*/ NetTime_t *extractedTime); + + bool UpdateNTPTime(); + SNTP_Timestamp_t* NTPGetTime(SNTP_Timestamp_t* ntpTime, bool local); + SNTP_Timestamp_t* NTPSetTime(SNTP_Timestamp_t* ntpTime, bool local); + int GetSystemClockAsNTPTime(SNTP_Timestamp_t* ntpSystemTime); + + private: + char GetNTPServerList(const char** ntp_pool_list, uint32_t* addrBuffer, int maxServerCount); + bool SNTP_GetTime(int sntpSocket, uint32_t *ntpServerAddr); + + NetTime_t m_timeStruct; + + uint8_t m_change_DST; // 0 if no daylight savings time change, +1 if spring change, -1 if fall change + + SNTP_Timestamp_t m_NTPReferenceTime; //base time for real-time clock real time = this + millisecond ticker + SNTP_Timestamp_t m_std_UTC_offset; //Local standard-time offset from UTC. Example: Eastern Standard is UTC - 5 hours + SNTP_Timestamp_t m_dst_UTC_offset; //Local daylight-savings-time offset from UTC. Ex: Eastern Daylght is UTC - 4 hours + SNTP_Timestamp_t* m_cur_UTC_offset; //Current offset from UTC. Pointer to either std_UTC_offset or dst_UTC_offset + bool m_twelveHour; //use 12-hour time when true, 24-hour time when false + bool m_enable_dst; //enable daylight savings time + SNTP_Timestamp_t m_dst_start; // next date when DST starts + SNTP_Timestamp_t m_dst_end; // next date when DST ends + uint32_t m_pollTime; // in seconds, how often to poll NTP to update clock + NTP_Pool_t m_localPool; //list of pool servers for current geographical location + NTP_Pool_t m_globalPool; //list of global pool servers if no local servers respond + uint8_t m_userServerCount; //number of NTP servers provded by user (not pool servers) + const char* m_userServers[MAX_NTP_SERVERS]; //list of NTP or NTP pool servers provided by user (pointers to userServerStrings) + char m_userServerStrings[MAX_NTP_SERVERS][MAX_URL_NAME+1]; //storage for user's NTP server URL strings + + bool m_timeIsSet; //false = current time is not set + +}; + +//extern sntp SNTP; +extern Print* CC3KPrinter; + +#endif + diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/socket.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/socket.cpp new file mode 100755 index 0000000000..b5bd8fd931 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/socket.cpp @@ -0,0 +1,1205 @@ +#define SEND_TIMEOUT_MS (30 * 1000) + +/***************************************************************************** +* +* socket.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ + +//***************************************************************************** +// +//! \addtogroup socket_api +//! @{ +// +//***************************************************************************** + +#include +#include +#include +#include "hci.h" +#include "socket.h" +#include "evnt_handler.h" +#include "netapp.h" +#include "debug.h" + + + +//Enable this flag if and only if you must comply with BSD socket +//close() function +#ifdef _API_USE_BSD_CLOSE + #define close(sd) closesocket(sd) +#endif + +//Enable this flag if and only if you must comply with BSD socket read() and +//write() functions +#ifdef _API_USE_BSD_READ_WRITE + #define read(sd, buf, len, flags) recv(sd, buf, len, flags) + #define write(sd, buf, len, flags) send(sd, buf, len, flags) +#endif + +#define SOCKET_OPEN_PARAMS_LEN (12) +#define SOCKET_CLOSE_PARAMS_LEN (4) +#define SOCKET_ACCEPT_PARAMS_LEN (4) +#define SOCKET_BIND_PARAMS_LEN (20) +#define SOCKET_LISTEN_PARAMS_LEN (8) +#define SOCKET_GET_HOST_BY_NAME_PARAMS_LEN (9) +#define SOCKET_CONNECT_PARAMS_LEN (20) +#define SOCKET_SELECT_PARAMS_LEN (44) +#define SOCKET_SET_SOCK_OPT_PARAMS_LEN (20) +#define SOCKET_GET_SOCK_OPT_PARAMS_LEN (12) +#define SOCKET_RECV_FROM_PARAMS_LEN (12) +#define SOCKET_SENDTO_PARAMS_LEN (24) +#define SOCKET_MDNS_ADVERTISE_PARAMS_LEN (12) + + +// The legnth of arguments for the SEND command: sd + buff_offset + len + flags, +// while size of each parameter is 32 bit - so the total length is 16 bytes; + +#define HCI_CMND_SEND_ARG_LENGTH (16) + + +#define SELECT_TIMEOUT_MIN_MICRO_SECONDS 5000 + +#define HEADERS_SIZE_DATA (SPI_HEADER_SIZE + 5) + +#define SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE (SPI_HEADER_SIZE + SIMPLE_LINK_HCI_CMND_HEADER_SIZE) + +#define MDNS_DEVICE_SERVICE_MAX_LENGTH (32) + + +//***************************************************************************** +// +//! HostFlowControlConsumeBuff +//! +//! @param sd socket descriptor +//! +//! @return 0 in case there are buffers available, +//! -1 in case of bad socket +//! -2 if there are no free buffers present (only when +//! SEND_NON_BLOCKING is enabled) +//! +//! @brief if SEND_NON_BLOCKING not define - block until have free buffer +//! becomes available, else return immediately with correct status +//! regarding the buffers available. +// +//***************************************************************************** +int +HostFlowControlConsumeBuff(int sd) +{ +#ifndef SEND_NON_BLOCKING + /* wait in busy loop */ + +#ifdef SEND_TIMEOUT_MS + unsigned long startTime = millis(); +#endif + + do + { + // In case last transmission failed then we will return the last failure + // reason here. + // Note that the buffer will not be allocated in this case + if (tSLInformation.slTransmitDataError != 0) + { + errno = tSLInformation.slTransmitDataError; + tSLInformation.slTransmitDataError = 0; + return errno; + } + + if(SOCKET_STATUS_ACTIVE != get_socket_active_status(sd)) + return -1; + +#ifdef SEND_TIMEOUT_MS + if ((millis() - startTime) > SEND_TIMEOUT_MS) + { + return -3; /* Timeout */ + } +#endif + + } while(0 == tSLInformation.usNumberOfFreeBuffers); + + tSLInformation.usNumberOfFreeBuffers--; + + return 0; +#else + + // In case last transmission failed then we will return the last failure + // reason here. + // Note that the buffer will not be allocated in this case + if (tSLInformation.slTransmitDataError != 0) + { + errno = tSLInformation.slTransmitDataError; + tSLInformation.slTransmitDataError = 0; + return errno; + } + if(SOCKET_STATUS_ACTIVE != get_socket_active_status(sd)) + return -1; + + //If there are no available buffers, return -2. It is recommended to use + // select or receive to see if there is any buffer occupied with received data + // If so, call receive() to release the buffer. + if(0 == tSLInformation.usNumberOfFreeBuffers) + { + return -2; + } + else + { + tSLInformation.usNumberOfFreeBuffers--; + return 0; + } +#endif +} + +//***************************************************************************** +// +//! socket +//! +//! @param domain selects the protocol family which will be used for +//! communication. On this version only AF_INET is supported +//! @param type specifies the communication semantics. On this version +//! only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported +//! @param protocol specifies a particular protocol to be used with the +//! socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are +//! supported. +//! +//! @return On success, socket handle that is used for consequent socket +//! operations. On error, -1 is returned. +//! +//! @brief create an endpoint for communication +//! The socket function creates a socket that is bound to a specific +//! transport service provider. This function is called by the +//! application layer to obtain a socket handle. +// +//***************************************************************************** + +int +socket(long domain, long type, long protocol) +{ + long ret; + unsigned char *ptr, *args; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, domain); + args = UINT32_TO_STREAM(args, type); + args = UINT32_TO_STREAM(args, protocol); + + // Initiate a HCI command + hci_command_send(HCI_CMND_SOCKET, ptr, SOCKET_OPEN_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_CMND_SOCKET, &ret); + + // Process the event + errno = ret; + + set_socket_active_status(ret, SOCKET_STATUS_ACTIVE); + + return(ret); +} + +//***************************************************************************** +// +//! closesocket +//! +//! @param sd socket handle. +//! +//! @return On success, zero is returned. On error, -1 is returned. +//! +//! @brief The socket function closes a created socket. +// +//***************************************************************************** + +long +closesocket(long sd) +{ + long ret; + unsigned char *ptr, *args; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, sd); + + // Initiate a HCI command + hci_command_send(HCI_CMND_CLOSE_SOCKET, ptr, SOCKET_CLOSE_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_CMND_CLOSE_SOCKET, &ret); + errno = ret; + + // since 'close' call may result in either OK (and then it closed) or error + // mark this socket as invalid + set_socket_active_status(sd, SOCKET_STATUS_INACTIVE); + + return(ret); +} + +//***************************************************************************** +// +//! accept +//! +//! @param[in] sd socket descriptor (handle) +//! @param[out] addr the argument addr is a pointer to a sockaddr structure +//! This structure is filled in with the address of the +//! peer socket, as known to the communications layer. +//! determined. The exact format of the address returned +//! addr is by the socket's address sockaddr. +//! On this version only AF_INET is supported. +//! This argument returns in network order. +//! @param[out] addrlen the addrlen argument is a value-result argument: +//! it should initially contain the size of the structure +//! pointed to by addr. +//! +//! @return For socket in blocking mode: +//! On success, socket handle. on failure negative +//! For socket in non-blocking mode: +//! - On connection establishment, socket handle +//! - On connection pending, SOC_IN_PROGRESS (-2) +//! - On failure, SOC_ERROR (-1) +//! +//! @brief accept a connection on a socket: +//! This function is used with connection-based socket types +//! (SOCK_STREAM). It extracts the first connection request on the +//! queue of pending connections, creates a new connected socket, and +//! returns a new file descriptor referring to that socket. +//! The newly created socket is not in the listening state. +//! The original socket sd is unaffected by this call. +//! The argument sd is a socket that has been created with socket(), +//! bound to a local address with bind(), and is listening for +//! connections after a listen(). The argument addr is a pointer +//! to a sockaddr structure. This structure is filled in with the +//! address of the peer socket, as known to the communications layer. +//! The exact format of the address returned addr is determined by the +//! socket's address family. The addrlen argument is a value-result +//! argument: it should initially contain the size of the structure +//! pointed to by addr, on return it will contain the actual +//! length (in bytes) of the address returned. +//! +//! @sa socket ; bind ; listen +// +//***************************************************************************** + +long +accept(long sd, sockaddr *addr, socklen_t *addrlen) +{ + long ret; + unsigned char *ptr, *args; + tBsdReturnParams tAcceptReturnArguments; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, sd); + + // Initiate a HCI command + hci_command_send(HCI_CMND_ACCEPT, + ptr, SOCKET_ACCEPT_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_CMND_ACCEPT, &tAcceptReturnArguments); + + + // need specify return parameters!!! + if (addr) memcpy(addr, &tAcceptReturnArguments.tSocketAddress, ASIC_ADDR_LEN); + if (addrlen) *addrlen = ASIC_ADDR_LEN; + errno = tAcceptReturnArguments.iStatus; + ret = errno; + + // if succeeded, iStatus = new socket descriptor. otherwise - error number + if(M_IS_VALID_SD(ret)) + { + set_socket_active_status(ret, SOCKET_STATUS_ACTIVE); + } + else + { + set_socket_active_status(sd, SOCKET_STATUS_INACTIVE); + } + + return(ret); +} + +//***************************************************************************** +// +//! bind +//! +//! @param[in] sd socket descriptor (handle) +//! @param[out] addr specifies the destination address. On this version +//! only AF_INET is supported. +//! @param[out] addrlen contains the size of the structure pointed to by addr. +//! +//! @return On success, zero is returned. On error, -1 is returned. +//! +//! @brief assign a name to a socket +//! This function gives the socket the local address addr. +//! addr is addrlen bytes long. Traditionally, this is called when a +//! socket is created with socket, it exists in a name space (address +//! family) but has no name assigned. +//! It is necessary to assign a local address before a SOCK_STREAM +//! socket may receive connections. +//! +//! @sa socket ; accept ; listen +// +//***************************************************************************** + +long +bind(long sd, const sockaddr *addr, long addrlen) +{ + long ret; + unsigned char *ptr, *args; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + addrlen = ASIC_ADDR_LEN; + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, sd); + args = UINT32_TO_STREAM(args, 0x00000008); + args = UINT32_TO_STREAM(args, addrlen); + ARRAY_TO_STREAM(args, ((unsigned char *)addr), addrlen); + + // Initiate a HCI command + hci_command_send(HCI_CMND_BIND, + ptr, SOCKET_BIND_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_CMND_BIND, &ret); + + errno = ret; + + return(ret); +} + +//***************************************************************************** +// +//! listen +//! +//! @param[in] sd socket descriptor (handle) +//! @param[in] backlog specifies the listen queue depth. On this version +//! backlog is not supported. +//! @return On success, zero is returned. On error, -1 is returned. +//! +//! @brief listen for connections on a socket +//! The willingness to accept incoming connections and a queue +//! limit for incoming connections are specified with listen(), +//! and then the connections are accepted with accept. +//! The listen() call applies only to sockets of type SOCK_STREAM +//! The backlog parameter defines the maximum length the queue of +//! pending connections may grow to. +//! +//! @sa socket ; accept ; bind +//! +//! @note On this version, backlog is not supported +// +//***************************************************************************** + +long +listen(long sd, long backlog) +{ + long ret; + unsigned char *ptr, *args; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, sd); + args = UINT32_TO_STREAM(args, backlog); + + // Initiate a HCI command + hci_command_send(HCI_CMND_LISTEN, + ptr, SOCKET_LISTEN_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_CMND_LISTEN, &ret); + errno = ret; + + return(ret); +} + +//***************************************************************************** +// +//! gethostbyname +//! +//! @param[in] hostname host name +//! @param[in] usNameLen name length +//! @param[out] out_ip_addr This parameter is filled in with host IP address. +//! In case that host name is not resolved, +//! out_ip_addr is zero. +//! @return On success, positive is returned. On error, negative is returned +//! +//! @brief Get host IP by name. Obtain the IP Address of machine on network, +//! by its name. +//! +//! @note On this version, only blocking mode is supported. Also note that +//! the function requires DNS server to be configured prior to its usage. +// +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +int +gethostbyname(const char * hostname, uint8_t usNameLen, uint32_t * out_ip_addr) +{ + tBsdGethostbynameParams ret; + unsigned char *ptr, *args; + + errno = EFAIL; + + if (usNameLen > HOSTNAME_MAX_LENGTH) + { + return errno; + } + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, 8); + args = UINT32_TO_STREAM(args, usNameLen); + ARRAY_TO_STREAM(args, hostname, usNameLen); + + // Initiate a HCI command + hci_command_send(HCI_CMND_GETHOSTNAME, ptr, SOCKET_GET_HOST_BY_NAME_PARAMS_LEN + + usNameLen - 1); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_EVNT_BSD_GETHOSTBYNAME, &ret); + + errno = ret.retVal; + //Dprinter->print("errno: "); Dprinter->println(errno); + (*((uint32_t *)out_ip_addr)) = ret.outputAddress; + + return (errno); + +} +#endif + +//***************************************************************************** +// +//! connect +//! +//! @param[in] sd socket descriptor (handle) +//! @param[in] addr specifies the destination addr. On this version +//! only AF_INET is supported. +//! @param[out] addrlen contains the size of the structure pointed to by addr +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief initiate a connection on a socket +//! Function connects the socket referred to by the socket descriptor +//! sd, to the address specified by addr. The addrlen argument +//! specifies the size of addr. The format of the address in addr is +//! determined by the address space of the socket. If it is of type +//! SOCK_DGRAM, this call specifies the peer with which the socket is +//! to be associated; this address is that to which datagrams are to be +//! sent, and the only address from which datagrams are to be received. +//! If the socket is of type SOCK_STREAM, this call attempts to make a +//! connection to another socket. The other socket is specified by +//! address, which is an address in the communications space of the +//! socket. Note that the function implements only blocking behavior +//! thus the caller will be waiting either for the connection +//! establishment or for the connection establishment failure. +//! +//! @sa socket +// +//***************************************************************************** + +long +connect(long sd, const sockaddr *addr, long addrlen) +{ + long int ret; + unsigned char *ptr, *args; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE); + addrlen = 8; + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, sd); + args = UINT32_TO_STREAM(args, 0x00000008); + args = UINT32_TO_STREAM(args, addrlen); + ARRAY_TO_STREAM(args, ((unsigned char *)addr), addrlen); + + // Initiate a HCI command + hci_command_send(HCI_CMND_CONNECT, + ptr, SOCKET_CONNECT_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_CMND_CONNECT, &ret); + + errno = ret; + + return((long)ret); +} + + +//***************************************************************************** +// +//! select +//! +//! @param[in] nfds the highest-numbered file descriptor in any of the +//! three sets, plus 1. +//! @param[out] writesds socket descriptors list for write monitoring +//! @param[out] readsds socket descriptors list for read monitoring +//! @param[out] exceptsds socket descriptors list for exception monitoring +//! @param[in] timeout is an upper bound on the amount of time elapsed +//! before select() returns. Null means infinity +//! timeout. The minimum timeout is 5 milliseconds, +//! less than 5 milliseconds will be set +//! automatically to 5 milliseconds. +//! @return On success, select() returns the number of file descriptors +//! contained in the three returned descriptor sets (that is, the +//! total number of bits that are set in readfds, writefds, +//! exceptfds) which may be zero if the timeout expires before +//! anything interesting happens. +//! On error, -1 is returned. +//! *readsds - return the sockets on which Read request will +//! return without delay with valid data. +//! *writesds - return the sockets on which Write request +//! will return without delay. +//! *exceptsds - return the sockets which closed recently. +//! +//! @brief Monitor socket activity +//! Select allow a program to monitor multiple file descriptors, +//! waiting until one or more of the file descriptors become +//! "ready" for some class of I/O operation +//! +//! @Note If the timeout value set to less than 5ms it will automatically set +//! to 5ms to prevent overload of the system +//! +//! @sa socket +// +//***************************************************************************** + +int +select(long nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, + struct timeval *timeout) +{ + unsigned char *ptr, *args; + tBsdSelectRecvParams tParams; + unsigned long is_blocking; + + if( timeout == NULL) + { + is_blocking = 1; /* blocking , infinity timeout */ + } + else + { + is_blocking = 0; /* no blocking, timeout */ + } + + // Fill in HCI packet structure + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, nfds); + args = UINT32_TO_STREAM(args, 0x00000014); + args = UINT32_TO_STREAM(args, 0x00000014); + args = UINT32_TO_STREAM(args, 0x00000014); + args = UINT32_TO_STREAM(args, 0x00000014); + args = UINT32_TO_STREAM(args, is_blocking); + args = UINT32_TO_STREAM(args, ((readsds) ? *(unsigned long*)readsds : 0)); + args = UINT32_TO_STREAM(args, ((writesds) ? *(unsigned long*)writesds : 0)); + args = UINT32_TO_STREAM(args, ((exceptsds) ? *(unsigned long*)exceptsds : 0)); + + if (timeout) + { + if ( 0 == timeout->tv_sec && timeout->tv_usec < + SELECT_TIMEOUT_MIN_MICRO_SECONDS) + { + timeout->tv_usec = SELECT_TIMEOUT_MIN_MICRO_SECONDS; + } + args = UINT32_TO_STREAM(args, timeout->tv_sec); + args = UINT32_TO_STREAM(args, timeout->tv_usec); + } + + // Initiate a HCI command + hci_command_send(HCI_CMND_BSD_SELECT, ptr, SOCKET_SELECT_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_EVNT_SELECT, &tParams); + + // Update actually read FD + if (tParams.iStatus >= 0) + { + if (readsds) + { + memcpy(readsds, &tParams.uiRdfd, sizeof(tParams.uiRdfd)); + } + + if (writesds) + { + memcpy(writesds, &tParams.uiWrfd, sizeof(tParams.uiWrfd)); + } + + if (exceptsds) + { + memcpy(exceptsds, &tParams.uiExfd, sizeof(tParams.uiExfd)); + } + + return(tParams.iStatus); + + } + else + { + errno = tParams.iStatus; + return(-1); + } +} + +//***************************************************************************** +// +//! setsockopt +//! +//! @param[in] sd socket handle +//! @param[in] level defines the protocol level for this option +//! @param[in] optname defines the option name to Interrogate +//! @param[in] optval specifies a value for the option +//! @param[in] optlen specifies the length of the option value +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief set socket options +//! This function manipulate the options associated with a socket. +//! Options may exist at multiple protocol levels; they are always +//! present at the uppermost socket level. +//! When manipulating socket options the level at which the option +//! resides and the name of the option must be specified. +//! To manipulate options at the socket level, level is specified as +//! SOL_SOCKET. To manipulate options at any other level the protocol +//! number of the appropriate protocol controlling the option is +//! supplied. For example, to indicate that an option is to be +//! interpreted by the TCP protocol, level should be set to the +//! protocol number of TCP; +//! The parameters optval and optlen are used to access optval - +//! use for setsockopt(). For getsockopt() they identify a buffer +//! in which the value for the requested option(s) are to +//! be returned. For getsockopt(), optlen is a value-result +//! parameter, initially containing the size of the buffer +//! pointed to by option_value, and modified on return to +//! indicate the actual size of the value returned. If no option +//! value is to be supplied or returned, option_value may be NULL. +//! +//! @Note On this version the following two socket options are enabled: +//! The only protocol level supported in this version +//! is SOL_SOCKET (level). +//! 1. SOCKOPT_RECV_TIMEOUT (optname) +//! SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout +//! in milliseconds. +//! In that case optval should be pointer to unsigned long. +//! 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on +//! or off. +//! In that case optval should be SOCK_ON or SOCK_OFF (optval). +//! +//! @sa getsockopt +// +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +int +setsockopt(long sd, long level, long optname, const void *optval, + socklen_t optlen) +{ + long ret; + unsigned char *ptr, *args; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, sd); + args = UINT32_TO_STREAM(args, level); + args = UINT32_TO_STREAM(args, optname); + args = UINT32_TO_STREAM(args, 0x00000008); + args = UINT32_TO_STREAM(args, optlen); + ARRAY_TO_STREAM(args, ((unsigned char *)optval), optlen); + + // Initiate a HCI command + hci_command_send(HCI_CMND_SETSOCKOPT, + ptr, SOCKET_SET_SOCK_OPT_PARAMS_LEN + optlen); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_CMND_SETSOCKOPT, &ret); + + if (ret >= 0) + { + return (0); + } + else + { + errno = ret; + return (-1); + } +} +#endif + +//***************************************************************************** +// +//! getsockopt +//! +//! @param[in] sd socket handle +//! @param[in] level defines the protocol level for this option +//! @param[in] optname defines the option name to Interrogate +//! @param[out] optval specifies a value for the option +//! @param[out] optlen specifies the length of the option value +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief set socket options +//! This function manipulate the options associated with a socket. +//! Options may exist at multiple protocol levels; they are always +//! present at the uppermost socket level. +//! When manipulating socket options the level at which the option +//! resides and the name of the option must be specified. +//! To manipulate options at the socket level, level is specified as +//! SOL_SOCKET. To manipulate options at any other level the protocol +//! number of the appropriate protocol controlling the option is +//! supplied. For example, to indicate that an option is to be +//! interpreted by the TCP protocol, level should be set to the +//! protocol number of TCP; +//! The parameters optval and optlen are used to access optval - +//! use for setsockopt(). For getsockopt() they identify a buffer +//! in which the value for the requested option(s) are to +//! be returned. For getsockopt(), optlen is a value-result +//! parameter, initially containing the size of the buffer +//! pointed to by option_value, and modified on return to +//! indicate the actual size of the value returned. If no option +//! value is to be supplied or returned, option_value may be NULL. +//! +//! @Note On this version the following two socket options are enabled: +//! The only protocol level supported in this version +//! is SOL_SOCKET (level). +//! 1. SOCKOPT_RECV_TIMEOUT (optname) +//! SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout +//! in milliseconds. +//! In that case optval should be pointer to unsigned long. +//! 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on +//! or off. +//! In that case optval should be SOCK_ON or SOCK_OFF (optval). +//! +//! @sa setsockopt +// +//***************************************************************************** + +int +getsockopt (long sd, long level, long optname, void *optval, socklen_t *optlen) +{ + unsigned char *ptr, *args; + tBsdGetSockOptReturnParams tRetParams; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, sd); + args = UINT32_TO_STREAM(args, level); + args = UINT32_TO_STREAM(args, optname); + + // Initiate a HCI command + hci_command_send(HCI_CMND_GETSOCKOPT, + ptr, SOCKET_GET_SOCK_OPT_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_CMND_GETSOCKOPT, &tRetParams); + + if (((signed char)tRetParams.iStatus) >= 0) + { + *optlen = 4; + memcpy(optval, tRetParams.ucOptValue, 4); + return (0); + } + else + { + errno = tRetParams.iStatus; + return (-1); + } +} + +//***************************************************************************** +// +//! simple_link_recv +//! +//! @param sd socket handle +//! @param buf read buffer +//! @param len buffer length +//! @param flags indicates blocking or non-blocking operation +//! @param from pointer to an address structure indicating source address +//! @param fromlen source address structure size +//! +//! @return Return the number of bytes received, or -1 if an error +//! occurred +//! +//! @brief Read data from socket +//! Return the length of the message on successful completion. +//! If a message is too long to fit in the supplied buffer, +//! excess bytes may be discarded depending on the type of +//! socket the message is received from +// +//***************************************************************************** +int +simple_link_recv(long sd, void *buf, long len, long flags, sockaddr *from, + socklen_t *fromlen, long opcode) +{ + unsigned char *ptr, *args; + tBsdReadReturnParams tSocketReadEvent; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, sd); + args = UINT32_TO_STREAM(args, len); + args = UINT32_TO_STREAM(args, flags); + + // Generate the read command, and wait for the + hci_command_send(opcode, ptr, SOCKET_RECV_FROM_PARAMS_LEN); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(opcode, &tSocketReadEvent); + + DEBUGPRINT_F("\n\r\tRecv'd data... Socket #"); + DEBUGPRINT_DEC(tSocketReadEvent.iSocketDescriptor); + DEBUGPRINT_F(" Bytes: 0x"); + DEBUGPRINT_HEX(tSocketReadEvent.iNumberOfBytes); + DEBUGPRINT_F(" Flags: 0x"); + DEBUGPRINT_HEX(tSocketReadEvent.uiFlags); + DEBUGPRINT_F("\n\r"); + + // In case the number of bytes is more then zero - read data + if (tSocketReadEvent.iNumberOfBytes > 0) + { + // Wait for the data in a synchronous way. Here we assume that the bug is + // big enough to store also parameters of receive from too.... + SimpleLinkWaitData((unsigned char *)buf, (unsigned char *)from, (unsigned char *)fromlen); + } + + errno = tSocketReadEvent.iNumberOfBytes; + +#if (DEBUG_MODE == 1) + for (uint8_t i=0; i MDNS_DEVICE_SERVICE_MAX_LENGTH) + { + return EFAIL; + } + + pTxBuffer = tSLInformation.pucTxCommandBuffer; + pArgs = (pTxBuffer + SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE); + + // Fill in HCI packet structure + pArgs = UINT32_TO_STREAM(pArgs, mdnsEnabled); + pArgs = UINT32_TO_STREAM(pArgs, 8); + pArgs = UINT32_TO_STREAM(pArgs, deviceServiceNameLength); + ARRAY_TO_STREAM(pArgs, deviceServiceName, deviceServiceNameLength); + + // Initiate a HCI command + hci_command_send(HCI_CMND_MDNS_ADVERTISE, pTxBuffer, SOCKET_MDNS_ADVERTISE_PARAMS_LEN + deviceServiceNameLength); + + // Since we are in blocking state - wait for event complete + SimpleLinkWaitEvent(HCI_EVNT_MDNS_ADVERTISE, &ret); + + return ret; + +} diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/socket.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/socket.h new file mode 100755 index 0000000000..58e7ef13be --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/socket.h @@ -0,0 +1,691 @@ +/***************************************************************************** +* +* socket.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef __SOCKET_H__ +#define __SOCKET_H__ + + +//***************************************************************************** +// +//! \addtogroup socket_api +//! @{ +// +//***************************************************************************** + + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" { +#endif + +#define HOSTNAME_MAX_LENGTH (230) // 230 bytes + header shouldn't exceed 8 bit value + +//--------- Address Families -------- + +#define AF_INET 2 +#define AF_INET6 23 + +//------------ Socket Types ------------ + +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 // Raw sockets allow new IPv4 protocols to be implemented in user space. A raw socket receives or sends the raw datagram not including link level headers +#define SOCK_RDM 4 +#define SOCK_SEQPACKET 5 + +//----------- Socket Protocol ---------- + +#define IPPROTO_IP 0 // dummy for IP +#define IPPROTO_ICMP 1 // control message protocol +#define IPPROTO_IPV4 IPPROTO_IP // IP inside IP +#define IPPROTO_TCP 6 // tcp +#define IPPROTO_UDP 17 // user datagram protocol +#define IPPROTO_IPV6 41 // IPv6 in IPv6 +#define IPPROTO_NONE 59 // No next header +#define IPPROTO_RAW 255 // raw IP packet +#define IPPROTO_MAX 256 + +//----------- Socket retunr codes ----------- + +#define SOC_ERROR (-1) // error +#define SOC_IN_PROGRESS (-2) // socket in progress + +//----------- Socket Options ----------- +#define SOL_SOCKET 0xffff // socket level +#define SOCKOPT_RECV_NONBLOCK 0 // recv non block mode, set SOCK_ON or SOCK_OFF (default block mode) +#define SOCKOPT_RECV_TIMEOUT 1 // optname to configure recv and recvfromtimeout +#define SOCKOPT_ACCEPT_NONBLOCK 2 // accept non block mode, set SOCK_ON or SOCK_OFF (default block mode) +#define SOCK_ON 0 // socket non-blocking mode is enabled +#define SOCK_OFF 1 // socket blocking mode is enabled + +#define TCP_NODELAY 0x0001 +#define TCP_BSDURGENT 0x7000 + +#define MAX_PACKET_SIZE 1500 +#define MAX_LISTEN_QUEUE 4 + +#define IOCTL_SOCKET_EVENTMASK + +#ifdef ENOBUFS +#undef ENOBUFS +#endif +#define ENOBUFS 55 // No buffer space available + +#define __FD_SETSIZE 32 + +#define ASIC_ADDR_LEN 8 + +#define NO_QUERY_RECIVED -3 + + +typedef struct _in_addr_t +{ + unsigned long s_addr; // load with inet_aton() +} in_addr; + +typedef struct _sockaddr_t +{ + unsigned short int sa_family; + unsigned char sa_data[14]; +} sockaddr; + +typedef struct _sockaddr_in_t +{ + short sin_family; // e.g. AF_INET + unsigned short sin_port; // e.g. htons(3490) + in_addr sin_addr; // see struct in_addr, below + char sin_zero[8]; // zero this if you want to +} sockaddr_in; + +typedef unsigned long socklen_t; + +// The fd_set member is required to be an array of longs. +typedef long int __fd_mask; + +// It's easier to assume 8-bit bytes than to get CHAR_BIT. +#define __NFDBITS (8 * sizeof (__fd_mask)) +#define __FDELT(d) ((d) / __NFDBITS) +#define __FDMASK(d) ((__fd_mask) 1 << ((d) % __NFDBITS)) + +#ifdef fd_set +#undef fd_set // for compatibility with newlib, which defines fd_set +#endif + +// fd_set for select and pselect. +typedef struct +{ + __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS]; +#define __FDS_BITS(set) ((set)->fds_bits) +} fd_set; + +// We don't use `memset' because this would require a prototype and +// the array isn't too big. +#define __FD_ZERO(set) \ + do { \ + unsigned int __i; \ + fd_set *__arr = (set); \ + for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \ + __FDS_BITS (__arr)[__i] = 0; \ + } while (0) +#define __FD_SET(d, set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d)) +#define __FD_CLR(d, set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d)) +#define __FD_ISSET(d, set) (__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d)) + +// Access macros for 'fd_set'. +#ifdef FD_SET +#undef FD_SET +#endif +#ifdef FD_CLR +#undef FD_CLR +#endif +#ifdef FD_ISSET +#undef FD_ISSET +#endif +#ifdef FD_ZERO +#undef FD_ZERO +#endif +#define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp) +#define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp) +#define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp) +#define FD_ZERO(fdsetp) __FD_ZERO (fdsetp) + +//Use in case of Big Endian only + +#define htonl(A) ((((unsigned long)(A) & 0xff000000) >> 24) | \ + (((unsigned long)(A) & 0x00ff0000) >> 8) | \ + (((unsigned long)(A) & 0x0000ff00) << 8) | \ + (((unsigned long)(A) & 0x000000ff) << 24)) + +#define ntohl htonl + +//Use in case of Big Endian only +#define htons(A) ((((unsigned long)(A) & 0xff00) >> 8) | \ + (((unsigned long)(A) & 0x00ff) << 8)) + + +#define ntohs htons + +// mDNS port - 5353 mDNS multicast address - 224.0.0.251 +#define SET_mDNS_ADD(sockaddr) sockaddr.sa_data[0] = 0x14; \ + sockaddr.sa_data[1] = 0xe9; \ + sockaddr.sa_data[2] = 0xe0; \ + sockaddr.sa_data[3] = 0x0; \ + sockaddr.sa_data[4] = 0x0; \ + sockaddr.sa_data[5] = 0xfb; + + +//***************************************************************************** +// +// Prototypes for the APIs. +// +//***************************************************************************** + +//***************************************************************************** +// +//! socket +//! +//! @param domain selects the protocol family which will be used for +//! communication. On this version only AF_INET is supported +//! @param type specifies the communication semantics. On this version +//! only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported +//! @param protocol specifies a particular protocol to be used with the +//! socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are +//! supported. +//! +//! @return On success, socket handle that is used for consequent socket +//! operations. On error, -1 is returned. +//! +//! @brief create an endpoint for communication +//! The socket function creates a socket that is bound to a specific +//! transport service provider. This function is called by the +//! application layer to obtain a socket handle. +// +//***************************************************************************** +extern int socket(long domain, long type, long protocol); + +//***************************************************************************** +// +//! closesocket +//! +//! @param sd socket handle. +//! +//! @return On success, zero is returned. On error, -1 is returned. +//! +//! @brief The socket function closes a created socket. +// +//***************************************************************************** +extern long closesocket(long sd); + +//***************************************************************************** +// +//! accept +//! +//! @param[in] sd socket descriptor (handle) +//! @param[out] addr the argument addr is a pointer to a sockaddr structure +//! This structure is filled in with the address of the +//! peer socket, as known to the communications layer. +//! determined. The exact format of the address returned +//! addr is by the socket's address sockaddr. +//! On this version only AF_INET is supported. +//! This argument returns in network order. +//! @param[out] addrlen the addrlen argument is a value-result argument: +//! it should initially contain the size of the structure +//! pointed to by addr. +//! +//! @return For socket in blocking mode: +//! On success, socket handle. on failure negative +//! For socket in non-blocking mode: +//! - On connection establishment, socket handle +//! - On connection pending, SOC_IN_PROGRESS (-2) +//! - On failure, SOC_ERROR (-1) +//! +//! @brief accept a connection on a socket: +//! This function is used with connection-based socket types +//! (SOCK_STREAM). It extracts the first connection request on the +//! queue of pending connections, creates a new connected socket, and +//! returns a new file descriptor referring to that socket. +//! The newly created socket is not in the listening state. +//! The original socket sd is unaffected by this call. +//! The argument sd is a socket that has been created with socket(), +//! bound to a local address with bind(), and is listening for +//! connections after a listen(). The argument addr is a pointer +//! to a sockaddr structure. This structure is filled in with the +//! address of the peer socket, as known to the communications layer. +//! The exact format of the address returned addr is determined by the +//! socket's address family. The addrlen argument is a value-result +//! argument: it should initially contain the size of the structure +//! pointed to by addr, on return it will contain the actual +//! length (in bytes) of the address returned. +//! +//! @sa socket ; bind ; listen +// +//***************************************************************************** +extern long accept(long sd, sockaddr *addr, socklen_t *addrlen); + +//***************************************************************************** +// +//! bind +//! +//! @param[in] sd socket descriptor (handle) +//! @param[out] addr specifies the destination address. On this version +//! only AF_INET is supported. +//! @param[out] addrlen contains the size of the structure pointed to by addr. +//! +//! @return On success, zero is returned. On error, -1 is returned. +//! +//! @brief assign a name to a socket +//! This function gives the socket the local address addr. +//! addr is addrlen bytes long. Traditionally, this is called when a +//! socket is created with socket, it exists in a name space (address +//! family) but has no name assigned. +//! It is necessary to assign a local address before a SOCK_STREAM +//! socket may receive connections. +//! +//! @sa socket ; accept ; listen +// +//***************************************************************************** +extern long bind(long sd, const sockaddr *addr, long addrlen); + +//***************************************************************************** +// +//! listen +//! +//! @param[in] sd socket descriptor (handle) +//! @param[in] backlog specifies the listen queue depth. On this version +//! backlog is not supported. +//! @return On success, zero is returned. On error, -1 is returned. +//! +//! @brief listen for connections on a socket +//! The willingness to accept incoming connections and a queue +//! limit for incoming connections are specified with listen(), +//! and then the connections are accepted with accept. +//! The listen() call applies only to sockets of type SOCK_STREAM +//! The backlog parameter defines the maximum length the queue of +//! pending connections may grow to. +//! +//! @sa socket ; accept ; bind +//! +//! @note On this version, backlog is not supported +// +//***************************************************************************** +extern long listen(long sd, long backlog); + +//***************************************************************************** +// +//! gethostbyname +//! +//! @param[in] hostname host name +//! @param[in] usNameLen name length +//! @param[out] out_ip_addr This parameter is filled in with host IP address. +//! In case that host name is not resolved, +//! out_ip_addr is zero. +//! @return On success, positive is returned. On error, negative is returned +//! +//! @brief Get host IP by name. Obtain the IP Address of machine on network, +//! by its name. +//! +//! @note On this version, only blocking mode is supported. Also note that +//! the function requires DNS server to be configured prior to its usage. +// +//***************************************************************************** +#ifndef CC3000_TINY_DRIVER +extern int gethostbyname(const char * hostname, uint8_t usNameLen, uint32_t* out_ip_addr); +#endif + + +//***************************************************************************** +// +//! connect +//! +//! @param[in] sd socket descriptor (handle) +//! @param[in] addr specifies the destination addr. On this version +//! only AF_INET is supported. +//! @param[out] addrlen contains the size of the structure pointed to by addr +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief initiate a connection on a socket +//! Function connects the socket referred to by the socket descriptor +//! sd, to the address specified by addr. The addrlen argument +//! specifies the size of addr. The format of the address in addr is +//! determined by the address space of the socket. If it is of type +//! SOCK_DGRAM, this call specifies the peer with which the socket is +//! to be associated; this address is that to which datagrams are to be +//! sent, and the only address from which datagrams are to be received. +//! If the socket is of type SOCK_STREAM, this call attempts to make a +//! connection to another socket. The other socket is specified by +//! address, which is an address in the communications space of the +//! socket. Note that the function implements only blocking behavior +//! thus the caller will be waiting either for the connection +//! establishment or for the connection establishment failure. +//! +//! @sa socket +// +//***************************************************************************** +extern long connect(long sd, const sockaddr *addr, long addrlen); + +//***************************************************************************** +// +//! select +//! +//! @param[in] nfds the highest-numbered file descriptor in any of the +//! three sets, plus 1. +//! @param[out] writesds socket descriptors list for write monitoring +//! @param[out] readsds socket descriptors list for read monitoring +//! @param[out] exceptsds socket descriptors list for exception monitoring +//! @param[in] timeout is an upper bound on the amount of time elapsed +//! before select() returns. Null means infinity +//! timeout. The minimum timeout is 5 milliseconds, +//! less than 5 milliseconds will be set +//! automatically to 5 milliseconds. +//! @return On success, select() returns the number of file descriptors +//! contained in the three returned descriptor sets (that is, the +//! total number of bits that are set in readfds, writefds, +//! exceptfds) which may be zero if the timeout expires before +//! anything interesting happens. +//! On error, -1 is returned. +//! *readsds - return the sockets on which Read request will +//! return without delay with valid data. +//! *writesds - return the sockets on which Write request +//! will return without delay. +//! *exceptsds - return the sockets which closed recently. +//! +//! @brief Monitor socket activity +//! Select allow a program to monitor multiple file descriptors, +//! waiting until one or more of the file descriptors become +//! "ready" for some class of I/O operation +//! +//! @Note If the timeout value set to less than 5ms it will automatically set +//! to 5ms to prevent overload of the system +//! +//! @sa socket +// +//***************************************************************************** +extern int select(long nfds, fd_set *readsds, fd_set *writesds, + fd_set *exceptsds, struct timeval *timeout); + +//***************************************************************************** +// +//! setsockopt +//! +//! @param[in] sd socket handle +//! @param[in] level defines the protocol level for this option +//! @param[in] optname defines the option name to Interrogate +//! @param[in] optval specifies a value for the option +//! @param[in] optlen specifies the length of the option value +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief set socket options +//! This function manipulate the options associated with a socket. +//! Options may exist at multiple protocol levels; they are always +//! present at the uppermost socket level. +//! When manipulating socket options the level at which the option +//! resides and the name of the option must be specified. +//! To manipulate options at the socket level, level is specified as +//! SOL_SOCKET. To manipulate options at any other level the protocol +//! number of the appropriate protocol controlling the option is +//! supplied. For example, to indicate that an option is to be +//! interpreted by the TCP protocol, level should be set to the +//! protocol number of TCP; +//! The parameters optval and optlen are used to access optval - +//! use for setsockopt(). For getsockopt() they identify a buffer +//! in which the value for the requested option(s) are to +//! be returned. For getsockopt(), optlen is a value-result +//! parameter, initially containing the size of the buffer +//! pointed to by option_value, and modified on return to +//! indicate the actual size of the value returned. If no option +//! value is to be supplied or returned, option_value may be NULL. +//! +//! @Note On this version the following two socket options are enabled: +//! The only protocol level supported in this version +//! is SOL_SOCKET (level). +//! 1. SOCKOPT_RECV_TIMEOUT (optname) +//! SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout +//! in milliseconds. +//! In that case optval should be pointer to unsigned long. +//! 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on +//! or off. +//! In that case optval should be SOCK_ON or SOCK_OFF (optval). +//! +//! @sa getsockopt +// +//***************************************************************************** +#ifndef CC3000_TINY_DRIVER +extern int setsockopt(long sd, long level, long optname, const void *optval, + socklen_t optlen); +#endif +//***************************************************************************** +// +//! getsockopt +//! +//! @param[in] sd socket handle +//! @param[in] level defines the protocol level for this option +//! @param[in] optname defines the option name to Interrogate +//! @param[out] optval specifies a value for the option +//! @param[out] optlen specifies the length of the option value +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief set socket options +//! This function manipulate the options associated with a socket. +//! Options may exist at multiple protocol levels; they are always +//! present at the uppermost socket level. +//! When manipulating socket options the level at which the option +//! resides and the name of the option must be specified. +//! To manipulate options at the socket level, level is specified as +//! SOL_SOCKET. To manipulate options at any other level the protocol +//! number of the appropriate protocol controlling the option is +//! supplied. For example, to indicate that an option is to be +//! interpreted by the TCP protocol, level should be set to the +//! protocol number of TCP; +//! The parameters optval and optlen are used to access optval - +//! use for setsockopt(). For getsockopt() they identify a buffer +//! in which the value for the requested option(s) are to +//! be returned. For getsockopt(), optlen is a value-result +//! parameter, initially containing the size of the buffer +//! pointed to by option_value, and modified on return to +//! indicate the actual size of the value returned. If no option +//! value is to be supplied or returned, option_value may be NULL. +//! +//! @Note On this version the following two socket options are enabled: +//! The only protocol level supported in this version +//! is SOL_SOCKET (level). +//! 1. SOCKOPT_RECV_TIMEOUT (optname) +//! SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout +//! in milliseconds. +//! In that case optval should be pointer to unsigned long. +//! 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on +//! or off. +//! In that case optval should be SOCK_ON or SOCK_OFF (optval). +//! +//! @sa setsockopt +// +//***************************************************************************** +extern int getsockopt(long sd, long level, long optname, void *optval, + socklen_t *optlen); + +//***************************************************************************** +// +//! recv +//! +//! @param[in] sd socket handle +//! @param[out] buf Points to the buffer where the message should be stored +//! @param[in] len Specifies the length in bytes of the buffer pointed to +//! by the buffer argument. +//! @param[in] flags Specifies the type of message reception. +//! On this version, this parameter is not supported. +//! +//! @return Return the number of bytes received, or -1 if an error +//! occurred +//! +//! @brief function receives a message from a connection-mode socket +//! +//! @sa recvfrom +//! +//! @Note On this version, only blocking mode is supported. +// +//***************************************************************************** +extern int recv(long sd, void *buf, long len, long flags); + +//***************************************************************************** +// +//! recvfrom +//! +//! @param[in] sd socket handle +//! @param[out] buf Points to the buffer where the message should be stored +//! @param[in] len Specifies the length in bytes of the buffer pointed to +//! by the buffer argument. +//! @param[in] flags Specifies the type of message reception. +//! On this version, this parameter is not supported. +//! @param[in] from pointer to an address structure indicating the source +//! address: sockaddr. On this version only AF_INET is +//! supported. +//! @param[in] fromlen source address structure size +//! +//! @return Return the number of bytes received, or -1 if an error +//! occurred +//! +//! @brief read data from socket +//! function receives a message from a connection-mode or +//! connectionless-mode socket. Note that raw sockets are not +//! supported. +//! +//! @sa recv +//! +//! @Note On this version, only blocking mode is supported. +// +//***************************************************************************** +extern int recvfrom(long sd, void *buf, long len, long flags, sockaddr *from, + socklen_t *fromlen); + +//***************************************************************************** +// +//! send +//! +//! @param sd socket handle +//! @param buf Points to a buffer containing the message to be sent +//! @param len message size in bytes +//! @param flags On this version, this parameter is not supported +//! +//! @return Return the number of bytes transmitted, or -1 if an +//! error occurred +//! +//! @brief Write data to TCP socket +//! This function is used to transmit a message to another +//! socket. +//! +//! @Note On this version, only blocking mode is supported. +//! +//! @sa sendto +// +//***************************************************************************** + +extern int send(long sd, const void *buf, long len, long flags); + +//***************************************************************************** +// +//! sendto +//! +//! @param sd socket handle +//! @param buf Points to a buffer containing the message to be sent +//! @param len message size in bytes +//! @param flags On this version, this parameter is not supported +//! @param to pointer to an address structure indicating the destination +//! address: sockaddr. On this version only AF_INET is +//! supported. +//! @param tolen destination address structure size +//! +//! @return Return the number of bytes transmitted, or -1 if an +//! error occurred +//! +//! @brief Write data to TCP socket +//! This function is used to transmit a message to another +//! socket. +//! +//! @Note On this version, only blocking mode is supported. +//! +//! @sa send +// +//***************************************************************************** + +extern int sendto(long sd, const void *buf, long len, long flags, + const sockaddr *to, socklen_t tolen); + +//***************************************************************************** +// +//! mdnsAdvertiser +//! +//! @param[in] mdnsEnabled flag to enable/disable the mDNS feature +//! @param[in] deviceServiceName Service name as part of the published +//! canonical domain name +//! @param[in] deviceServiceNameLength Length of the service name +//! +//! +//! @return On success, zero is returned, return SOC_ERROR if socket was not +//! opened successfully, or if an error occurred. +//! +//! @brief Set CC3000 in mDNS advertiser mode in order to advertise itself. +// +//***************************************************************************** +extern int mdnsAdvertiser(unsigned short mdnsEnabled, char * deviceServiceName, unsigned short deviceServiceNameLength); + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** + + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // __SOCKET_H__ diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/wlan.cpp b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/wlan.cpp new file mode 100755 index 0000000000..f7800501c0 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/wlan.cpp @@ -0,0 +1,1261 @@ +/***************************************************************************** +* +* wlan.c - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! + +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ + +//***************************************************************************** +// +//! \addtogroup wlan_api +//! @{ +// +//***************************************************************************** +#include +#include "wlan.h" +#include "hci.h" +#include "../ccspi.h" +#include "socket.h" +#include "nvmem.h" +#include "security.h" +#include "evnt_handler.h" +#include "debug.h" + +volatile sSimplLinkInformation tSLInformation; + +#define SMART_CONFIG_PROFILE_SIZE 67 // 67 = 32 (max ssid) + 32 (max key) + 1 (SSID length) + 1 (security type) + 1 (key length) + +#ifndef CC3000_UNENCRYPTED_SMART_CONFIG +unsigned char key[AES128_KEY_SIZE]; +unsigned char profileArray[SMART_CONFIG_PROFILE_SIZE]; +#endif //CC3000_UNENCRYPTED_SMART_CONFIG + +/* patches type */ +#define PATCHES_HOST_TYPE_WLAN_DRIVER 0x01 +#define PATCHES_HOST_TYPE_WLAN_FW 0x02 +#define PATCHES_HOST_TYPE_BOOTLOADER 0x03 + +#define SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE (16) +#define SL_SIMPLE_CONFIG_PREFIX_LENGTH (3) +#define ETH_ALEN (6) +#define MAXIMAL_SSID_LENGTH (32) + +#define SL_PATCHES_REQUEST_DEFAULT (0) +#define SL_PATCHES_REQUEST_FORCE_HOST (1) +#define SL_PATCHES_REQUEST_FORCE_NONE (2) + + +#define WLAN_SEC_UNSEC (0) +#define WLAN_SEC_WEP (1) +#define WLAN_SEC_WPA (2) +#define WLAN_SEC_WPA2 (3) + + +#define WLAN_SL_INIT_START_PARAMS_LEN (1) +#define WLAN_PATCH_PARAMS_LENGTH (8) +#define WLAN_SET_CONNECTION_POLICY_PARAMS_LEN (12) +#define WLAN_DEL_PROFILE_PARAMS_LEN (4) +#define WLAN_SET_MASK_PARAMS_LEN (4) +#define WLAN_SET_SCAN_PARAMS_LEN (100) +#define WLAN_GET_SCAN_RESULTS_PARAMS_LEN (4) +#define WLAN_ADD_PROFILE_NOSEC_PARAM_LEN (24) +#define WLAN_ADD_PROFILE_WEP_PARAM_LEN (36) +#define WLAN_ADD_PROFILE_WPA_PARAM_LEN (44) +#define WLAN_CONNECT_PARAM_LEN (29) +#define WLAN_SMART_CONFIG_START_PARAMS_LEN (4) + + + + +//***************************************************************************** +// +//! SimpleLink_Init_Start +//! +//! @param usPatchesAvailableAtHost flag to indicate if patches available +//! from host or from EEPROM. Due to the +//! fact the patches are burn to the EEPROM +//! using the patch programmer utility, the +//! patches will be available from the EEPROM +//! and not from the host. +//! +//! @return none +//! +//! @brief Send HCI_CMND_SIMPLE_LINK_START to CC3000 +// +//***************************************************************************** +static void SimpleLink_Init_Start(unsigned short usPatchesAvailableAtHost) +{ + unsigned char *ptr; + unsigned char *args; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); + if (usPatchesAvailableAtHost > 2) + usPatchesAvailableAtHost = 2; + + UINT8_TO_STREAM(args, usPatchesAvailableAtHost); + + // IRQ Line asserted - send HCI_CMND_SIMPLE_LINK_START to CC3000 + hci_command_send(HCI_CMND_SIMPLE_LINK_START, ptr, WLAN_SL_INIT_START_PARAMS_LEN); + SimpleLinkWaitEvent(HCI_CMND_SIMPLE_LINK_START, 0); +} + + + +//***************************************************************************** +// +//! wlan_init +//! +//! @param sWlanCB Asynchronous events callback. +//! 0 no event call back. +//! -call back parameters: +//! 1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event, +//! HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event, +//! HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done, +//! HCI_EVNT_WLAN_UNSOL_DHCP dhcp report, +//! HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR +//! HCI_EVNT_WLAN_KEEPALIVE keepalive. +//! 2) data: pointer to extra data that received by the event +//! (NULL no data). +//! 3) length: data length. +//! -Events with extra data: +//! HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask, +//! 4 bytes default gateway, 4 bytes DHCP server and 4 bytes +//! for DNS server. +//! HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent, +//! 4 bytes Packets received, 4 bytes Min round time, +//! 4 bytes Max round time and 4 bytes for Avg round time. +//! +//! @param sFWPatches 0 no patch or pointer to FW patches +//! @param sDriverPatches 0 no patch or pointer to driver patches +//! @param sBootLoaderPatches 0 no patch or pointer to bootloader patches +//! @param sReadWlanInterruptPin init callback. the callback read wlan +//! interrupt status. +//! @param sWlanInterruptEnable init callback. the callback enable wlan +//! interrupt. +//! @param sWlanInterruptDisable init callback. the callback disable wlan +//! interrupt. +//! @param sWriteWlanPin init callback. the callback write value +//! to device pin. +//! +//! @return none +//! +//! @sa wlan_set_event_mask , wlan_start , wlan_stop +//! +//! @brief Initialize wlan driver +//! +//! @warning This function must be called before ANY other wlan driver function +// +//***************************************************************************** + +void wlan_init( tWlanCB sWlanCB, + tFWPatches sFWPatches, + tDriverPatches sDriverPatches, + tBootLoaderPatches sBootLoaderPatches, + tWlanReadInteruptPin sReadWlanInterruptPin, + tWlanInterruptEnable sWlanInterruptEnable, + tWlanInterruptDisable sWlanInterruptDisable, + tWriteWlanPin sWriteWlanPin) +{ + + tSLInformation.sFWPatches = sFWPatches; + tSLInformation.sDriverPatches = sDriverPatches; + tSLInformation.sBootLoaderPatches = sBootLoaderPatches; + + // init io callback + tSLInformation.ReadWlanInterruptPin = sReadWlanInterruptPin; + tSLInformation.WlanInterruptEnable = sWlanInterruptEnable; + tSLInformation.WlanInterruptDisable = sWlanInterruptDisable; + tSLInformation.WriteWlanPin = sWriteWlanPin; + + //init asynchronous events callback + tSLInformation.sWlanCB= sWlanCB; + + // By default TX Complete events are routed to host too + tSLInformation.InformHostOnTxComplete = 1; +} + +//***************************************************************************** +// +//! SpiReceiveHandler +//! +//! @param pvBuffer - pointer to the received data buffer +//! The function triggers Received event/data processing +//! +//! @param Pointer to the received data +//! @return none +//! +//! @brief The function triggers Received event/data processing. It is +//! called from the SPI library to receive the data +// +//***************************************************************************** +void SpiReceiveHandler(void *pvBuffer) +{ + tSLInformation.usEventOrDataReceived = 1; + tSLInformation.pucReceivedData = (unsigned char *)pvBuffer; + + hci_unsolicited_event_handler(); +} + + +//***************************************************************************** +// +//! wlan_start +//! +//! @param usPatchesAvailableAtHost - flag to indicate if patches available +//! from host or from EEPROM. Due to the +//! fact the patches are burn to the EEPROM +//! using the patch programmer utility, the +//! patches will be available from the EEPROM +//! and not from the host. +//! +//! @return none +//! +//! @brief Start WLAN device. This function asserts the enable pin of +//! the device (WLAN_EN), starting the HW initialization process. +//! The function blocked until device Initialization is completed. +//! Function also configure patches (FW, driver or bootloader) +//! and calls appropriate device callbacks. +//! +//! @Note Prior calling the function wlan_init shall be called. +//! @Warning This function must be called after wlan_init and before any +//! other wlan API +//! @sa wlan_init , wlan_stop +//! +// +//***************************************************************************** + +void +wlan_start(unsigned short usPatchesAvailableAtHost) +{ + + unsigned long ulSpiIRQState; + + tSLInformation.NumberOfSentPackets = 0; + tSLInformation.NumberOfReleasedPackets = 0; + tSLInformation.usRxEventOpcode = 0; + tSLInformation.usNumberOfFreeBuffers = 0; + tSLInformation.usSlBufferLength = 0; + tSLInformation.usBufferSize = 0; + tSLInformation.usRxDataPending = 0; + tSLInformation.slTransmitDataError = 0; + tSLInformation.usEventOrDataReceived = 0; + tSLInformation.pucReceivedData = 0; + + // Allocate the memory for the RX/TX data transactions + tSLInformation.pucTxCommandBuffer = (unsigned char *)wlan_tx_buffer; + + // init spi + SpiOpen(SpiReceiveHandler); + + // Check the IRQ line + ulSpiIRQState = tSLInformation.ReadWlanInterruptPin(); + + // ASIC 1273 chip enable: toggle WLAN EN line + tSLInformation.WriteWlanPin( WLAN_ENABLE ); + + if (ulSpiIRQState) + { + // wait till the IRQ line goes low + while(tSLInformation.ReadWlanInterruptPin() != 0) + { + } + } + else + { + // wait till the IRQ line goes high and than low + while(tSLInformation.ReadWlanInterruptPin() == 0) + { + } + + while(tSLInformation.ReadWlanInterruptPin() != 0) + { + } + } + DEBUGPRINT_F("SimpleLink start\n\r"); + SimpleLink_Init_Start(usPatchesAvailableAtHost); + + // Read Buffer's size and finish + DEBUGPRINT_F("Read buffer\n\r"); + hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0); + SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0); +} + + +//***************************************************************************** +// +//! wlan_stop +//! +//! @param none +//! +//! @return none +//! +//! @brief Stop WLAN device by putting it into reset state. +//! +//! @sa wlan_start +// +//***************************************************************************** + +void +wlan_stop(void) +{ + // ASIC 1273 chip disable + tSLInformation.WriteWlanPin( WLAN_DISABLE ); + + // Wait till IRQ line goes high... + while(tSLInformation.ReadWlanInterruptPin() == 0) + { + } + + // Free the used by WLAN Driver memory + if (tSLInformation.pucTxCommandBuffer) + { + tSLInformation.pucTxCommandBuffer = 0; + } + + SpiClose(); +} + + +//***************************************************************************** +// +//! wlan_connect +//! +//! @param sec_type security options: +//! WLAN_SEC_UNSEC, +//! WLAN_SEC_WEP (ASCII support only), +//! WLAN_SEC_WPA or WLAN_SEC_WPA2 +//! @param ssid up to 32 bytes and is ASCII SSID of the AP +//! @param ssid_len length of the SSID +//! @param bssid 6 bytes specified the AP bssid +//! @param key up to 16 bytes specified the AP security key +//! @param key_len key length +//! +//! @return On success, zero is returned. On error, negative is returned. +//! Note that even though a zero is returned on success to trigger +//! connection operation, it does not mean that CCC3000 is already +//! connected. An asynchronous "Connected" event is generated when +//! actual association process finishes and CC3000 is connected to +//! the AP. If DHCP is set, An asynchronous "DHCP" event is +//! generated when DHCP process is finish. +//! +//! +//! @brief Connect to AP +//! @warning Please Note that when connection to AP configured with security +//! type WEP, please confirm that the key is set as ASCII and not +//! as HEX. +//! @sa wlan_disconnect +// +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long +wlan_connect(unsigned long ulSecType, const char *ssid, long ssid_len, + unsigned char *bssid, unsigned char *key, long key_len) +{ + long ret; + unsigned char *ptr; + unsigned char *args; + unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0}; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in command buffer + args = UINT32_TO_STREAM(args, 0x0000001c); + args = UINT32_TO_STREAM(args, ssid_len); + args = UINT32_TO_STREAM(args, ulSecType); + args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len); + args = UINT32_TO_STREAM(args, key_len); + args = UINT16_TO_STREAM(args, 0); + + // padding shall be zeroed + if(bssid) + { + ARRAY_TO_STREAM(args, bssid, ETH_ALEN); + } + else + { + ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); + } + + ARRAY_TO_STREAM(args, ssid, ssid_len); + + if(key_len && key) + { + ARRAY_TO_STREAM(args, key, key_len); + } + + // Initiate a HCI command + hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN + + ssid_len + key_len - 1); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret); + errno = ret; + + return(ret); +} +#else +long +wlan_connect(const char *ssid, long ssid_len) +{ + long ret; + unsigned char *ptr; + unsigned char *args; + unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0}; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in command buffer + args = UINT32_TO_STREAM(args, 0x0000001c); + args = UINT32_TO_STREAM(args, ssid_len); + args = UINT32_TO_STREAM(args, 0); + args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len); + args = UINT32_TO_STREAM(args, 0); + args = UINT16_TO_STREAM(args, 0); + + // padding shall be zeroed + ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); + ARRAY_TO_STREAM(args, ssid, ssid_len); + + // Initiate a HCI command + hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN + + ssid_len - 1); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret); + errno = ret; + + return(ret); +} +#endif + +//***************************************************************************** +// +//! wlan_disconnect +//! +//! @return 0 disconnected done, other CC3000 already disconnected +//! +//! @brief Disconnect connection from AP. +//! +//! @sa wlan_connect +// +//***************************************************************************** + +long +wlan_disconnect() +{ + long ret; + unsigned char *ptr; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + + hci_command_send(HCI_CMND_WLAN_DISCONNECT, ptr, 0); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_DISCONNECT, &ret); + errno = ret; + + return(ret); +} + +//***************************************************************************** +// +//! wlan_ioctl_set_connection_policy +//! +//! @param should_connect_to_open_ap enable(1), disable(0) connect to any +//! available AP. This parameter corresponds to the configuration of +//! item # 3 in the brief description. +//! @param should_use_fast_connect enable(1), disable(0). if enabled, tries +//! to connect to the last connected AP. This parameter corresponds +//! to the configuration of item # 1 in the brief description. +//! @param auto_start enable(1), disable(0) auto connect +//! after reset and periodically reconnect if needed. This +//! configuration configures option 2 in the above description. +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief When auto is enabled, the device tries to connect according +//! the following policy: +//! 1) If fast connect is enabled and last connection is valid, +//! the device will try to connect to it without the scanning +//! procedure (fast). The last connection will be marked as +//! invalid, due to adding/removing profile. +//! 2) If profile exists, the device will try to connect it +//! (Up to seven profiles). +//! 3) If fast and profiles are not found, and open mode is +//! enabled, the device will try to connect to any AP. +//! * Note that the policy settings are stored in the CC3000 NVMEM. +//! +//! @sa wlan_add_profile , wlan_ioctl_del_profile +// +//***************************************************************************** + +long +wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, + unsigned long ulShouldUseFastConnect, + unsigned long ulUseProfiles) +{ + long ret; + unsigned char *ptr; + unsigned char *args; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, should_connect_to_open_ap); + args = UINT32_TO_STREAM(args, ulShouldUseFastConnect); + args = UINT32_TO_STREAM(args, ulUseProfiles); + + // Initiate a HCI command + hci_command_send(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, + ptr, WLAN_SET_CONNECTION_POLICY_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, &ret); + + return(ret); +} + +//***************************************************************************** +// +//! wlan_add_profile +//! +//! @param ulSecType WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2 +//! @param ucSsid ssid SSID up to 32 bytes +//! @param ulSsidLen ssid length +//! @param ucBssid bssid 6 bytes +//! @param ulPriority ulPriority profile priority. Lowest priority:0. +//! @param ulPairwiseCipher_Or_TxKeyLen key length for WEP security +//! @param ulGroupCipher_TxKeyIndex key index +//! @param ulKeyMgmt KEY management +//! @param ucPf_OrKey security key +//! @param ulPassPhraseLen security key length for WPA\WPA2 +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief When auto start is enabled, the device connects to +//! station from the profiles table. Up to 7 profiles are supported. +//! If several profiles configured the device choose the highest +//! priority profile, within each priority group, device will choose +//! profile based on security policy, signal strength, etc +//! parameters. All the profiles are stored in CC3000 NVMEM. +//! +//! @sa wlan_ioctl_del_profile +// +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long +wlan_add_profile(unsigned long ulSecType, + unsigned char* ucSsid, + unsigned long ulSsidLen, + unsigned char *ucBssid, + unsigned long ulPriority, + unsigned long ulPairwiseCipher_Or_TxKeyLen, + unsigned long ulGroupCipher_TxKeyIndex, + unsigned long ulKeyMgmt, + unsigned char* ucPf_OrKey, + unsigned long ulPassPhraseLen) +{ + unsigned short arg_len; + long ret; + unsigned char *ptr; + long i = 0; + unsigned char *args; + unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0}; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + args = UINT32_TO_STREAM(args, ulSecType); + + // Setup arguments in accordance with the security type + switch (ulSecType) + { + //OPEN + case WLAN_SEC_UNSEC: + { + args = UINT32_TO_STREAM(args, 0x00000014); + args = UINT32_TO_STREAM(args, ulSsidLen); + args = UINT16_TO_STREAM(args, 0); + if(ucBssid) + { + ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN); + } + else + { + ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); + } + args = UINT32_TO_STREAM(args, ulPriority); + ARRAY_TO_STREAM(args, ucSsid, ulSsidLen); + + arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ulSsidLen; + } + break; + + //WEP + case WLAN_SEC_WEP: + { + args = UINT32_TO_STREAM(args, 0x00000020); + args = UINT32_TO_STREAM(args, ulSsidLen); + args = UINT16_TO_STREAM(args, 0); + if(ucBssid) + { + ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN); + } + else + { + ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); + } + args = UINT32_TO_STREAM(args, ulPriority); + args = UINT32_TO_STREAM(args, 0x0000000C + ulSsidLen); + args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen); + args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex); + ARRAY_TO_STREAM(args, ucSsid, ulSsidLen); + + for(i = 0; i < 4; i++) + { + unsigned char *p = &ucPf_OrKey[i * ulPairwiseCipher_Or_TxKeyLen]; + + ARRAY_TO_STREAM(args, p, ulPairwiseCipher_Or_TxKeyLen); + } + + arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ulSsidLen + + ulPairwiseCipher_Or_TxKeyLen * 4; + + } + break; + + //WPA + //WPA2 + case WLAN_SEC_WPA: + case WLAN_SEC_WPA2: + { + args = UINT32_TO_STREAM(args, 0x00000028); + args = UINT32_TO_STREAM(args, ulSsidLen); + args = UINT16_TO_STREAM(args, 0); + if(ucBssid) + { + ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN); + } + else + { + ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); + } + args = UINT32_TO_STREAM(args, ulPriority); + args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen); + args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex); + args = UINT32_TO_STREAM(args, ulKeyMgmt); + args = UINT32_TO_STREAM(args, 0x00000008 + ulSsidLen); + args = UINT32_TO_STREAM(args, ulPassPhraseLen); + ARRAY_TO_STREAM(args, ucSsid, ulSsidLen); + ARRAY_TO_STREAM(args, ucPf_OrKey, ulPassPhraseLen); + + arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ulSsidLen + ulPassPhraseLen; + } + + break; + } + + // Initiate a HCI command + hci_command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, + ptr, arg_len); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret); + + return(ret); +} +#else +long +wlan_add_profile(unsigned long ulSecType, + unsigned char* ucSsid, + unsigned long ulSsidLen, + unsigned char *ucBssid, + unsigned long ulPriority, + unsigned long ulPairwiseCipher_Or_TxKeyLen, + unsigned long ulGroupCipher_TxKeyIndex, + unsigned long ulKeyMgmt, + unsigned char* ucPf_OrKey, + unsigned long ulPassPhraseLen) +{ + return -1; +} +#endif + +//***************************************************************************** +// +//! wlan_ioctl_del_profile +//! +//! @param index number of profile to delete +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Delete WLAN profile +//! +//! @Note In order to delete all stored profile, set index to 255. +//! +//! @sa wlan_add_profile +// +//***************************************************************************** + +long +wlan_ioctl_del_profile(unsigned long ulIndex) +{ + long ret; + unsigned char *ptr; + unsigned char *args; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, ulIndex); + ret = EFAIL; + + // Initiate a HCI command + hci_command_send(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, + ptr, WLAN_DEL_PROFILE_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret); + + return(ret); +} + +//***************************************************************************** +// +//! wlan_ioctl_get_scan_results +//! +//! @param[in] scan_timeout parameter not supported +//! @param[out] ucResults scan results (_wlan_full_scan_results_args_t) +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Gets entry from scan result table. +//! The scan results are returned one by one, and each entry +//! represents a single AP found in the area. The following is a +//! format of the scan result: +//! - 4 Bytes: number of networks found +//! - 4 Bytes: The status of the scan: 0 - aged results, +//! 1 - results valid, 2 - no results +//! - 42 bytes: Result entry, where the bytes are arranged as follows: +//! +//! - 1 bit isValid - is result valid or not +//! - 7 bits rssi - RSSI value; +//! - 2 bits: securityMode - security mode of the AP: +//! 0 - Open, 1 - WEP, 2 WPA, 3 WPA2 +//! - 6 bits: SSID name length +//! - 2 bytes: the time at which the entry has entered into +//! scans result table +//! - 32 bytes: SSID name +//! - 6 bytes: BSSID +//! +//! @Note scan_timeout, is not supported on this version. +//! +//! @sa wlan_ioctl_set_scan_params +// +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long +wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, + unsigned char *ucResults) +{ + unsigned char *ptr; + unsigned char *args; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, ulScanTimeout); + + // Initiate a HCI command + hci_command_send(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, + ptr, WLAN_GET_SCAN_RESULTS_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, ucResults); + + return(0); +} +#endif + +//***************************************************************************** +// +//! wlan_ioctl_set_scan_params +//! +//! @param uiEnable - start/stop application scan: +//! 1 = start scan with default interval value of 10 min. +//! in order to set a different scan interval value apply the value +//! in milliseconds. minimum 1 second. 0=stop). Wlan reset +//! (wlan_stop() wlan_start()) is needed when changing scan interval +//! value. Saved: No +//! @param uiMinDwellTime minimum dwell time value to be used for each +//! channel, in milliseconds. Saved: yes +//! Recommended Value: 100 (Default: 20) +//! @param uiMaxDwellTime maximum dwell time value to be used for each +//! channel, in milliseconds. Saved: yes +//! Recommended Value: 100 (Default: 30) +//! @param uiNumOfProbeRequests max probe request between dwell time. +//! Saved: yes. Recommended Value: 5 (Default:2) +//! @param uiChannelMask bitwise, up to 13 channels (0x1fff). +//! Saved: yes. Default: 0x7ff +//! @param uiRSSIThreshold RSSI threshold. Saved: yes (Default: -80) +//! @param uiSNRThreshold NSR threshold. Saved: yes (Default: 0) +//! @param uiDefaultTxPower probe Tx power. Saved: yes (Default: 205) +//! @param aiIntervalList pointer to array with 16 entries (16 channels) +//! each entry (unsigned long) holds timeout between periodic scan +//! (connection scan) - in millisecond. Saved: yes. Default 2000ms. +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief start and stop scan procedure. Set scan parameters. +//! +//! @Note uiDefaultTxPower, is not supported on this version. +//! +//! @sa wlan_ioctl_get_scan_results +// +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long +wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime, + unsigned long uiMaxDwellTime, + unsigned long uiNumOfProbeRequests, + unsigned long uiChannelMask,long iRSSIThreshold, + unsigned long uiSNRThreshold, + unsigned long uiDefaultTxPower, + unsigned long *aiIntervalList) +{ + unsigned long uiRes; + unsigned char *ptr; + unsigned char *args; + + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + // Fill in temporary command buffer + args = UINT32_TO_STREAM(args, 36); + args = UINT32_TO_STREAM(args, uiEnable); + args = UINT32_TO_STREAM(args, uiMinDwellTime); + args = UINT32_TO_STREAM(args, uiMaxDwellTime); + args = UINT32_TO_STREAM(args, uiNumOfProbeRequests); + args = UINT32_TO_STREAM(args, uiChannelMask); + args = UINT32_TO_STREAM(args, iRSSIThreshold); + args = UINT32_TO_STREAM(args, uiSNRThreshold); + args = UINT32_TO_STREAM(args, uiDefaultTxPower); + ARRAY_TO_STREAM(args, aiIntervalList, sizeof(unsigned long) * + SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE); + + // Initiate a HCI command + hci_command_send(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, + ptr, WLAN_SET_SCAN_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, &uiRes); + + return(uiRes); +} +#endif + +//***************************************************************************** +// +//! wlan_set_event_mask +//! +//! @param mask mask option: +//! HCI_EVNT_WLAN_UNSOL_CONNECT connect event +//! HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event +//! HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE smart config done +//! HCI_EVNT_WLAN_UNSOL_INIT init done +//! HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report +//! HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report +//! HCI_EVNT_WLAN_KEEPALIVE keepalive +//! HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission +//! Saved: no. +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Mask event according to bit mask. In case that event is +//! masked (1), the device will not send the masked event to host. +// +//***************************************************************************** + +long +wlan_set_event_mask(unsigned long ulMask) +{ + long ret; + unsigned char *ptr; + unsigned char *args; + + + if ((ulMask & HCI_EVNT_WLAN_TX_COMPLETE) == HCI_EVNT_WLAN_TX_COMPLETE) + { + tSLInformation.InformHostOnTxComplete = 0; + + // Since an event is a virtual event - i.e. it is not coming from CC3000 + // there is no need to send anything to the device if it was an only event + if (ulMask == HCI_EVNT_WLAN_TX_COMPLETE) + { + return 0; + } + + ulMask &= ~HCI_EVNT_WLAN_TX_COMPLETE; + ulMask |= HCI_EVNT_WLAN_UNSOL_BASE; + } + else + { + tSLInformation.InformHostOnTxComplete = 1; + } + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, ulMask); + + // Initiate a HCI command + hci_command_send(HCI_CMND_EVENT_MASK, + ptr, WLAN_SET_MASK_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_EVENT_MASK, &ret); + + return(ret); +} + +//***************************************************************************** +// +//! wlan_ioctl_statusget +//! +//! @param none +//! +//! @return WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING, +//! STATUS_CONNECTING or WLAN_STATUS_CONNECTED +//! +//! @brief get wlan status: disconnected, scanning, connecting or connected +// +//***************************************************************************** + +#ifndef CC3000_TINY_DRIVER +long +wlan_ioctl_statusget(void) +{ + long ret; + unsigned char *ptr; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + + hci_command_send(HCI_CMND_WLAN_IOCTL_STATUSGET, + ptr, 0); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_STATUSGET, &ret); + + return(ret); +} +#endif + +//***************************************************************************** +// +//! wlan_smart_config_start +//! +//! @param algoEncryptedFlag indicates whether the information is encrypted +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Start to acquire device profile. The device acquire its own +//! profile, if profile message is found. The acquired AP information +//! is stored in CC3000 EEPROM only in case AES128 encryption is used. +//! In case AES128 encryption is not used, a profile is created by +//! CC3000 internally. +//! +//! @Note An asynchronous event - Smart Config Done will be generated as soon +//! as the process finishes successfully. +//! +//! @sa wlan_smart_config_set_prefix , wlan_smart_config_stop +// +//***************************************************************************** + +long +wlan_smart_config_start(unsigned long algoEncryptedFlag) +{ + long ret; + unsigned char *ptr; + unsigned char *args; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); + + // Fill in HCI packet structure + args = UINT32_TO_STREAM(args, algoEncryptedFlag); + ret = EFAIL; + + hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, ptr, + WLAN_SMART_CONFIG_START_PARAMS_LEN); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, &ret); + + return(ret); +} + +//***************************************************************************** +// +//! wlan_smart_config_stop +//! +//! @param algoEncryptedFlag indicates whether the information is encrypted +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Stop the acquire profile procedure +//! +//! @sa wlan_smart_config_start , wlan_smart_config_set_prefix +// +//***************************************************************************** + +long +wlan_smart_config_stop(void) +{ + long ret; + unsigned char *ptr; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + + hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, ptr, 0); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, &ret); + + return(ret); +} + +//***************************************************************************** +// +//! wlan_smart_config_set_prefix +//! +//! @param newPrefix 3 bytes identify the SSID prefix for the Smart Config. +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Configure station ssid prefix. The prefix is used internally +//! in CC3000. It should always be TTT. +//! +//! @Note The prefix is stored in CC3000 NVMEM +//! +//! @sa wlan_smart_config_start , wlan_smart_config_stop +// +//***************************************************************************** + +long +wlan_smart_config_set_prefix(char* cNewPrefix) +{ + long ret; + unsigned char *ptr; + unsigned char *args; + + ret = EFAIL; + ptr = tSLInformation.pucTxCommandBuffer; + args = (ptr + HEADERS_SIZE_CMD); + + if (cNewPrefix == NULL) + return ret; + else // with the new Smart Config, prefix must be TTT + { + *cNewPrefix = 'T'; + *(cNewPrefix + 1) = 'T'; + *(cNewPrefix + 2) = 'T'; + } + + ARRAY_TO_STREAM(args, cNewPrefix, SL_SIMPLE_CONFIG_PREFIX_LENGTH); + + hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, ptr, + SL_SIMPLE_CONFIG_PREFIX_LENGTH); + + // Wait for command complete event + SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, &ret); + + return(ret); +} + +//***************************************************************************** +// +//! wlan_smart_config_process +//! +//! @param none +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief process the acquired data and store it as a profile. The acquired +//! AP information is stored in CC3000 EEPROM encrypted. +//! The encrypted data is decrypted and stored as a profile. +//! behavior is as defined by connection policy. +// +//***************************************************************************** + + +#ifndef CC3000_UNENCRYPTED_SMART_CONFIG +long +wlan_smart_config_process() +{ + signed long returnValue; + unsigned long ssidLen, keyLen; + unsigned char *decKeyPtr; + unsigned char *ssidPtr; + + // read the key from EEPROM - fileID 12 + returnValue = aes_read_key(key); + + if (returnValue != 0) + return returnValue; + + // read the received data from fileID #13 and parse it according to the followings: + // 1) SSID LEN - not encrypted + // 2) SSID - not encrypted + // 3) KEY LEN - not encrypted. always 32 bytes long + // 4) Security type - not encrypted + // 5) KEY - encrypted together with true key length as the first byte in KEY + // to elaborate, there are two corner cases: + // 1) the KEY is 32 bytes long. In this case, the first byte does not represent KEY length + // 2) the KEY is 31 bytes long. In this case, the first byte represent KEY length and equals 31 + returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE, 0, profileArray); + + if (returnValue != 0) + return returnValue; + + ssidPtr = &profileArray[1]; + + ssidLen = profileArray[0]; + + decKeyPtr = &profileArray[profileArray[0] + 3]; + + aes_decrypt(decKeyPtr, key); + if (profileArray[profileArray[0] + 1] > 16) + aes_decrypt((unsigned char *)(decKeyPtr + 16), key); + + if (*(unsigned char *)(decKeyPtr +31) != 0) + { + if (*decKeyPtr == 31) + { + keyLen = 31; + decKeyPtr++; + } + else + { + keyLen = 32; + } + } + else + { + keyLen = *decKeyPtr; + decKeyPtr++; + } + + // add a profile + switch (profileArray[profileArray[0] + 2]) + { + case WLAN_SEC_UNSEC://None + { + returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type + ssidPtr, // SSID + ssidLen, // SSID length + NULL, // BSSID + 1, // Priority + 0, 0, 0, 0, 0); + + break; + } + + case WLAN_SEC_WEP://WEP + { + returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type + ssidPtr, // SSID + ssidLen, // SSID length + NULL, // BSSID + 1, // Priority + keyLen, // KEY length + 0, // KEY index + 0, + decKeyPtr, // KEY + 0); + + break; + } + + case WLAN_SEC_WPA://WPA + case WLAN_SEC_WPA2://WPA2 + { + returnValue = wlan_add_profile(WLAN_SEC_WPA2, // security type + ssidPtr, + ssidLen, + NULL, // BSSID + 1, // Priority + 0x18, // PairwiseCipher + 0x1e, // GroupCipher + 2, // KEY management + decKeyPtr, // KEY + keyLen); // KEY length + + break; + } + } + + return returnValue; +} +#endif //CC3000_UNENCRYPTED_SMART_CONFIG + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** diff --git a/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/wlan.h b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/wlan.h new file mode 100755 index 0000000000..d5ccd363f5 --- /dev/null +++ b/examples/arduino-adafruit-library/lib/Adafruit_CC3000/utility/wlan.h @@ -0,0 +1,533 @@ +/***************************************************************************** +* +* wlan.h - CC3000 Host Driver Implementation. +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* +* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend) +* & Limor Fried for Adafruit Industries +* This library works with the Adafruit CC3000 breakout +* ----> https://www.adafruit.com/products/1469 +* Adafruit invests time and resources providing this open source code, +* please support Adafruit and open-source hardware by purchasing +* products from Adafruit! +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* + +Adapted for use with the Arduino/AVR by KTOWN for Adafruit Industries +This library works with the Adafruit CC3000 breakout + ----> https://www.adafruit.com/products/1469 +Adafruit invests time and resources providing this open source code, +please support Adafruit and open-source hardware by purchasing +products from Adafruit! + +*****************************************************************************/ +#ifndef __WLAN_H__ +#define __WLAN_H__ + +#include "cc3000_common.h" + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" { +#endif + +#define WLAN_SEC_UNSEC (0) +#define WLAN_SEC_WEP (1) +#define WLAN_SEC_WPA (2) +#define WLAN_SEC_WPA2 (3) +//***************************************************************************** +// +//! \addtogroup wlan_api +//! @{ +// +//***************************************************************************** + + +//***************************************************************************** +// +//! wlan_init +//! +//! @param sWlanCB Asynchronous events callback. +//! 0 no event call back. +//! -call back parameters: +//! 1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event, +//! HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event, +//! HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done, +//! HCI_EVNT_WLAN_UNSOL_DHCP dhcp report, +//! HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR +//! HCI_EVNT_WLAN_KEEPALIVE keepalive. +//! 2) data: pointer to extra data that received by the event +//! (NULL no data). +//! 3) length: data length. +//! -Events with extra data: +//! HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask, +//! 4 bytes default gateway, 4 bytes DHCP server and 4 bytes +//! for DNS server. +//! HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent, +//! 4 bytes Packets received, 4 bytes Min round time, +//! 4 bytes Max round time and 4 bytes for Avg round time. +//! +//! @param sFWPatches 0 no patch or pointer to FW patches +//! @param sDriverPatches 0 no patch or pointer to driver patches +//! @param sBootLoaderPatches 0 no patch or pointer to bootloader patches +//! @param sReadWlanInterruptPin init callback. the callback read wlan +//! interrupt status. +//! @param sWlanInterruptEnable init callback. the callback enable wlan +//! interrupt. +//! @param sWlanInterruptDisable init callback. the callback disable wlan +//! interrupt. +//! @param sWriteWlanPin init callback. the callback write value +//! to device pin. +//! +//! @return none +//! +//! @sa wlan_set_event_mask , wlan_start , wlan_stop +//! +//! @brief Initialize wlan driver +//! +//! @warning This function must be called before ANY other wlan driver function +// +//***************************************************************************** +extern void wlan_init( tWlanCB sWlanCB, + tFWPatches sFWPatches, + tDriverPatches sDriverPatches, + tBootLoaderPatches sBootLoaderPatches, + tWlanReadInteruptPin sReadWlanInterruptPin, + tWlanInterruptEnable sWlanInterruptEnable, + tWlanInterruptDisable sWlanInterruptDisable, + tWriteWlanPin sWriteWlanPin); + + + +//***************************************************************************** +// +//! wlan_start +//! +//! @param usPatchesAvailableAtHost - flag to indicate if patches available +//! from host or from EEPROM. Due to the +//! fact the patches are burn to the EEPROM +//! using the patch programmer utility, the +//! patches will be available from the EEPROM +//! and not from the host. +//! +//! @return none +//! +//! @brief Start WLAN device. This function asserts the enable pin of +//! the device (WLAN_EN), starting the HW initialization process. +//! The function blocked until device Initialization is completed. +//! Function also configure patches (FW, driver or bootloader) +//! and calls appropriate device callbacks. +//! +//! @Note Prior calling the function wlan_init shall be called. +//! @Warning This function must be called after wlan_init and before any +//! other wlan API +//! @sa wlan_init , wlan_stop +//! +// +//***************************************************************************** +extern void wlan_start(unsigned short usPatchesAvailableAtHost); + +//***************************************************************************** +// +//! wlan_stop +//! +//! @param none +//! +//! @return none +//! +//! @brief Stop WLAN device by putting it into reset state. +//! +//! @sa wlan_start +// +//***************************************************************************** +extern void wlan_stop(void); + +//***************************************************************************** +// +//! wlan_connect +//! +//! @param sec_type security options: +//! WLAN_SEC_UNSEC, +//! WLAN_SEC_WEP (ASCII support only), +//! WLAN_SEC_WPA or WLAN_SEC_WPA2 +//! @param ssid up to 32 bytes and is ASCII SSID of the AP +//! @param ssid_len length of the SSID +//! @param bssid 6 bytes specified the AP bssid +//! @param key up to 16 bytes specified the AP security key +//! @param key_len key length +//! +//! @return On success, zero is returned. On error, negative is returned. +//! Note that even though a zero is returned on success to trigger +//! connection operation, it does not mean that CCC3000 is already +//! connected. An asynchronous "Connected" event is generated when +//! actual association process finishes and CC3000 is connected to +//! the AP. If DHCP is set, An asynchronous "DHCP" event is +//! generated when DHCP process is finish. +//! +//! +//! @brief Connect to AP +//! @warning Please Note that when connection to AP configured with security +//! type WEP, please confirm that the key is set as ASCII and not +//! as HEX. +//! @sa wlan_disconnect +// +//***************************************************************************** +#ifndef CC3000_TINY_DRIVER +extern long wlan_connect(unsigned long ulSecType, const char *ssid, long ssid_len, + unsigned char *bssid, unsigned char *key, long key_len); +#else +extern long wlan_connect(const char *ssid, long ssid_len); + +#endif + +//***************************************************************************** +// +//! wlan_disconnect +//! +//! @return 0 disconnected done, other CC3000 already disconnected +//! +//! @brief Disconnect connection from AP. +//! +//! @sa wlan_connect +// +//***************************************************************************** + +extern long wlan_disconnect(void); + +//***************************************************************************** +// +//! wlan_add_profile +//! +//! @param ulSecType WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2 +//! @param ucSsid ssid SSID up to 32 bytes +//! @param ulSsidLen ssid length +//! @param ucBssid bssid 6 bytes +//! @param ulPriority ulPriority profile priority. Lowest priority:0. +//! @param ulPairwiseCipher_Or_TxKeyLen key length for WEP security +//! @param ulGroupCipher_TxKeyIndex key index +//! @param ulKeyMgmt KEY management +//! @param ucPf_OrKey security key +//! @param ulPassPhraseLen security key length for WPA\WPA2 +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief When auto start is enabled, the device connects to +//! station from the profiles table. Up to 7 profiles are supported. +//! If several profiles configured the device choose the highest +//! priority profile, within each priority group, device will choose +//! profile based on security policy, signal strength, etc +//! parameters. All the profiles are stored in CC3000 NVMEM. +//! +//! @sa wlan_ioctl_del_profile +// +//***************************************************************************** + +extern long wlan_add_profile(unsigned long ulSecType, unsigned char* ucSsid, + unsigned long ulSsidLen, + unsigned char *ucBssid, + unsigned long ulPriority, + unsigned long ulPairwiseCipher_Or_Key, + unsigned long ulGroupCipher_TxKeyLen, + unsigned long ulKeyMgmt, + unsigned char* ucPf_OrKey, + unsigned long ulPassPhraseLen); + + + +//***************************************************************************** +// +//! wlan_ioctl_del_profile +//! +//! @param index number of profile to delete +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Delete WLAN profile +//! +//! @Note In order to delete all stored profile, set index to 255. +//! +//! @sa wlan_add_profile +// +//***************************************************************************** +extern long wlan_ioctl_del_profile(unsigned long ulIndex); + +//***************************************************************************** +// +//! wlan_set_event_mask +//! +//! @param mask mask option: +//! HCI_EVNT_WLAN_UNSOL_CONNECT connect event +//! HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event +//! HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE smart config done +//! HCI_EVNT_WLAN_UNSOL_INIT init done +//! HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report +//! HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report +//! HCI_EVNT_WLAN_KEEPALIVE keepalive +//! HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission +//! Saved: no. +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Mask event according to bit mask. In case that event is +//! masked (1), the device will not send the masked event to host. +// +//***************************************************************************** +extern long wlan_set_event_mask(unsigned long ulMask); + +//***************************************************************************** +// +//! wlan_ioctl_statusget +//! +//! @param none +//! +//! @return WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING, +//! STATUS_CONNECTING or WLAN_STATUS_CONNECTED +//! +//! @brief get wlan status: disconnected, scanning, connecting or connected +// +//***************************************************************************** +extern long wlan_ioctl_statusget(void); + + +//***************************************************************************** +// +//! wlan_ioctl_set_connection_policy +//! +//! @param should_connect_to_open_ap enable(1), disable(0) connect to any +//! available AP. This parameter corresponds to the configuration of +//! item # 3 in the brief description. +//! @param should_use_fast_connect enable(1), disable(0). if enabled, tries +//! to connect to the last connected AP. This parameter corresponds +//! to the configuration of item # 1 in the brief description. +//! @param auto_start enable(1), disable(0) auto connect +//! after reset and periodically reconnect if needed. This +//! configuration configures option 2 in the above description. +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief When auto is enabled, the device tries to connect according +//! the following policy: +//! 1) If fast connect is enabled and last connection is valid, +//! the device will try to connect to it without the scanning +//! procedure (fast). The last connection will be marked as +//! invalid, due to adding/removing profile. +//! 2) If profile exists, the device will try to connect it +//! (Up to seven profiles). +//! 3) If fast and profiles are not found, and open mode is +//! enabled, the device will try to connect to any AP. +//! * Note that the policy settings are stored in the CC3000 NVMEM. +//! +//! @sa wlan_add_profile , wlan_ioctl_del_profile +// +//***************************************************************************** +extern long wlan_ioctl_set_connection_policy( + unsigned long should_connect_to_open_ap, + unsigned long should_use_fast_connect, + unsigned long ulUseProfiles); + +//***************************************************************************** +// +//! wlan_ioctl_get_scan_results +//! +//! @param[in] scan_timeout parameter not supported +//! @param[out] ucResults scan result (_wlan_full_scan_results_args_t) +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Gets entry from scan result table. +//! The scan results are returned one by one, and each entry +//! represents a single AP found in the area. The following is a +//! format of the scan result: +//! - 4 Bytes: number of networks found +//! - 4 Bytes: The status of the scan: 0 - aged results, +//! 1 - results valid, 2 - no results +//! - 42 bytes: Result entry, where the bytes are arranged as follows: +//! +//! - 1 bit isValid - is result valid or not +//! - 7 bits rssi - RSSI value; +//! - 2 bits: securityMode - security mode of the AP: +//! 0 - Open, 1 - WEP, 2 WPA, 3 WPA2 +//! - 6 bits: SSID name length +//! - 2 bytes: the time at which the entry has entered into +//! scans result table +//! - 32 bytes: SSID name +//! - 6 bytes: BSSID +//! +//! @Note scan_timeout, is not supported on this version. +//! +//! @sa wlan_ioctl_set_scan_params +// +//***************************************************************************** + + +extern long wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, + unsigned char *ucResults); + +//***************************************************************************** +// +//! wlan_ioctl_set_scan_params +//! +//! @param uiEnable - start/stop application scan: +//! 1 = start scan with default interval value of 10 min. +//! in order to set a different scan interval value apply the value +//! in milliseconds. minimum 1 second. 0=stop). Wlan reset +//! (wlan_stop() wlan_start()) is needed when changing scan interval +//! value. Saved: No +//! @param uiMinDwellTime minimum dwell time value to be used for each +//! channel, in milliseconds. Saved: yes +//! Recommended Value: 100 (Default: 20) +//! @param uiMaxDwellTime maximum dwell time value to be used for each +//! channel, in milliseconds. Saved: yes +//! Recommended Value: 100 (Default: 30) +//! @param uiNumOfProbeRequests max probe request between dwell time. +//! Saved: yes. Recommended Value: 5 (Default:2) +//! @param uiChannelMask bitwise, up to 13 channels (0x1fff). +//! Saved: yes. Default: 0x7ff +//! @param uiRSSIThreshold RSSI threshold. Saved: yes (Default: -80) +//! @param uiSNRThreshold NSR threshold. Saved: yes (Default: 0) +//! @param uiDefaultTxPower probe Tx power. Saved: yes (Default: 205) +//! @param aiIntervalList pointer to array with 16 entries (16 channels) +//! each entry (unsigned long) holds timeout between periodic scan +//! (connection scan) - in milliseconds. Saved: yes. Default 2000ms. +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief start and stop scan procedure. Set scan parameters. +//! +//! @Note uiDefaultTxPower, is not supported on this version. +//! +//! @sa wlan_ioctl_get_scan_results +// +//***************************************************************************** +extern long wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long + uiMinDwellTime,unsigned long uiMaxDwellTime, + unsigned long uiNumOfProbeRequests, + unsigned long uiChannelMask, + long iRSSIThreshold,unsigned long uiSNRThreshold, + unsigned long uiDefaultTxPower, + unsigned long *aiIntervalList); + + +//***************************************************************************** +// +//! wlan_smart_config_start +//! +//! @param algoEncryptedFlag indicates whether the information is encrypted +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Start to acquire device profile. The device acquire its own +//! profile, if profile message is found. The acquired AP information +//! is stored in CC3000 EEPROM only in case AES128 encryption is used. +//! In case AES128 encryption is not used, a profile is created by +//! CC3000 internally. +//! +//! @Note An asynchronous event - Smart Config Done will be generated as soon +//! as the process finishes successfully. +//! +//! @sa wlan_smart_config_set_prefix , wlan_smart_config_stop +// +//***************************************************************************** +extern long wlan_smart_config_start(unsigned long algoEncryptedFlag); + + +//***************************************************************************** +// +//! wlan_smart_config_stop +//! +//! @param algoEncryptedFlag indicates whether the information is encrypted +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Stop the acquire profile procedure +//! +//! @sa wlan_smart_config_start , wlan_smart_config_set_prefix +// +//***************************************************************************** +extern long wlan_smart_config_stop(void); + +//***************************************************************************** +// +//! wlan_smart_config_set_prefix +//! +//! @param newPrefix 3 bytes identify the SSID prefix for the Smart Config. +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief Configure station ssid prefix. The prefix is used internally +//! in CC3000. It should always be TTT. +//! +//! @Note The prefix is stored in CC3000 NVMEM +//! +//! @sa wlan_smart_config_start , wlan_smart_config_stop +// +//***************************************************************************** +extern long wlan_smart_config_set_prefix(char* cNewPrefix); + +//***************************************************************************** +// +//! wlan_smart_config_process +//! +//! @param none +//! +//! @return On success, zero is returned. On error, -1 is returned +//! +//! @brief process the acquired data and store it as a profile. The acquired +//! AP information is stored in CC3000 EEPROM encrypted. +//! The encrypted data is decrypted and stored as a profile. +//! behavior is as defined by connection policy. +// +//***************************************************************************** +extern long wlan_smart_config_process(void); + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** + + + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // __WLAN_H__ diff --git a/examples/arduino-adafruit-library/platformio.ini b/examples/arduino-adafruit-library/platformio.ini new file mode 100644 index 0000000000..109c539a26 --- /dev/null +++ b/examples/arduino-adafruit-library/platformio.ini @@ -0,0 +1,7 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +[env:microduino] +platform = atmelavr +framework = arduino +board = 644pa16m diff --git a/examples/arduino-adafruit-library/src/EchoServer.ino b/examples/arduino-adafruit-library/src/EchoServer.ino new file mode 100755 index 0000000000..e747cd85f6 --- /dev/null +++ b/examples/arduino-adafruit-library/src/EchoServer.ino @@ -0,0 +1,185 @@ + +/*************************************************** + Adafruit CC3000 Breakout/Shield TCP Echo Server + + This is a simple implementation of the echo + protocol, RFC 862 http://tools.ietf.org/html/rfc862 , + for the Arduino platform and Adafruit CC3000 breakout + or shield. This sketch will create a TCP server that + listens by default on port 7 and echos back any data + received. Up to 3 clients can be connected concurrently + to the server. This sketch is meant as an example of how + to write a simple server with the Arduino and CC3000. + + See the CC3000 tutorial on Adafruit's learning system + for more information on setting up and using the + CC3000: + http://learn.adafruit.com/adafruit-cc3000-wifi + + Requirements: + + This sketch requires the Adafruit CC3000 library. You can + download the library from: + https://github.com/adafruit/Adafruit_CC3000_Library + + For information on installing libraries in the Arduino IDE + see this page: + http://arduino.cc/en/Guide/Libraries + + Usage: + + Update the SSID and, if necessary, the CC3000 hardware pin + information below, then run the sketch and check the + output of the serial port. After connecting to the + wireless network successfully the sketch will output + the IP address of the server and start listening for + connections. Once listening for connections, connect + to the server from your computer using a telnet client + on port 7. + + For example on Linux or Mac OSX, if your CC3000 has an + IP address 192.168.1.100 you would execute in a command + window: + + telnet 192.168.1.100 7 + + After connecting, notice that as you type input and + press enter to send it the CC3000 will echo back exactly + what you typed. Press ctrl-] and type quit at the prompt + to close the telnet session. + + On Windows you'll need to download a telnet client. PuTTY + is a good, free GUI client: + http://www.chiark.greenend.org.uk/~sgtatham/putty/ + + License: + + This example is copyright (c) 2013 Tony DiCola (tony@tonydicola.com) + and is released under an open source MIT license. See details at: + http://opensource.org/licenses/MIT + + This code was adapted from Adafruit CC3000 library example + code which has the following license: + + Designed specifically to work with the Adafruit WiFi products: + ----> https://www.adafruit.com/products/1469 + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried & Kevin Townsend for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ +#include +#include +#include "utility/debug.h" +#include "utility/socket.h" + +// These are the interrupt and control pins +#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! +// These can be any two pins +#define ADAFRUIT_CC3000_VBAT 5 +#define ADAFRUIT_CC3000_CS 10 +// Use hardware SPI for the remaining pins +// On an UNO, SCK = 13, MISO = 12, and MOSI = 11 +Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, + SPI_CLOCK_DIVIDER); // you can change this clock speed + +#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters! +#define WLAN_PASS "myPassword" +// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 +#define WLAN_SECURITY WLAN_SEC_WPA2 + +#define LISTEN_PORT 7 // What TCP port to listen on for connections. The echo protocol uses port 7. + +Adafruit_CC3000_Server echoServer(LISTEN_PORT); + +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Hello, CC3000!\n")); + + Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); + + /* Initialise the module */ + Serial.println(F("\nInitializing...")); + if (!cc3000.begin()) + { + Serial.println(F("Couldn't begin()! Check your wiring?")); + while(1); + } + + Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID); + if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { + Serial.println(F("Failed!")); + while(1); + } + + Serial.println(F("Connected!")); + + Serial.println(F("Request DHCP")); + while (!cc3000.checkDHCP()) + { + delay(100); // ToDo: Insert a DHCP timeout! + } + + /* Display the IP address DNS, Gateway, etc. */ + while (! displayConnectionDetails()) { + delay(1000); + } + + /*********************************************************/ + /* You can safely remove this to save some flash memory! */ + /*********************************************************/ + Serial.println(F("\r\nNOTE: This sketch may cause problems with other sketches")); + Serial.println(F("since the .disconnect() function is never called, so the")); + Serial.println(F("AP may refuse connection requests from the CC3000 until a")); + Serial.println(F("timeout period passes. This is normal behaviour since")); + Serial.println(F("there isn't an obvious moment to disconnect with a server.\r\n")); + + // Start listening for connections + echoServer.begin(); + + Serial.println(F("Listening for connections...")); +} + +void loop(void) +{ + // Try to get a client which is connected. + Adafruit_CC3000_ClientRef client = echoServer.available(); + if (client) { + // Check if there is data available to read. + if (client.available() > 0) { + // Read a byte and write it to all clients. + uint8_t ch = client.read(); + client.write(ch); + } + } +} + +/**************************************************************************/ +/*! + @brief Tries to read the IP address and other connection details +*/ +/**************************************************************************/ +bool displayConnectionDetails(void) +{ + uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv; + + if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) + { + Serial.println(F("Unable to retrieve the IP Address!\r\n")); + return false; + } + else + { + Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress); + Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask); + Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway); + Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv); + Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv); + Serial.println(); + return true; + } +} diff --git a/platformio/__init__.py b/platformio/__init__.py index df358fd3fc..ca8fbc5a65 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,12 +1,11 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (0, 4, 0) +VERSION = (0, 5, 0) __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" -__description__ = ("A console tool to build code with different " - "development platforms") +__description__ = ("A cross-platform code builder and library manager") __url__ = "https://github.com/ivankravets/platformio" __author__ = "Ivan Kravets" diff --git a/platformio/__main__.py b/platformio/__main__.py index bf8f26d010..3fa96c6f5c 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -1,16 +1,18 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -from os import listdir -from os.path import join +from os import listdir, makedirs +from os.path import getmtime, isdir, isfile, join from sys import exit as sys_exit +from time import time from traceback import format_exc -from click import command, MultiCommand, version_option +from click import command, MultiCommand, secho, version_option from platformio import __version__ +from platformio.commands.upgrade import get_latest_version from platformio.exception import PlatformioException, UnknownCLICommand -from platformio.util import get_source_dir +from platformio.util import get_home_dir, get_source_dir class PlatformioCLI(MultiCommand): @@ -40,8 +42,25 @@ def cli(): pass +def autocheck_latest_version(): + check_interval = 3600 * 24 * 7 # 1 week + checkfile = join(get_home_dir(), ".pioupgrade") + if isfile(checkfile) and getmtime(checkfile) > (time() - check_interval): + return False + if not isdir(get_home_dir()): + makedirs(get_home_dir()) + with open(checkfile, "w") as f: + f.write(str(time())) + return get_latest_version() != __version__ + + def main(): try: + if autocheck_latest_version(): + secho("\nThere is a new version of PlatformIO available.\n" + "Please upgrade it via `platformio upgrade` command.\n", + fg="yellow") + cli() except Exception as e: # pylint: disable=W0703 if isinstance(e, PlatformioException): diff --git a/platformio/builder/scripts/atmelavr.py b/platformio/builder/scripts/atmelavr.py index 6cb008be11..dcaed8f637 100644 --- a/platformio/builder/scripts/atmelavr.py +++ b/platformio/builder/scripts/atmelavr.py @@ -6,6 +6,7 @@ """ from os.path import join +from time import sleep from SCons.Script import (AlwaysBuild, Builder, COMMAND_LINE_TARGETS, Default, DefaultEnvironment, Exit) @@ -33,10 +34,10 @@ CCFLAGS=[ "-g", # include debugging info (so errors include line numbers) "-Os", # optimize for size - "-Wall", # show warnings + # "-Wall", # show warnings "-ffunction-sections", # place each function in its own section "-fdata-sections", - "-MMD", # output dependancy info + "-MMD", # output dependency info "-mmcu=$BOARD_MCU" ], @@ -99,13 +100,31 @@ ) ) -BUILT_LIBS = env.ProcessGeneral() + +def reset_device(): + + def rpi_sysgpio(path, value): + with open(path, "w") as f: + f.write(str(value)) + + if env.subst("$BOARD") == "raspduino": + rpi_sysgpio("/sys/class/gpio/export", 18) + rpi_sysgpio("/sys/class/gpio/gpio18/direction", "out") + rpi_sysgpio("/sys/class/gpio/gpio18/value", 1) + sleep(0.1) + rpi_sysgpio("/sys/class/gpio/gpio18/value", 0) + rpi_sysgpio("/sys/class/gpio/unexport", 18) + else: + return reset_serialport(env.subst("$UPLOAD_PORT")) + + +CORELIBS = env.ProcessGeneral() # # Target: Build executable and linkable firmware # -target_elf = env.BuildFirmware(BUILT_LIBS + ["m"]) +target_elf = env.BuildFirmware(CORELIBS + ["m"]) # # Target: Extract EEPROM data (from EEMEM directive) to .eep file @@ -128,8 +147,7 @@ # upload = env.Alias(["upload", "uploadlazy"], target_hex, [ - lambda target, source, env: reset_serialport(env.subst("$UPLOAD_PORT")), - "$UPLOADHEXCMD"]) + lambda target, source, env: reset_device(), "$UPLOADHEXCMD"]) AlwaysBuild(upload) # @@ -137,8 +155,7 @@ # uploadeep = env.Alias("uploadeep", target_eep, [ - lambda target, source, env: reset_serialport(env.subst("$UPLOAD_PORT")), - "$UPLOADEEPCMD"]) + lambda target, source, env: reset_device(), "$UPLOADEEPCMD"]) AlwaysBuild(uploadeep) # diff --git a/platformio/builder/scripts/timsp430.py b/platformio/builder/scripts/timsp430.py index 6a82a0e3da..cd81bce787 100644 --- a/platformio/builder/scripts/timsp430.py +++ b/platformio/builder/scripts/timsp430.py @@ -33,7 +33,7 @@ CCFLAGS=[ "-g", # include debugging info (so errors include line numbers) "-Os", # optimize for size - "-Wall", # show warnings + # "-Wall", # show warnings "-ffunction-sections", # place each function in its own section "-fdata-sections", "-MMD", # output dependancy info @@ -75,13 +75,13 @@ ) ) -BUILT_LIBS = env.ProcessGeneral() +CORELIBS = env.ProcessGeneral() # # Target: Build executable and linkable firmware # -target_elf = env.BuildFirmware(BUILT_LIBS + ["m"]) +target_elf = env.BuildFirmware(CORELIBS + ["m"]) # # Target: Build the .hex diff --git a/platformio/builder/scripts/titiva.py b/platformio/builder/scripts/titiva.py index ffb538d026..8dacd75f78 100644 --- a/platformio/builder/scripts/titiva.py +++ b/platformio/builder/scripts/titiva.py @@ -37,7 +37,7 @@ CCFLAGS=[ "-g", # include debugging info (so errors include line numbers) "-Os", # optimize for size - "-Wall", # show warnings + # "-Wall", # show warnings "-ffunction-sections", # place each function in its own section "-fdata-sections", "-Wall", @@ -89,13 +89,13 @@ ) ) -BUILT_LIBS = env.ProcessGeneral() +CORELIBS = env.ProcessGeneral() # # Target: Build executable and linkable firmware # -target_elf = env.BuildFirmware(BUILT_LIBS + ["c", "gcc", "m"]) +target_elf = env.BuildFirmware(CORELIBS + ["c", "gcc", "m"]) # # Target: Build the .bin file diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 9216c6061b..1f4d456e32 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -1,15 +1,16 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. +import atexit import re -from os import getenv, listdir, walk -from os.path import isdir, isfile, join +from os import getenv, listdir, remove, walk +from os.path import basename, isdir, isfile, join from SCons.Script import SConscript, SConscriptChdir def ProcessGeneral(env): - libs = [] + corelibs = [] if "BUILD_FLAGS" in env: env.MergeFlags(env['BUILD_FLAGS']) @@ -19,56 +20,31 @@ def ProcessGeneral(env): ) if "FRAMEWORK" in env: + if env['FRAMEWORK'] in ("arduino", "energia"): + env.ConvertInotoCpp() SConscriptChdir(0) - libs = SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", - "frameworks", "${FRAMEWORK}.py")), - exports="env") - return libs - - -def BuildLibrary(env, variant_dir, library_dir): - lib = env.Clone() - vdirs = lib.VariantDirRecursive(variant_dir, library_dir) - return lib.Library( - lib.subst(variant_dir), - [lib.GlobCXXFiles(vdir) for vdir in vdirs] - ) - - -def BuildDependentLibraries(env, src_dir): - libs = [] - for deplibfile in env.GetDependentLibraries(src_dir): - for lsd_dir in env['LIBSOURCE_DIRS']: - lsd_dir = env.subst(lsd_dir) - if not isdir(lsd_dir): - continue - for libname in listdir(lsd_dir): - if not isfile(join(lsd_dir, libname, deplibfile)): - continue - _libbuild_dir = join("$BUILD_DIR", libname) - env.Append(CPPPATH=[_libbuild_dir]) - libs.append( - env.BuildLibrary(_libbuild_dir, join(lsd_dir, libname))) - return libs + corelibs = SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", + "frameworks", "${FRAMEWORK}.py")), + exports="env") + return corelibs -def BuildFirmware(env, libslist): +def BuildFirmware(env, corelibs): src = env.Clone() vdirs = src.VariantDirRecursive( join("$BUILD_DIR", "src"), join("$PROJECT_DIR", "src")) # build source's dependent libs + deplibs = [] for vdir in vdirs: - _libs = src.BuildDependentLibraries(vdir) - if _libs: - libslist += _libs + deplibs += src.BuildDependentLibraries(vdir) src.MergeFlags(getenv("PIOSRCBUILD_FLAGS", "$SRCBUILD_FLAGS")) return src.Program( join("$BUILD_DIR", "firmware"), [src.GlobCXXFiles(vdir) for vdir in vdirs], - LIBS=libslist, + LIBS=deplibs + corelibs, LIBPATH="$BUILD_DIR", PROGSUFFIX=".elf") @@ -82,12 +58,59 @@ def GlobCXXFiles(env, path): return files +def BuildLibrary(env, variant_dir, library_dir): + lib = env.Clone() + vdirs = lib.VariantDirRecursive(variant_dir, library_dir) + return lib.Library( + lib.subst(variant_dir), + [lib.GlobCXXFiles(vdir) for vdir in vdirs] + ) + + +def BuildDependentLibraries(env, src_dir): + libs = [] + deplibs = env.GetDependentLibraries(src_dir) + env.Append(CPPPATH=[join("$BUILD_DIR", l) for (l, _) in deplibs]) + + for (libname, lsd_dir) in deplibs: + lib = env.BuildLibrary( + join("$BUILD_DIR", libname), join(lsd_dir, libname)) + env.Clean(libname, lib) + libs.append(lib) + return libs + + def GetDependentLibraries(env, src_dir): - deplibs = [] - regexp = re.compile(r"^#include\s+<([^>]+)>", re.M) + includes = {} + regexp = re.compile(r"^\s*#include\s+(?:\<|\")([^\>\"\']+)(?:\>|\")", re.M) for node in env.GlobCXXFiles(src_dir): - deplibs += regexp.findall(node.get_text_contents()) - return deplibs + env.ParseIncludesRecurive(regexp, node, includes) + includes = sorted(includes.items(), key=lambda s: s[0]) + + result = [] + for i in includes: + item = (i[1][1], i[1][2]) + if item in result: + continue + result.append(item) + return result + + +def ParseIncludesRecurive(env, regexp, source_file, includes): + matches = regexp.findall(source_file.get_text_contents()) + for inc_name in matches: + if inc_name in includes: + continue + for lsd_dir in env['LIBSOURCE_DIRS']: + lsd_dir = env.subst(lsd_dir) + if not isdir(lsd_dir): + continue + for libname in listdir(lsd_dir): + inc_path = join(lsd_dir, libname, inc_name) + if not isfile(inc_path): + continue + includes[inc_name] = (len(includes) + 1, libname, lsd_dir) + env.ParseIncludesRecurive(regexp, env.File(inc_path), includes) def VariantDirRecursive(env, variant_dir, src_dir, duplicate=True): @@ -135,17 +158,59 @@ def ParseBoardOptions(env, path, name): return data +def ConvertInotoCpp(env): + + def delete_tmpcpp(files): + for f in files: + remove(f) + + tmpcpp = [] + + for item in env.Glob(join("$PROJECT_DIR", "src", "*.ino")): + cppfile = item.get_path()[:-3] + "cpp" + if isfile(cppfile): + continue + ino_contents = item.get_text_contents() + + # fetch prototypes + regexp = re.compile( + r"""^( + (?:\s*[a-z_\d]+){1,2} # return type + \s+[a-z_\d]+\s* # name of prototype + \([a-z_,\.\*\&\s\d]+\) # args + )\s*\{ # must end with { + """, + re.X | re.M | re.I + ) + prototypes = regexp.findall(ino_contents) + # print prototypes + + # create new temporary C++ valid file + with open(cppfile, "w") as f: + f.write("#include \n") + if prototypes: + f.write("%s;\n" % ";\n".join(prototypes)) + f.write("#line 1 \"%s\"\n" % basename(item.path)) + f.write(ino_contents) + tmpcpp.append(cppfile) + + if tmpcpp: + atexit.register(delete_tmpcpp, tmpcpp) + + def exists(_): return True def generate(env): env.AddMethod(ProcessGeneral) - env.AddMethod(BuildLibrary) - env.AddMethod(BuildDependentLibraries) env.AddMethod(BuildFirmware) env.AddMethod(GlobCXXFiles) + env.AddMethod(BuildLibrary) + env.AddMethod(BuildDependentLibraries) env.AddMethod(GetDependentLibraries) + env.AddMethod(ParseIncludesRecurive) env.AddMethod(VariantDirRecursive) env.AddMethod(ParseBoardOptions) + env.AddMethod(ConvertInotoCpp) return env diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 4422c1d054..5e989c1798 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -56,4 +56,5 @@ def cli(environment, target, upload_port): p = PlatformFactory().newPlatform(config.get(section, "platform")) result = p.run(variables, envtargets) secho(result['out'], fg="green") - secho(result['err'], fg="red") + secho(result['err'], + fg="red" if "Error" in result['err'] else "yellow") diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py new file mode 100644 index 0000000000..2f211d367d --- /dev/null +++ b/platformio/commands/upgrade.py @@ -0,0 +1,30 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +from click import command, secho +from requests import get + +from platformio import __version__ +from platformio.exception import GetLatestVersionError +from platformio.util import exec_command + + +@command("upgrade", short_help="Upgrade PlatformIO to the latest version") +def cli(): + try: + last = get_latest_version() + except: + raise GetLatestVersionError() + + if __version__ == last: + return secho("You're up-to-date!\nPlatformIO %s is currently the " + "newest version available." % __version__, fg="green") + else: + result = exec_command(["pip", "install", "--upgrade", "platformio"]) + secho(result['out'], fg="green") + secho(result['err'], fg="red") + + +def get_latest_version(): + pkgdata = get("https://pypi.python.org/pypi/platformio/json").json() + return pkgdata['info']['version'] diff --git a/platformio/exception.py b/platformio/exception.py index 7b7d08f182..046ad0846e 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -100,3 +100,8 @@ class UnknownEnvNames(PlatformioException): class GetSerialPortsError(PlatformioException): MESSAGE = "No implementation for your platform ('%s') available" + + +class GetLatestVersionError(PlatformioException): + + MESSAGE = "Can't retrieve latest PlatformIO version" diff --git a/platformio/util.py b/platformio/util.py index 3604c84d34..8fb6363ba9 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -53,7 +53,7 @@ def get_project_config(): def get_platforms(): platforms = [] for p in listdir(join(get_source_dir(), "platforms")): - if p.startswith("_") or not p.endswith(".py"): + if p in ("__init__.py", "base.py") or not p.endswith(".py"): continue platforms.append(p[:-3]) return platforms diff --git a/setup.py b/setup.py index 2850082816..00be748247 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -from sys import platform as sysplatform +from platform import system from setuptools import find_packages, setup @@ -22,7 +22,7 @@ "pyserial", "requests", # "SCons" - ] + (["colorama"] if sysplatform.startswith("win") else []), + ] + (["colorama"] if system() == "Windows" else []), packages=find_packages(), package_data={"platformio": ["*.ini"]}, entry_points={ diff --git a/tox.ini b/tox.ini index ed6145475c..c57c77d361 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,6 @@ usedevelop = True deps = isort flake8 - wheel commands = pip install --egg scons