cc3000 hostdriver with the mbed socket interface
Fork of cc3000_hostdriver_mbedsocket by
cc3000.cpp@51:897cfc2c7e8c, 2015-04-06 (annotated)
- Committer:
- frankvnk
- Date:
- Mon Apr 06 18:23:37 2015 +0000
- Revision:
- 51:897cfc2c7e8c
- Parent:
- 48:192e2fde71e9
Added 2 optional parameters to the constructor : set TX and RX buffer size
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Kojto | 20:30b6ed7bf8fd | 1 | /***************************************************************************** |
| Kojto | 20:30b6ed7bf8fd | 2 | * |
| Kojto | 20:30b6ed7bf8fd | 3 | * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to |
| Kojto | 20:30b6ed7bf8fd | 4 | * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and |
| Kojto | 20:30b6ed7bf8fd | 5 | * provided help. |
| Kojto | 20:30b6ed7bf8fd | 6 | * |
| Kojto | 20:30b6ed7bf8fd | 7 | * This version of "host driver" uses CC3000 Host Driver Implementation. Thus |
| Kojto | 20:30b6ed7bf8fd | 8 | * read the following copyright: |
| Kojto | 20:30b6ed7bf8fd | 9 | * |
| Kojto | 20:30b6ed7bf8fd | 10 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
| Kojto | 20:30b6ed7bf8fd | 11 | * |
| Kojto | 20:30b6ed7bf8fd | 12 | * Redistribution and use in source and binary forms, with or without |
| Kojto | 20:30b6ed7bf8fd | 13 | * modification, are permitted provided that the following conditions |
| Kojto | 20:30b6ed7bf8fd | 14 | * are met: |
| Kojto | 20:30b6ed7bf8fd | 15 | * |
| Kojto | 20:30b6ed7bf8fd | 16 | * Redistributions of source code must retain the above copyright |
| Kojto | 20:30b6ed7bf8fd | 17 | * notice, this list of conditions and the following disclaimer. |
| Kojto | 20:30b6ed7bf8fd | 18 | * |
| Kojto | 20:30b6ed7bf8fd | 19 | * Redistributions in binary form must reproduce the above copyright |
| Kojto | 20:30b6ed7bf8fd | 20 | * notice, this list of conditions and the following disclaimer in the |
| Kojto | 20:30b6ed7bf8fd | 21 | * documentation and/or other materials provided with the |
| Kojto | 20:30b6ed7bf8fd | 22 | * distribution. |
| Kojto | 20:30b6ed7bf8fd | 23 | * |
| Kojto | 20:30b6ed7bf8fd | 24 | * Neither the name of Texas Instruments Incorporated nor the names of |
| Kojto | 20:30b6ed7bf8fd | 25 | * its contributors may be used to endorse or promote products derived |
| Kojto | 20:30b6ed7bf8fd | 26 | * from this software without specific prior written permission. |
| Kojto | 20:30b6ed7bf8fd | 27 | * |
| Kojto | 20:30b6ed7bf8fd | 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| Kojto | 20:30b6ed7bf8fd | 29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| Kojto | 20:30b6ed7bf8fd | 30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| Kojto | 20:30b6ed7bf8fd | 31 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| Kojto | 20:30b6ed7bf8fd | 32 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| Kojto | 20:30b6ed7bf8fd | 33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| Kojto | 20:30b6ed7bf8fd | 34 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| Kojto | 20:30b6ed7bf8fd | 35 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| Kojto | 20:30b6ed7bf8fd | 36 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| Kojto | 20:30b6ed7bf8fd | 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| Kojto | 20:30b6ed7bf8fd | 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Kojto | 20:30b6ed7bf8fd | 39 | * |
| Kojto | 20:30b6ed7bf8fd | 40 | *****************************************************************************/ |
| Kojto | 20:30b6ed7bf8fd | 41 | #include "cc3000.h" |
| Kojto | 20:30b6ed7bf8fd | 42 | #include "cc3000_event.h" |
| Kojto | 20:30b6ed7bf8fd | 43 | |
| Kojto | 20:30b6ed7bf8fd | 44 | namespace mbed_cc3000 { |
| Kojto | 20:30b6ed7bf8fd | 45 | |
| Kojto | 20:30b6ed7bf8fd | 46 | /* TODO this prefix remove? verify */ |
| Kojto | 20:30b6ed7bf8fd | 47 | static uint8_t cc3000_prefix[] = {'T', 'T', 'T'}; |
| Kojto | 20:30b6ed7bf8fd | 48 | cc3000 *cc3000::_inst; |
| Kojto | 20:30b6ed7bf8fd | 49 | |
| frankvnk | 51:897cfc2c7e8c | 50 | cc3000::cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, uint32_t max_tx_size, uint32_t max_rx_size) |
| Kojto | 45:50ab13d8f2dc | 51 | : _event(_simple_link, _hci, _spi, *this), _socket(_simple_link, _hci, _event), |
| frankvnk | 51:897cfc2c7e8c | 52 | _spi(cc3000_irq, cc3000_en, cc3000_cs, cc3000_spi, _event, _simple_link, max_tx_size, max_rx_size), _hci(_spi), |
| Kojto | 45:50ab13d8f2dc | 53 | _nvmem(_hci, _event, _simple_link), _netapp(_simple_link, _nvmem, _hci, _event), |
| Kojto | 45:50ab13d8f2dc | 54 | _wlan(_simple_link, _event, _spi, _hci) { |
| frankvnk | 51:897cfc2c7e8c | 55 | _simple_link.create_txrx_buffers(max_tx_size, max_rx_size); |
| Kojto | 20:30b6ed7bf8fd | 56 | _simple_link.set_tx_complete_signal(1); |
| Kojto | 45:50ab13d8f2dc | 57 | memset(&_status, 0, sizeof(_status)); |
| Kojto | 20:30b6ed7bf8fd | 58 | _inst = this; |
| Kojto | 20:30b6ed7bf8fd | 59 | } |
| Kojto | 20:30b6ed7bf8fd | 60 | |
| Kojto | 20:30b6ed7bf8fd | 61 | cc3000::~cc3000() { |
| Kojto | 20:30b6ed7bf8fd | 62 | } |
| Kojto | 20:30b6ed7bf8fd | 63 | |
| Kojto | 44:960b73df5981 | 64 | #if (CC3000_ETH_COMPAT == 1) |
| Kojto | 45:50ab13d8f2dc | 65 | cc3000::cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, const char *ssid, |
| frankvnk | 51:897cfc2c7e8c | 66 | const char *phrase, Security sec, bool smart_config, uint32_t max_tx_size, uint32_t max_rx_size) |
| Kojto | 45:50ab13d8f2dc | 67 | : _event(_simple_link, _hci, _spi, *this), _socket(_simple_link, _hci, _event), |
| frankvnk | 51:897cfc2c7e8c | 68 | _spi(cc3000_irq, cc3000_en, cc3000_cs, cc3000_spi, _event, _simple_link, max_tx_size, max_rx_size), _hci(_spi), |
| Kojto | 45:50ab13d8f2dc | 69 | _nvmem(_hci, _event, _simple_link), _netapp(_simple_link, _nvmem, _hci, _event), |
| Kojto | 45:50ab13d8f2dc | 70 | _wlan(_simple_link, _event, _spi, _hci), _sec(sec), _smart_config(smart_config) { |
| frankvnk | 51:897cfc2c7e8c | 71 | _simple_link.create_txrx_buffers(max_tx_size, max_rx_size); |
| Kojto | 45:50ab13d8f2dc | 72 | _simple_link.set_tx_complete_signal(1); |
| Kojto | 45:50ab13d8f2dc | 73 | memset(&_status, 0, sizeof(_status)); |
| Kojto | 45:50ab13d8f2dc | 74 | strcpy((char *)_ssid, ssid); |
| Kojto | 45:50ab13d8f2dc | 75 | strcpy((char *)_phrase, phrase); |
| Kojto | 45:50ab13d8f2dc | 76 | _inst = this; |
| Kojto | 45:50ab13d8f2dc | 77 | } |
| Kojto | 45:50ab13d8f2dc | 78 | |
| SolderSplashLabs | 39:03ac37ab34eb | 79 | // Ethernet library compatible, functions return strings |
| SolderSplashLabs | 39:03ac37ab34eb | 80 | // Caches the ipconfig from the usync callback |
| Kojto | 45:50ab13d8f2dc | 81 | static char mac_addr[19]= "\0"; |
| SolderSplashLabs | 39:03ac37ab34eb | 82 | static char ip_addr[17] = "\0"; |
| SolderSplashLabs | 39:03ac37ab34eb | 83 | static char gateway[17] = "\0"; |
| SolderSplashLabs | 39:03ac37ab34eb | 84 | static char networkmask[17] = "\0"; |
| SolderSplashLabs | 39:03ac37ab34eb | 85 | |
| Kojto | 45:50ab13d8f2dc | 86 | void cc3000::init() { |
| Kojto | 45:50ab13d8f2dc | 87 | _wlan.start(0); |
| Kojto | 45:50ab13d8f2dc | 88 | |
| Kojto | 45:50ab13d8f2dc | 89 | uint32_t subnet[4] = {0}; |
| Kojto | 45:50ab13d8f2dc | 90 | uint32_t ip[4] = {0}; |
| Kojto | 45:50ab13d8f2dc | 91 | uint32_t getway[4] = {0}; |
| Kojto | 45:50ab13d8f2dc | 92 | uint32_t dns[4] = {0}; |
| Kojto | 45:50ab13d8f2dc | 93 | |
| Kojto | 45:50ab13d8f2dc | 94 | _netapp.dhcp(ip, subnet, getway, dns); |
| Kojto | 45:50ab13d8f2dc | 95 | _wlan.stop(); |
| Kojto | 45:50ab13d8f2dc | 96 | wait(1); |
| Kojto | 45:50ab13d8f2dc | 97 | _wlan.start(0); |
| Kojto | 45:50ab13d8f2dc | 98 | |
| Kojto | 45:50ab13d8f2dc | 99 | _status.enabled = 1; |
| Kojto | 46:ca8c234997c0 | 100 | _wlan.set_event_mask(HCI_EVNT_WLAN_UNSOL_INIT | HCI_EVNT_WLAN_KEEPALIVE); |
| Kojto | 45:50ab13d8f2dc | 101 | } |
| Kojto | 45:50ab13d8f2dc | 102 | |
| Kojto | 45:50ab13d8f2dc | 103 | void cc3000::init(const char *ip, const char *mask, const char *gateway) { |
| frankvnk | 48:192e2fde71e9 | 104 | _wlan.start(0); |
| Kojto | 45:50ab13d8f2dc | 105 | _netapp.dhcp((uint32_t *)ip, (uint32_t *)mask, (uint32_t *)gateway, (uint32_t *)ip); //dns = ip |
| Kojto | 45:50ab13d8f2dc | 106 | _wlan.stop(); |
| Kojto | 45:50ab13d8f2dc | 107 | wait(1); |
| Kojto | 45:50ab13d8f2dc | 108 | _wlan.start(0); |
| Kojto | 45:50ab13d8f2dc | 109 | |
| Kojto | 45:50ab13d8f2dc | 110 | _status.enabled = 1; |
| Kojto | 46:ca8c234997c0 | 111 | _wlan.set_event_mask(HCI_EVNT_WLAN_UNSOL_INIT | HCI_EVNT_WLAN_KEEPALIVE); |
| Kojto | 45:50ab13d8f2dc | 112 | } |
| Kojto | 45:50ab13d8f2dc | 113 | |
| Kojto | 45:50ab13d8f2dc | 114 | int cc3000::connect(unsigned int timeout_ms) { |
| Kojto | 45:50ab13d8f2dc | 115 | Timer t; |
| Kojto | 45:50ab13d8f2dc | 116 | int ret = 0; |
| Kojto | 45:50ab13d8f2dc | 117 | |
| Kojto | 45:50ab13d8f2dc | 118 | if (_smart_config == false) { |
| Kojto | 45:50ab13d8f2dc | 119 | _wlan.ioctl_set_connection_policy(0, 0, 0); |
| Kojto | 45:50ab13d8f2dc | 120 | } else { |
| Kojto | 45:50ab13d8f2dc | 121 | tUserFS user_info; |
| Kojto | 45:50ab13d8f2dc | 122 | get_user_file_info((uint8_t *)&user_info, sizeof(user_info)); |
| Kojto | 45:50ab13d8f2dc | 123 | if (user_info.FTC == 1) { |
| Kojto | 45:50ab13d8f2dc | 124 | _wlan.ioctl_set_connection_policy(0, 1, 1); |
| Kojto | 45:50ab13d8f2dc | 125 | } else { |
| Kojto | 45:50ab13d8f2dc | 126 | DBG_CC("Smart config is not set. Please run the first time configuration."); |
| Kojto | 45:50ab13d8f2dc | 127 | return -1; |
| Kojto | 45:50ab13d8f2dc | 128 | } |
| Kojto | 45:50ab13d8f2dc | 129 | } |
| Kojto | 45:50ab13d8f2dc | 130 | |
| Kojto | 45:50ab13d8f2dc | 131 | t.start(); |
| Kojto | 45:50ab13d8f2dc | 132 | while (is_connected() == false) { |
| Kojto | 45:50ab13d8f2dc | 133 | if (strlen((const char *)_phrase) < 8) { |
| Kojto | 45:50ab13d8f2dc | 134 | if (connect_open(_ssid)) { |
| Kojto | 45:50ab13d8f2dc | 135 | break; |
| Kojto | 45:50ab13d8f2dc | 136 | } |
| Kojto | 45:50ab13d8f2dc | 137 | } else { |
| Kojto | 45:50ab13d8f2dc | 138 | #ifndef CC3000_TINY_DRIVER |
| Kojto | 45:50ab13d8f2dc | 139 | if (connect_secure(_ssid,_phrase, _sec)) { |
| Kojto | 45:50ab13d8f2dc | 140 | break; |
| Kojto | 45:50ab13d8f2dc | 141 | } |
| Kojto | 45:50ab13d8f2dc | 142 | #else |
| Kojto | 45:50ab13d8f2dc | 143 | return -1; /* secure connection not supported with TINY_DRIVER */ |
| Kojto | 45:50ab13d8f2dc | 144 | #endif |
| Kojto | 45:50ab13d8f2dc | 145 | } |
| Kojto | 45:50ab13d8f2dc | 146 | |
| Kojto | 45:50ab13d8f2dc | 147 | if (t.read_ms() > timeout_ms) { |
| Kojto | 45:50ab13d8f2dc | 148 | ret = -1; |
| Kojto | 45:50ab13d8f2dc | 149 | DBG_CC("Connection to AP failed"); |
| Kojto | 45:50ab13d8f2dc | 150 | break; |
| Kojto | 45:50ab13d8f2dc | 151 | } |
| Kojto | 45:50ab13d8f2dc | 152 | } |
| Kojto | 45:50ab13d8f2dc | 153 | |
| Kojto | 45:50ab13d8f2dc | 154 | while (is_dhcp_configured() == false) |
| Kojto | 45:50ab13d8f2dc | 155 | { |
| Kojto | 45:50ab13d8f2dc | 156 | if (t.read_ms() > timeout_ms) { |
| Kojto | 45:50ab13d8f2dc | 157 | ret = -1; |
| Kojto | 45:50ab13d8f2dc | 158 | DBG_CC("Connection to AP failed"); |
| Kojto | 45:50ab13d8f2dc | 159 | break; |
| Kojto | 45:50ab13d8f2dc | 160 | } |
| Kojto | 45:50ab13d8f2dc | 161 | } |
| Kojto | 45:50ab13d8f2dc | 162 | |
| Kojto | 45:50ab13d8f2dc | 163 | return ret; |
| Kojto | 45:50ab13d8f2dc | 164 | } |
| Kojto | 45:50ab13d8f2dc | 165 | |
| SolderSplashLabs | 39:03ac37ab34eb | 166 | char* cc3000::getMACAddress() { |
| SolderSplashLabs | 39:03ac37ab34eb | 167 | return mac_addr; |
| SolderSplashLabs | 39:03ac37ab34eb | 168 | } |
| SolderSplashLabs | 39:03ac37ab34eb | 169 | |
| SolderSplashLabs | 39:03ac37ab34eb | 170 | char* cc3000::getIPAddress() { |
| SolderSplashLabs | 39:03ac37ab34eb | 171 | return ip_addr; |
| SolderSplashLabs | 39:03ac37ab34eb | 172 | } |
| SolderSplashLabs | 39:03ac37ab34eb | 173 | |
| SolderSplashLabs | 39:03ac37ab34eb | 174 | char* cc3000::getGateway() { |
| SolderSplashLabs | 39:03ac37ab34eb | 175 | return gateway; |
| SolderSplashLabs | 39:03ac37ab34eb | 176 | } |
| SolderSplashLabs | 39:03ac37ab34eb | 177 | |
| SolderSplashLabs | 39:03ac37ab34eb | 178 | char* cc3000::getNetworkMask() { |
| SolderSplashLabs | 39:03ac37ab34eb | 179 | return networkmask; |
| SolderSplashLabs | 39:03ac37ab34eb | 180 | } |
| Kojto | 45:50ab13d8f2dc | 181 | |
| Kojto | 45:50ab13d8f2dc | 182 | int cc3000::disconnect(void){ |
| Kojto | 45:50ab13d8f2dc | 183 | if (_wlan.disconnect()) { |
| Kojto | 45:50ab13d8f2dc | 184 | return -1; |
| Kojto | 45:50ab13d8f2dc | 185 | } else { |
| Kojto | 45:50ab13d8f2dc | 186 | return 0; |
| Kojto | 45:50ab13d8f2dc | 187 | } |
| Kojto | 45:50ab13d8f2dc | 188 | } |
| Kojto | 45:50ab13d8f2dc | 189 | |
| SolderSplashLabs | 39:03ac37ab34eb | 190 | #endif |
| SolderSplashLabs | 39:03ac37ab34eb | 191 | |
| Kojto | 44:960b73df5981 | 192 | void cc3000::usync_callback(int32_t event_type, uint8_t *data, uint8_t length) { |
| Kojto | 45:50ab13d8f2dc | 193 | if (event_type == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE) { |
| SolderSplashLabs | 41:eb1999bd50fb | 194 | DBG_CC("Callback : HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE"); |
| Kojto | 20:30b6ed7bf8fd | 195 | _status.smart_config_complete = 1; |
| Kojto | 20:30b6ed7bf8fd | 196 | _status.stop_smart_config = 1; |
| Kojto | 20:30b6ed7bf8fd | 197 | } |
| Kojto | 20:30b6ed7bf8fd | 198 | |
| Kojto | 45:50ab13d8f2dc | 199 | if (event_type == HCI_EVNT_WLAN_UNSOL_CONNECT) { |
| SolderSplashLabs | 41:eb1999bd50fb | 200 | DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_CONNECT"); |
| Kojto | 20:30b6ed7bf8fd | 201 | _status.connected = 1; |
| SolderSplashLabs | 39:03ac37ab34eb | 202 | // Connect message is always followed by a DHCP message, connection is not useable until then |
| SolderSplashLabs | 39:03ac37ab34eb | 203 | _status.dhcp = 0; |
| Kojto | 20:30b6ed7bf8fd | 204 | } |
| Kojto | 20:30b6ed7bf8fd | 205 | |
| Kojto | 45:50ab13d8f2dc | 206 | if (event_type == HCI_EVNT_WLAN_UNSOL_DISCONNECT) { |
| SolderSplashLabs | 41:eb1999bd50fb | 207 | DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DISCONNECT"); |
| Kojto | 20:30b6ed7bf8fd | 208 | _status.connected = 0; |
| Kojto | 20:30b6ed7bf8fd | 209 | _status.dhcp = 0; |
| Kojto | 20:30b6ed7bf8fd | 210 | _status.dhcp_configured = 0; |
| Kojto | 20:30b6ed7bf8fd | 211 | } |
| Kojto | 20:30b6ed7bf8fd | 212 | |
| Kojto | 45:50ab13d8f2dc | 213 | if (event_type == HCI_EVNT_WLAN_UNSOL_DHCP) { |
| Kojto | 44:960b73df5981 | 214 | #if (CC3000_ETH_COMPAT == 1) |
| SolderSplashLabs | 42:bd2c631a031a | 215 | _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_IP_OFFSET]))), ip_addr, 17); |
| SolderSplashLabs | 42:bd2c631a031a | 216 | _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_GW_OFFSET]))), gateway, 17); |
| SolderSplashLabs | 42:bd2c631a031a | 217 | _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_SUBNET_OFFSET]))), networkmask, 17); |
| SolderSplashLabs | 42:bd2c631a031a | 218 | _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_MAC_OFFSET]))), mac_addr, 19); |
| Kojto | 44:960b73df5981 | 219 | #endif |
| Kojto | 44:960b73df5981 | 220 | if (*(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0) { |
| SolderSplashLabs | 41:eb1999bd50fb | 221 | _status.dhcp = 1; |
| SolderSplashLabs | 41:eb1999bd50fb | 222 | DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP %i.%i.%i.%i", data[3], data[2], data[1], data[0]); |
| SolderSplashLabs | 41:eb1999bd50fb | 223 | } else { |
| SolderSplashLabs | 42:bd2c631a031a | 224 | DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP - Disconnecting"); |
| SolderSplashLabs | 41:eb1999bd50fb | 225 | _status.dhcp = 0; |
| SolderSplashLabs | 41:eb1999bd50fb | 226 | } |
| Kojto | 20:30b6ed7bf8fd | 227 | } |
| Kojto | 20:30b6ed7bf8fd | 228 | |
| Kojto | 45:50ab13d8f2dc | 229 | if (event_type == HCI_EVENT_CC3000_CAN_SHUT_DOWN) { |
| Kojto | 44:960b73df5981 | 230 | // Note this means the modules is idle, so it could be shutdown.. |
| SolderSplashLabs | 41:eb1999bd50fb | 231 | //DBG_CC("Callback : HCI_EVENT_CC3000_CAN_SHUT_DOWN"); |
| Kojto | 20:30b6ed7bf8fd | 232 | _status.ok_to_shut_down = 1; |
| Kojto | 20:30b6ed7bf8fd | 233 | } |
| Kojto | 20:30b6ed7bf8fd | 234 | |
| Kojto | 45:50ab13d8f2dc | 235 | if (event_type == HCI_EVNT_WLAN_ASYNC_PING_REPORT) { |
| SolderSplashLabs | 41:eb1999bd50fb | 236 | DBG_CC("Callback : HCI_EVNT_WLAN_ASYNC_PING_REPORT"); |
| Kojto | 20:30b6ed7bf8fd | 237 | memcpy(&_ping_report, data, length); |
| Kojto | 20:30b6ed7bf8fd | 238 | } |
| Kojto | 20:30b6ed7bf8fd | 239 | |
| Kojto | 20:30b6ed7bf8fd | 240 | if (event_type == HCI_EVNT_BSD_TCP_CLOSE_WAIT) { |
| Kojto | 45:50ab13d8f2dc | 241 | uint8_t socketnum = data[0]; |
| SolderSplashLabs | 41:eb1999bd50fb | 242 | DBG_CC("Callback : HCI_EVNT_BSD_TCP_CLOSE_WAIT - Socket : %d", socketnum); |
| Kojto | 20:30b6ed7bf8fd | 243 | if (socketnum < MAX_SOCKETS) { |
| Kojto | 20:30b6ed7bf8fd | 244 | _closed_sockets[socketnum] = true; /* clients socket is closed */ |
| Kojto | 20:30b6ed7bf8fd | 245 | } |
| Kojto | 20:30b6ed7bf8fd | 246 | } |
| Kojto | 20:30b6ed7bf8fd | 247 | } |
| Kojto | 20:30b6ed7bf8fd | 248 | |
| Kojto | 20:30b6ed7bf8fd | 249 | void cc3000::start_smart_config(const uint8_t *smart_config_key) { |
| SolderSplashLabs | 39:03ac37ab34eb | 250 | _status.smart_config_complete = 0; |
| Kojto | 20:30b6ed7bf8fd | 251 | _wlan.ioctl_set_connection_policy(0, 0, 0); |
| Kojto | 44:960b73df5981 | 252 | |
| Kojto | 45:50ab13d8f2dc | 253 | if (_status.connected == 1) { |
| SolderSplashLabs | 42:bd2c631a031a | 254 | disconnect(); |
| SolderSplashLabs | 42:bd2c631a031a | 255 | } |
| Kojto | 20:30b6ed7bf8fd | 256 | |
| Kojto | 20:30b6ed7bf8fd | 257 | //Wait until CC3000 is disconected |
| Kojto | 45:50ab13d8f2dc | 258 | while (_status.connected == 1) { |
| Kojto | 20:30b6ed7bf8fd | 259 | wait_us(5); |
| Kojto | 20:30b6ed7bf8fd | 260 | _event.hci_unsolicited_event_handler(); |
| Kojto | 20:30b6ed7bf8fd | 261 | } |
| Kojto | 20:30b6ed7bf8fd | 262 | |
| Kojto | 20:30b6ed7bf8fd | 263 | // Trigger the Smart Config process |
| Kojto | 20:30b6ed7bf8fd | 264 | _wlan.smart_config_set_prefix(cc3000_prefix); |
| Kojto | 20:30b6ed7bf8fd | 265 | // Start the Smart Config process with AES disabled |
| Kojto | 20:30b6ed7bf8fd | 266 | _wlan.smart_config_start(0); |
| Kojto | 20:30b6ed7bf8fd | 267 | |
| Kojto | 20:30b6ed7bf8fd | 268 | DBG_CC("Waiting for smartconfig to be completed"); |
| Kojto | 20:30b6ed7bf8fd | 269 | |
| Kojto | 20:30b6ed7bf8fd | 270 | // Wait for Smart config finished |
| Kojto | 45:50ab13d8f2dc | 271 | while (_status.smart_config_complete == 0) { |
| Kojto | 20:30b6ed7bf8fd | 272 | wait_ms(100); |
| Kojto | 20:30b6ed7bf8fd | 273 | } |
| Kojto | 20:30b6ed7bf8fd | 274 | |
| Kojto | 20:30b6ed7bf8fd | 275 | DBG_CC("Smartconfig finished"); |
| Kojto | 20:30b6ed7bf8fd | 276 | |
| Kojto | 20:30b6ed7bf8fd | 277 | #ifndef CC3000_UNENCRYPTED_SMART_CONFIG |
| Kojto | 20:30b6ed7bf8fd | 278 | // create new entry for AES encryption key |
| Kojto | 20:30b6ed7bf8fd | 279 | _nvmem.create_entry(NVMEM_AES128_KEY_FILEID, 16); |
| Kojto | 20:30b6ed7bf8fd | 280 | // write AES key to NVMEM |
| Kojto | 20:30b6ed7bf8fd | 281 | _security.aes_write_key((uint8_t *)(&smart_config_key[0])); |
| Kojto | 20:30b6ed7bf8fd | 282 | // Decrypt configuration information and add profile |
| Kojto | 20:30b6ed7bf8fd | 283 | _wlan.smart_config_process(); |
| Kojto | 20:30b6ed7bf8fd | 284 | #endif |
| Kojto | 20:30b6ed7bf8fd | 285 | |
| Kojto | 20:30b6ed7bf8fd | 286 | // Configure to connect automatically to the AP retrieved in the |
| Kojto | 20:30b6ed7bf8fd | 287 | // Smart config process |
| SolderSplashLabs | 39:03ac37ab34eb | 288 | _wlan.ioctl_set_connection_policy(0, 0, 1); |
| Kojto | 20:30b6ed7bf8fd | 289 | |
| Kojto | 20:30b6ed7bf8fd | 290 | // reset the CC3000 |
| Kojto | 20:30b6ed7bf8fd | 291 | _wlan.stop(); |
| SolderSplashLabs | 39:03ac37ab34eb | 292 | _status.enabled = 0; |
| SolderSplashLabs | 39:03ac37ab34eb | 293 | wait(5); |
| Kojto | 20:30b6ed7bf8fd | 294 | _wlan.start(0); |
| SolderSplashLabs | 39:03ac37ab34eb | 295 | _status.enabled = 1; |
| Kojto | 20:30b6ed7bf8fd | 296 | |
| Kojto | 20:30b6ed7bf8fd | 297 | // Mask out all non-required events |
| Kojto | 46:ca8c234997c0 | 298 | _wlan.set_event_mask(HCI_EVNT_WLAN_KEEPALIVE | HCI_EVNT_WLAN_UNSOL_INIT); |
| Kojto | 20:30b6ed7bf8fd | 299 | } |
| Kojto | 20:30b6ed7bf8fd | 300 | |
| Kojto | 20:30b6ed7bf8fd | 301 | bool cc3000::connect_secure(const uint8_t *ssid, const uint8_t *key, int32_t security_mode) { |
| Kojto | 45:50ab13d8f2dc | 302 | #ifdef CC3000_TINY_DRIVER |
| Kojto | 45:50ab13d8f2dc | 303 | return false; /* not supported*/ |
| Kojto | 45:50ab13d8f2dc | 304 | #else |
| Kojto | 20:30b6ed7bf8fd | 305 | uint32_t ret; |
| Kojto | 20:30b6ed7bf8fd | 306 | |
| SolderSplashLabs | 42:bd2c631a031a | 307 | //_wlan.disconnect(); |
| Kojto | 20:30b6ed7bf8fd | 308 | wait_ms(3); |
| Kojto | 20:30b6ed7bf8fd | 309 | ret = _wlan.connect(security_mode, ssid, strlen((const char *)ssid), 0, (uint8_t *)key, strlen((const char *)key)); |
| Kojto | 20:30b6ed7bf8fd | 310 | if (ret == 0) { /* TODO static internal cc3000 state 0 to TRUE */ |
| Kojto | 20:30b6ed7bf8fd | 311 | ret = true; |
| Kojto | 20:30b6ed7bf8fd | 312 | } else { |
| Kojto | 20:30b6ed7bf8fd | 313 | ret = false; |
| Kojto | 20:30b6ed7bf8fd | 314 | } |
| Kojto | 20:30b6ed7bf8fd | 315 | return ret; |
| Kojto | 45:50ab13d8f2dc | 316 | #endif |
| Kojto | 20:30b6ed7bf8fd | 317 | } |
| Kojto | 20:30b6ed7bf8fd | 318 | |
| Kojto | 44:960b73df5981 | 319 | bool cc3000::connect_non_blocking(const uint8_t *ssid, const uint8_t *key, int32_t security_mode) |
| SolderSplashLabs | 39:03ac37ab34eb | 320 | { |
| Kojto | 45:50ab13d8f2dc | 321 | bool ret = false; |
| SolderSplashLabs | 39:03ac37ab34eb | 322 | |
| Kojto | 45:50ab13d8f2dc | 323 | if (key == 0) { |
| Kojto | 45:50ab13d8f2dc | 324 | if (connect_open(ssid)) { |
| SolderSplashLabs | 39:03ac37ab34eb | 325 | ret = true; |
| SolderSplashLabs | 39:03ac37ab34eb | 326 | } |
| Kojto | 45:50ab13d8f2dc | 327 | } else { |
| SolderSplashLabs | 39:03ac37ab34eb | 328 | #ifndef CC3000_TINY_DRIVER |
| Kojto | 45:50ab13d8f2dc | 329 | if (connect_secure(ssid,key,security_mode)) { |
| SolderSplashLabs | 39:03ac37ab34eb | 330 | ret = true; |
| SolderSplashLabs | 39:03ac37ab34eb | 331 | } |
| SolderSplashLabs | 39:03ac37ab34eb | 332 | #else |
| SolderSplashLabs | 39:03ac37ab34eb | 333 | /* secure connection not supported with TINY_DRIVER */ |
| SolderSplashLabs | 39:03ac37ab34eb | 334 | #endif |
| SolderSplashLabs | 39:03ac37ab34eb | 335 | } |
| Kojto | 44:960b73df5981 | 336 | |
| SolderSplashLabs | 39:03ac37ab34eb | 337 | return ret; |
| SolderSplashLabs | 39:03ac37ab34eb | 338 | } |
| SolderSplashLabs | 39:03ac37ab34eb | 339 | |
| Kojto | 20:30b6ed7bf8fd | 340 | bool cc3000::connect_to_AP(const uint8_t *ssid, const uint8_t *key, int32_t security_mode) { |
| Kojto | 45:50ab13d8f2dc | 341 | Timer t; |
| Kojto | 20:30b6ed7bf8fd | 342 | bool ret = true; |
| Kojto | 20:30b6ed7bf8fd | 343 | |
| Kojto | 20:30b6ed7bf8fd | 344 | t.start(); |
| Kojto | 20:30b6ed7bf8fd | 345 | while (is_connected() == false) { |
| Kojto | 20:30b6ed7bf8fd | 346 | if (key == 0) { |
| Kojto | 20:30b6ed7bf8fd | 347 | if (connect_open(ssid)) { |
| Kojto | 20:30b6ed7bf8fd | 348 | break; |
| Kojto | 20:30b6ed7bf8fd | 349 | } |
| Kojto | 20:30b6ed7bf8fd | 350 | } else { |
| Kojto | 20:30b6ed7bf8fd | 351 | #ifndef CC3000_TINY_DRIVER |
| Kojto | 20:30b6ed7bf8fd | 352 | if (connect_secure(ssid,key,security_mode)) { |
| Kojto | 20:30b6ed7bf8fd | 353 | break; |
| Kojto | 20:30b6ed7bf8fd | 354 | } |
| Kojto | 20:30b6ed7bf8fd | 355 | #else |
| Kojto | 20:30b6ed7bf8fd | 356 | return false; /* secure connection not supported with TINY_DRIVER */ |
| Kojto | 20:30b6ed7bf8fd | 357 | #endif |
| Kojto | 20:30b6ed7bf8fd | 358 | } |
| Kojto | 20:30b6ed7bf8fd | 359 | |
| Kojto | 20:30b6ed7bf8fd | 360 | /* timeout 10 seconds */ |
| Kojto | 45:50ab13d8f2dc | 361 | if (t.read_ms() > 10000) { |
| Kojto | 20:30b6ed7bf8fd | 362 | ret = false; |
| Kojto | 20:30b6ed7bf8fd | 363 | DBG_CC("Connection to AP failed"); |
| Kojto | 20:30b6ed7bf8fd | 364 | break; |
| Kojto | 20:30b6ed7bf8fd | 365 | } |
| Kojto | 20:30b6ed7bf8fd | 366 | } |
| Kojto | 20:30b6ed7bf8fd | 367 | |
| Kojto | 20:30b6ed7bf8fd | 368 | return ret; |
| Kojto | 20:30b6ed7bf8fd | 369 | } |
| Kojto | 20:30b6ed7bf8fd | 370 | |
| Kojto | 20:30b6ed7bf8fd | 371 | void cc3000::start(uint8_t patch) { |
| Kojto | 20:30b6ed7bf8fd | 372 | _wlan.start(patch); |
| SolderSplashLabs | 39:03ac37ab34eb | 373 | _status.enabled = 1; |
| Kojto | 46:ca8c234997c0 | 374 | _wlan.set_event_mask(HCI_EVNT_WLAN_UNSOL_INIT | HCI_EVNT_WLAN_KEEPALIVE); |
| Kojto | 20:30b6ed7bf8fd | 375 | } |
| Kojto | 20:30b6ed7bf8fd | 376 | |
| Kojto | 20:30b6ed7bf8fd | 377 | void cc3000::stop(void) { |
| Kojto | 20:30b6ed7bf8fd | 378 | _wlan.stop(); |
| SolderSplashLabs | 39:03ac37ab34eb | 379 | _status.enabled = 0; |
| Kojto | 20:30b6ed7bf8fd | 380 | } |
| Kojto | 20:30b6ed7bf8fd | 381 | |
| Kojto | 20:30b6ed7bf8fd | 382 | void cc3000::restart(uint8_t patch) { |
| Kojto | 20:30b6ed7bf8fd | 383 | _wlan.stop(); |
| SolderSplashLabs | 39:03ac37ab34eb | 384 | _status.enabled = 0; |
| Kojto | 20:30b6ed7bf8fd | 385 | wait_ms(500); |
| Kojto | 20:30b6ed7bf8fd | 386 | _wlan.start(patch); |
| SolderSplashLabs | 39:03ac37ab34eb | 387 | _status.enabled = 1; |
| Kojto | 20:30b6ed7bf8fd | 388 | } |
| Kojto | 20:30b6ed7bf8fd | 389 | |
| Kojto | 20:30b6ed7bf8fd | 390 | bool cc3000::connect_open(const uint8_t *ssid) { |
| Kojto | 20:30b6ed7bf8fd | 391 | _wlan.disconnect(); |
| Kojto | 20:30b6ed7bf8fd | 392 | wait_ms(3); |
| Kojto | 45:50ab13d8f2dc | 393 | uint32_t ret; |
| Kojto | 20:30b6ed7bf8fd | 394 | #ifndef CC3000_TINY_DRIVER |
| Kojto | 20:30b6ed7bf8fd | 395 | ret = _wlan.connect(0,ssid, strlen((const char *)ssid), 0, 0, 0); |
| Kojto | 20:30b6ed7bf8fd | 396 | #else |
| Kojto | 20:30b6ed7bf8fd | 397 | ret = _wlan.connect(ssid, strlen((const char *)ssid)); |
| Kojto | 20:30b6ed7bf8fd | 398 | #endif |
| Kojto | 20:30b6ed7bf8fd | 399 | if (ret == 0) { |
| Kojto | 20:30b6ed7bf8fd | 400 | ret = true; |
| Kojto | 20:30b6ed7bf8fd | 401 | } else { |
| Kojto | 20:30b6ed7bf8fd | 402 | ret = false; |
| Kojto | 20:30b6ed7bf8fd | 403 | } |
| Kojto | 20:30b6ed7bf8fd | 404 | return ret; |
| Kojto | 20:30b6ed7bf8fd | 405 | } |
| Kojto | 20:30b6ed7bf8fd | 406 | |
| SolderSplashLabs | 39:03ac37ab34eb | 407 | bool cc3000::is_enabled() |
| SolderSplashLabs | 39:03ac37ab34eb | 408 | { |
| SolderSplashLabs | 39:03ac37ab34eb | 409 | return _status.enabled; |
| SolderSplashLabs | 39:03ac37ab34eb | 410 | } |
| SolderSplashLabs | 39:03ac37ab34eb | 411 | |
| Kojto | 20:30b6ed7bf8fd | 412 | bool cc3000::is_connected() { |
| Kojto | 45:50ab13d8f2dc | 413 | if (( _status.connected ) && ( _status.dhcp )) { |
| Kojto | 45:50ab13d8f2dc | 414 | return 1; |
| Kojto | 45:50ab13d8f2dc | 415 | } else { |
| Kojto | 45:50ab13d8f2dc | 416 | return 0; |
| SolderSplashLabs | 42:bd2c631a031a | 417 | } |
| Kojto | 20:30b6ed7bf8fd | 418 | } |
| Kojto | 20:30b6ed7bf8fd | 419 | |
| Kojto | 20:30b6ed7bf8fd | 420 | bool cc3000::is_dhcp_configured() { |
| Kojto | 20:30b6ed7bf8fd | 421 | return _status.dhcp; |
| Kojto | 20:30b6ed7bf8fd | 422 | } |
| Kojto | 20:30b6ed7bf8fd | 423 | |
| Kojto | 20:30b6ed7bf8fd | 424 | bool cc3000::is_smart_confing_completed() { |
| Kojto | 20:30b6ed7bf8fd | 425 | return _status.smart_config_complete; |
| Kojto | 20:30b6ed7bf8fd | 426 | } |
| Kojto | 20:30b6ed7bf8fd | 427 | |
| Kojto | 20:30b6ed7bf8fd | 428 | uint8_t cc3000::get_mac_address(uint8_t address[6]) { |
| Kojto | 20:30b6ed7bf8fd | 429 | return _nvmem.get_mac_address(address); |
| Kojto | 20:30b6ed7bf8fd | 430 | } |
| Kojto | 20:30b6ed7bf8fd | 431 | |
| Kojto | 20:30b6ed7bf8fd | 432 | uint8_t cc3000::set_mac_address(uint8_t address[6]) { |
| Kojto | 20:30b6ed7bf8fd | 433 | return _nvmem.set_mac_address(address); |
| Kojto | 20:30b6ed7bf8fd | 434 | } |
| Kojto | 20:30b6ed7bf8fd | 435 | |
| Kojto | 20:30b6ed7bf8fd | 436 | void cc3000::get_user_file_info(uint8_t *info_file, size_t size) { |
| Kojto | 20:30b6ed7bf8fd | 437 | _nvmem.read( NVMEM_USER_FILE_1_FILEID, size, 0, info_file); |
| Kojto | 20:30b6ed7bf8fd | 438 | } |
| Kojto | 20:30b6ed7bf8fd | 439 | |
| dreschpe | 47:a63fe1a4f568 | 440 | uint8_t cc3000::read_sp_version(uint8_t firmware[2]){ |
| dreschpe | 47:a63fe1a4f568 | 441 | return _nvmem.read_sp_version(firmware); |
| dreschpe | 47:a63fe1a4f568 | 442 | } |
| dreschpe | 47:a63fe1a4f568 | 443 | |
| dreschpe | 47:a63fe1a4f568 | 444 | uint8_t cc3000::write_patch(uint32_t file_id, uint32_t length, const uint8_t *data){ |
| dreschpe | 47:a63fe1a4f568 | 445 | if(file_id == NVMEM_WLAN_DRIVER_SP_FILEID || file_id == NVMEM_WLAN_FW_SP_FILEID){ |
| dreschpe | 47:a63fe1a4f568 | 446 | return _nvmem.write_patch(file_id, length, data); |
| dreschpe | 47:a63fe1a4f568 | 447 | } |
| dreschpe | 47:a63fe1a4f568 | 448 | else return (1); // error |
| dreschpe | 47:a63fe1a4f568 | 449 | } |
| dreschpe | 47:a63fe1a4f568 | 450 | |
| Kojto | 20:30b6ed7bf8fd | 451 | #ifndef CC3000_TINY_DRIVER |
| Kojto | 20:30b6ed7bf8fd | 452 | bool cc3000::get_ip_config(tNetappIpconfigRetArgs *ip_config) { |
| Kojto | 20:30b6ed7bf8fd | 453 | if ((_status.dhcp == false) || (_status.connected == false)) { |
| Kojto | 20:30b6ed7bf8fd | 454 | return false; |
| Kojto | 20:30b6ed7bf8fd | 455 | } |
| Kojto | 20:30b6ed7bf8fd | 456 | |
| Kojto | 20:30b6ed7bf8fd | 457 | _netapp.ipconfig(ip_config); |
| Kojto | 20:30b6ed7bf8fd | 458 | return true; |
| Kojto | 20:30b6ed7bf8fd | 459 | } |
| Kojto | 20:30b6ed7bf8fd | 460 | #endif |
| Kojto | 20:30b6ed7bf8fd | 461 | |
| Kojto | 20:30b6ed7bf8fd | 462 | void cc3000::delete_profiles(void) { |
| Kojto | 20:30b6ed7bf8fd | 463 | _wlan.ioctl_set_connection_policy(0, 0, 0); |
| Kojto | 20:30b6ed7bf8fd | 464 | _wlan.ioctl_del_profile(255); |
| Kojto | 20:30b6ed7bf8fd | 465 | |
| Kojto | 45:50ab13d8f2dc | 466 | tUserFS user_info; |
| Kojto | 20:30b6ed7bf8fd | 467 | get_user_file_info((uint8_t *)&user_info, sizeof(user_info)); |
| Kojto | 20:30b6ed7bf8fd | 468 | user_info.FTC = 0; |
| Kojto | 20:30b6ed7bf8fd | 469 | set_user_file_info((uint8_t *)&user_info, sizeof(user_info)); |
| Kojto | 20:30b6ed7bf8fd | 470 | } |
| Kojto | 20:30b6ed7bf8fd | 471 | |
| Kojto | 20:30b6ed7bf8fd | 472 | void cc3000::set_user_file_info(uint8_t *info_file, size_t size) { |
| Kojto | 20:30b6ed7bf8fd | 473 | _nvmem.write( NVMEM_USER_FILE_1_FILEID, size, 0, info_file); |
| Kojto | 20:30b6ed7bf8fd | 474 | } |
| Kojto | 20:30b6ed7bf8fd | 475 | |
| Kojto | 20:30b6ed7bf8fd | 476 | uint32_t cc3000::ping(uint32_t ip, uint8_t attempts, uint16_t timeout, uint8_t size) { |
| Kojto | 45:50ab13d8f2dc | 477 | #ifndef CC3000_TINY_DRIVER |
| Kojto | 37:3332f57b7f1e | 478 | uint32_t reversed_ip = (ip >> 24) | ((ip >> 8) & 0xFF00) | ((ip << 8) & 0xFF0000) | (ip << 24); |
| Kojto | 20:30b6ed7bf8fd | 479 | |
| Kojto | 20:30b6ed7bf8fd | 480 | _ping_report.packets_received = 0; |
| Kojto | 20:30b6ed7bf8fd | 481 | if (_netapp.ping_send(&reversed_ip, attempts, size, timeout) == -1) { |
| Kojto | 20:30b6ed7bf8fd | 482 | DBG_CC("Failed to send ping"); |
| Kojto | 20:30b6ed7bf8fd | 483 | return 0; |
| Kojto | 20:30b6ed7bf8fd | 484 | } |
| Kojto | 20:30b6ed7bf8fd | 485 | wait_ms(timeout*attempts*2); |
| Kojto | 20:30b6ed7bf8fd | 486 | |
| Kojto | 20:30b6ed7bf8fd | 487 | /* known issue of cc3000 - sent number is send + received */ |
| Kojto | 20:30b6ed7bf8fd | 488 | // TODO : Remove the Sent/recv'd counts until ti fix the firmware issue? |
| Kojto | 20:30b6ed7bf8fd | 489 | DBG_CC("Sent: %d",_ping_report.packets_sent); |
| Kojto | 20:30b6ed7bf8fd | 490 | DBG_CC("Received: %d",_ping_report.packets_received); |
| Kojto | 20:30b6ed7bf8fd | 491 | DBG_CC("Min time: %d",_ping_report.min_round_time); |
| Kojto | 20:30b6ed7bf8fd | 492 | DBG_CC("Max time: %d",_ping_report.max_round_time); |
| Kojto | 20:30b6ed7bf8fd | 493 | DBG_CC("Avg time: %d",_ping_report.avg_round_time); |
| Kojto | 20:30b6ed7bf8fd | 494 | |
| Kojto | 20:30b6ed7bf8fd | 495 | return _ping_report.packets_received; |
| Kojto | 45:50ab13d8f2dc | 496 | #else |
| Kojto | 45:50ab13d8f2dc | 497 | return 0; |
| Kojto | 45:50ab13d8f2dc | 498 | #endif |
| Kojto | 20:30b6ed7bf8fd | 499 | } |
| Kojto | 20:30b6ed7bf8fd | 500 | |
| Kojto | 20:30b6ed7bf8fd | 501 | /* Conversion between uint types and C strings */ |
| Kojto | 20:30b6ed7bf8fd | 502 | uint8_t* UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32) |
| Kojto | 20:30b6ed7bf8fd | 503 | { |
| Kojto | 20:30b6ed7bf8fd | 504 | *(p)++ = (uint8_t)(u32); |
| Kojto | 20:30b6ed7bf8fd | 505 | *(p)++ = (uint8_t)((u32) >> 8); |
| Kojto | 20:30b6ed7bf8fd | 506 | *(p)++ = (uint8_t)((u32) >> 16); |
| Kojto | 20:30b6ed7bf8fd | 507 | *(p)++ = (uint8_t)((u32) >> 24); |
| Kojto | 20:30b6ed7bf8fd | 508 | return p; |
| Kojto | 20:30b6ed7bf8fd | 509 | } |
| Kojto | 20:30b6ed7bf8fd | 510 | |
| Kojto | 20:30b6ed7bf8fd | 511 | |
| Kojto | 20:30b6ed7bf8fd | 512 | uint8_t* UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16) |
| Kojto | 20:30b6ed7bf8fd | 513 | { |
| Kojto | 20:30b6ed7bf8fd | 514 | *(p)++ = (uint8_t)(u16); |
| Kojto | 20:30b6ed7bf8fd | 515 | *(p)++ = (uint8_t)((u16) >> 8); |
| Kojto | 20:30b6ed7bf8fd | 516 | return p; |
| Kojto | 20:30b6ed7bf8fd | 517 | } |
| Kojto | 20:30b6ed7bf8fd | 518 | |
| Kojto | 20:30b6ed7bf8fd | 519 | |
| Kojto | 20:30b6ed7bf8fd | 520 | uint16_t STREAM_TO_UINT16_f(uint8_t *p, uint16_t offset) |
| Kojto | 20:30b6ed7bf8fd | 521 | { |
| Kojto | 20:30b6ed7bf8fd | 522 | return (uint16_t)((uint16_t)((uint16_t) |
| Kojto | 20:30b6ed7bf8fd | 523 | (*(p + offset + 1)) << 8) + (uint16_t)(*(p + offset))); |
| Kojto | 20:30b6ed7bf8fd | 524 | } |
| Kojto | 20:30b6ed7bf8fd | 525 | |
| Kojto | 20:30b6ed7bf8fd | 526 | |
| Kojto | 20:30b6ed7bf8fd | 527 | uint32_t STREAM_TO_UINT32_f(uint8_t *p, uint16_t offset) |
| Kojto | 20:30b6ed7bf8fd | 528 | { |
| Kojto | 20:30b6ed7bf8fd | 529 | return (uint32_t)((uint32_t)((uint32_t) |
| Kojto | 20:30b6ed7bf8fd | 530 | (*(p + offset + 3)) << 24) + (uint32_t)((uint32_t) |
| Kojto | 20:30b6ed7bf8fd | 531 | (*(p + offset + 2)) << 16) + (uint32_t)((uint32_t) |
| Kojto | 20:30b6ed7bf8fd | 532 | (*(p + offset + 1)) << 8) + (uint32_t)(*(p + offset))); |
| Kojto | 20:30b6ed7bf8fd | 533 | } |
| Kojto | 20:30b6ed7bf8fd | 534 | |
| Kojto | 45:50ab13d8f2dc | 535 | } // mbed_cc3000 namespace |
| Kojto | 20:30b6ed7bf8fd | 536 |
