cc3000 hostdriver with the mbed socket interface
Dependents: cc3000_hello_world_demo cc3000_simple_socket_demo cc3000_ntp_demo cc3000_ping_demo ... more
cc3000.h
00001 /***************************************************************************** 00002 * 00003 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to 00004 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and 00005 * provided help. 00006 * 00007 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus 00008 * read the following copyright: 00009 * 00010 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 00011 * 00012 * Redistribution and use in source and binary forms, with or without 00013 * modification, are permitted provided that the following conditions 00014 * are met: 00015 * 00016 * Redistributions of source code must retain the above copyright 00017 * notice, this list of conditions and the following disclaimer. 00018 * 00019 * Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in the 00021 * documentation and/or other materials provided with the 00022 * distribution. 00023 * 00024 * Neither the name of Texas Instruments Incorporated nor the names of 00025 * its contributors may be used to endorse or promote products derived 00026 * from this software without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00029 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00030 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00031 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00032 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00033 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00034 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00035 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00036 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00037 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00038 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 * 00040 *****************************************************************************/ 00041 #ifndef CC3000_H 00042 #define CC3000_H 00043 00044 #include "mbed.h" 00045 #include "cc3000_common.h" 00046 #include "cc3000_spi.h" 00047 #include "cc3000_simplelink.h" 00048 #include "cc3000_netapp.h" 00049 #include "cc3000_nvmem.h" 00050 #include "cc3000_socket.h" 00051 00052 #define MAX_SOCKETS 4 00053 // cc3000 Ethernet Interface - enabled by default 00054 #define CC3000_ETH_COMPAT 1 00055 00056 /** Enable debug messages - set 1 */ 00057 // Debug - Socket interface messages 00058 #define CC3000_DEBUG_SOCKET 0 00059 // Debug - HCI TX messages 00060 #define CC3000_DEBUG_HCI_TX 0 00061 // Debug - HCI Rx messages 00062 #define CC3000_DEBUG_HCI_RX 0 00063 // Debug - General Debug 00064 #define CC3000_DEBUG 0 00065 // Add colour to the debug messages, requires a VT100 terminal like putty, comment out to remove 00066 #define VT100_COLOUR 0 00067 00068 #if (CC3000_DEBUG_SOCKET == 1) 00069 #if (VT100_COLOUR == 1) 00070 #define DBG_SOCKET(x, ...) std::printf("\x1b[2;32;40m[CC3000 : SOCKET] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__); 00071 #else 00072 #define DBG_SOCKET(x, ...) std::printf("[CC3000 : SOCKET] "x"\r\n", ##__VA_ARGS__); 00073 #endif 00074 #else 00075 #define DBG_SOCKET(x, ...) 00076 #endif 00077 00078 #if (CC3000_DEBUG_HCI_TX == 1) 00079 #if (VT100_COLOUR == 1) 00080 #define DBG_HCI(x, ...) std::printf("\x1b[2;35;40m[CC3000 : HCI RX] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__); 00081 #else 00082 #define DBG_HCI(x, ...) std::printf("[CC3000 : HCI RX] "x"\r\n", ##__VA_ARGS__); 00083 #endif 00084 #else 00085 #define DBG_HCI(x, ...) 00086 #endif 00087 00088 #if (CC3000_DEBUG_HCI_RX == 1) 00089 #if (VT100_COLOUR == 1) 00090 #define DBG_HCI_CMD(x, ...) std::printf("\x1b[2;36;40m[CC3000 : HCI TX] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__); 00091 #else 00092 #define DBG_HCI_CMD(x, ...) std::printf("[CC3000 : HCI TX] "x"\r\n", ##__VA_ARGS__); 00093 #endif 00094 #else 00095 #define DBG_HCI_CMD(x, ...) 00096 #endif 00097 00098 #if (CC3000_DEBUG == 1) 00099 #if (VT100_COLOUR == 1) 00100 #define DBG_CC(x, ...) std::printf("\x1b[2;32;40m[CC3000] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__); 00101 #else 00102 #define DBG_CC(x, ...) std::printf("[CC3000] "x"\r\n", ##__VA_ARGS__); 00103 #endif 00104 #else 00105 #define DBG_CC(x, ...) 00106 #endif 00107 00108 namespace mbed_cc3000 { 00109 00110 /** User info structure 00111 */ 00112 typedef struct { 00113 uint8_t FTC; // First time config performed 00114 uint8_t PP_version[2]; // Patch Programmer version 00115 uint8_t SERV_PACK[2]; // Service Pack Version 00116 uint8_t DRV_VER[3]; // Driver Version 00117 uint8_t FW_VER[3]; // Firmware Version 00118 uint8_t validCIK; // CIK[] is valid (Client Interface Key) 00119 uint8_t CIK[40]; 00120 } tUserFS; 00121 00122 /** Function pointers which are not yet implemented 00123 */ 00124 enum FunctionNumber { 00125 FW_PATCHES = 0, 00126 DRIVER_PATCHES = 1, 00127 BOOTLOADER_PATCHES = 2, 00128 }; 00129 00130 /** AP security 00131 */ 00132 enum Security { 00133 NONE = 0, 00134 WEP = 1, 00135 WPA = 2, 00136 WPA2 = 3 00137 }; 00138 00139 /** CC3000 Simple Link class which contains status of cc3000. 00140 */ 00141 class cc3000_simple_link { 00142 public: 00143 /** 00144 * \brief ctor - sets magic number in the buffers (overflow mark). 00145 * \param none 00146 * \return none 00147 */ 00148 cc3000_simple_link(); 00149 /** 00150 * \brief dtor 00151 * \param none 00152 * \return none 00153 */ 00154 ~cc3000_simple_link(); 00155 /** 00156 * \brief Returns data received flag. 00157 * \return Data received flag. 00158 */ 00159 uint8_t get_data_received_flag(); 00160 /** 00161 * \brief Set data received flag. 00162 * \param value The value to be set. 00163 */ 00164 void set_data_received_flag(uint8_t value); 00165 /** Returns if tx was completed. 00166 * \return 00167 * true if tx was completed, 00168 * false otherwise. 00169 */ 00170 bool get_tx_complete_signal(); 00171 /** 00172 * \brief Sets flag that tx was completed. 00173 * \param value Value to be set 00174 * \return none 00175 */ 00176 void set_tx_complete_signal(bool value); 00177 /** 00178 * \brief Get receive buffer. 00179 * \param none 00180 * \return Pointer to the receive buffer. 00181 */ 00182 uint8_t *get_received_buffer(); 00183 /** 00184 * \brief Get transmit buffer. 00185 * \param none 00186 * \return Pointer to the transmit buffer. 00187 */ 00188 uint8_t *get_transmit_buffer(); 00189 /** 00190 * \brief Get number of free buffers. 00191 * \param none 00192 * \return 00193 * Number of free buffers. 00194 */ 00195 uint16_t get_number_free_buffers(); 00196 /** 00197 * \brief Set number of free buffers. 00198 * \param value Number of free buffers. 00199 * \return none 00200 */ 00201 void set_number_free_buffers(uint16_t value); 00202 /** 00203 * \brief Retrieve buffer length. 00204 * \param none 00205 * \return Buffer length 00206 */ 00207 uint16_t get_buffer_length(); 00208 /** 00209 * \brief Set buffer length 00210 * \param value The length 00211 * \return none 00212 */ 00213 void set_buffer_length(uint16_t value); 00214 /** 00215 * \brief Retrieve pending data flag. 00216 * \param none 00217 * \return Pending data flag 00218 */ 00219 uint16_t get_pending_data(); 00220 /** 00221 * \brief Set pending data flag. 00222 * \param value Pending data value. 00223 * \return none 00224 */ 00225 void set_pending_data(uint16_t value); 00226 /** 00227 * \brief Retreive op code. 00228 * \param none 00229 * \return Op code 00230 */ 00231 uint16_t get_op_code(); 00232 /** 00233 * \brief Set op code. 00234 * \param code op code. 00235 * \return none 00236 */ 00237 void set_op_code(uint16_t code); 00238 /** 00239 * \brief Get number of released packets. 00240 * \param none 00241 * \return Number of released packets. 00242 */ 00243 uint16_t get_released_packets(); 00244 /** 00245 * \brief Set number of released packets. 00246 * \param value Number of released packets. 00247 * \return none 00248 */ 00249 void set_number_of_released_packets(uint16_t value); 00250 /** 00251 * \brief Get number of sent packats 00252 * \param none 00253 * \return Number of sent packets. 00254 */ 00255 uint16_t get_sent_packets(); 00256 /** 00257 * \brief Set number of sent packets 00258 * \param value Number of sent packets. 00259 * \return none 00260 */ 00261 void set_sent_packets(uint16_t value); 00262 /** 00263 * \brief Retrieve transmit error 00264 * \param none 00265 * \return Transmit error 00266 */ 00267 int32_t get_transmit_error(); 00268 /** 00269 * \brief Set transmit error. 00270 * \param value Error to be set. 00271 * \return none 00272 */ 00273 void set_transmit_error(int32_t value); 00274 /** 00275 * \brief Get buffer size. 00276 * \param none 00277 * \return Size of buffer. 00278 */ 00279 uint16_t get_buffer_size(); 00280 /** 00281 * \brief Set buffer size. 00282 * \param value Buffer size. 00283 * \return none 00284 */ 00285 void set_buffer_size(uint16_t value); 00286 /** 00287 * \brief Not used currently. 00288 * \param function Number of desired function. 00289 * \return void pointer to the function (need to recast). 00290 */ 00291 void *get_func_pointer(FunctionNumber function); 00292 /** 00293 * \brief Retreive pointer to the received data. 00294 * \param none 00295 * \return Pointer to the received data buffer. 00296 */ 00297 uint8_t *get_received_data(); 00298 /** 00299 * \brief Set received data pointer. 00300 * \param pointer Pointer to the buffer. 00301 * \return none 00302 */ 00303 void set_received_data(uint8_t *pointer); 00304 private: 00305 uint8_t _data_received_flag; 00306 bool _tx_complete_signal; 00307 uint16_t _rx_event_opcode; 00308 uint16_t _free_buffers; 00309 uint16_t _buffer_length; 00310 uint16_t _buffer_size; 00311 uint16_t _rx_data_pending; 00312 uint16_t _sent_packets; 00313 uint16_t _released_packets; 00314 int32_t _transmit_data_error; 00315 uint8_t *_received_data; 00316 uint8_t _rx_buffer[CC3000_RX_BUFFER_SIZE]; 00317 uint8_t _tx_buffer[CC3000_TX_BUFFER_SIZE]; 00318 private: 00319 /* Not used currently */ 00320 int8_t *(* _fFWPatches)(uint32_t *length); 00321 int8_t *(* _fDriverPatches)(uint32_t *length); 00322 int8_t *(* _fBootLoaderPatches)(uint32_t *length); 00323 }; 00324 00325 /** Forward declaration classes 00326 */ 00327 class cc3000_hci; 00328 class cc3000_nvmem; 00329 class cc3000_spi; 00330 class cc3000; 00331 00332 /** Event layer 00333 */ 00334 class cc3000_event { 00335 public: 00336 /** 00337 * \brief Ctor 00338 * \param simplelink Reference to simple link object. 00339 * \param hci Reference to hci object. 00340 * \param spi Reference to spi object. 00341 * \param cc3000 Reference to cc3000 object. 00342 * \return none 00343 */ 00344 cc3000_event(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_spi &spi, cc3000 &cc3000); 00345 /** 00346 * \brief Dtor 00347 * \param none 00348 * \return none 00349 */ 00350 ~cc3000_event(); 00351 /** 00352 * \brief Handle unsolicited event from type patch request. 00353 * \param event_hdr event header 00354 * \return none 00355 */ 00356 void hci_unsol_handle_patch_request(uint8_t *event_hdr); 00357 /** 00358 * \brief Parse the incoming event packets and issue corresponding event handler from global array of handlers pointers. 00359 * \param ret_param incoming data buffer 00360 * \param from from information (in case of data received) 00361 * \param fromlen from information length (in case of data received) 00362 * \return none 00363 */ 00364 uint8_t* hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen); 00365 /** 00366 * \brief Handle unsolicited events. 00367 * \param event_hdr Event header 00368 * \return 1 if event supported and handled 00369 * \return 0 if event is not supported 00370 */ 00371 int32_t hci_unsol_event_handler(uint8_t *event_hdr); 00372 /** 00373 * \brief Parse the incoming unsolicited event packets and start corresponding event handler. 00374 * \param None 00375 * \return ESUCCESS if successful, EFAIL if an error occurred. 00376 */ 00377 int32_t hci_unsolicited_event_handler(void); 00378 /** 00379 * \brief Get the socket status. 00380 * \param Sd Socket IS 00381 * \return Current status of the socket. 00382 */ 00383 int32_t get_socket_active_status(int32_t sd); 00384 /** 00385 * \brief Check if the socket ID and status are valid and set the global socket status accordingly. 00386 * \param Sd Sock descr 00387 * \param Status status to be set 00388 * \return none 00389 */ 00390 void set_socket_active_status(int32_t sd, int32_t status); 00391 /** 00392 * \brief Keep track on the number of packets transmitted and update the number of free buffer in the SL device. 00393 * \brief Called when unsolicited event = HCI_EVNT_DATA_UNSOL_FREE_BUFF has received. 00394 * \param event pointer to the string contains parameters for IPERF. 00395 * \return ESUCCESS if successful, EFAIL if an error occurred. 00396 */ 00397 int32_t hci_event_unsol_flowcontrol_handler(uint8_t *event); 00398 /** 00399 * \brief Update the socket status. 00400 * \param resp_params Socket IS 00401 * \return Current status of the socket. 00402 */ 00403 void update_socket_active_status(uint8_t *resp_params); 00404 /** 00405 * \brief Wait for event, pass it to the hci_event_handler and update the event opcode in a global variable. 00406 * \param op_code Command operation code 00407 * \param ret_param Command return parameters 00408 * \return none 00409 */ 00410 void simplelink_wait_event(uint16_t op_code, void *ret_param); 00411 /** 00412 * \brief Wait for data, pass it to the hci_event_handler and set the data available flag. 00413 * \param buffer Data buffer 00414 * \param from From information 00415 * \param fromlen From information length 00416 * \return none 00417 */ 00418 void simplelink_wait_data(uint8_t *buffer, uint8_t *from, uint8_t *fromlen); 00419 /** 00420 * \brief Trigger Received event/data processing - called from the SPI library to receive the data 00421 * \param buffer pointer to the received data buffer\n 00422 * The function triggers Received event/data processing\n 00423 * \return none 00424 */ 00425 void received_handler(uint8_t *buffer); 00426 private: 00427 uint32_t socket_active_status; 00428 cc3000_simple_link &_simple_link; 00429 cc3000_hci &_hci; 00430 cc3000_spi &_spi; 00431 cc3000 &_cc3000; 00432 }; 00433 00434 /** Netapp layer 00435 */ 00436 class cc3000_netapp { 00437 public: 00438 /** 00439 * \brief Ctor 00440 * \param simple_link Reference to the simple link object. 00441 * \param nvmem Reference to the nvmem object. 00442 * \param hci Reference to the hci object. 00443 * \param event Reference to the event object. 00444 * \return none 00445 */ 00446 cc3000_netapp(cc3000_simple_link &simple_link, cc3000_nvmem &nvmem, cc3000_hci &hci, cc3000_event &event); 00447 /** 00448 * \brief Dtor 00449 * \param none 00450 * \return none 00451 */ 00452 ~cc3000_netapp(); 00453 /** 00454 * \brief Configure device MAC address and store it in NVMEM. 00455 * The value of the MAC address configured through the API will be\n 00456 * stored in CC3000 non volatile memory, thus preserved over resets.\n 00457 * \param mac device mac address, 6 bytes. Saved: yes 00458 * \return return on success 0, otherwise error. 00459 */ 00460 int32_t config_mac_adrress(uint8_t *mac); 00461 /** 00462 * \brief Configure the network interface, static or dynamic (DHCP). 00463 * In order to activate DHCP mode, ip, subnet_mask, default_gateway must be 0.\n 00464 * The default mode of CC3000 is DHCP mode. The configuration is saved in non volatile memory\n 00465 * and thus preserved over resets.\n 00466 * \param ip device mac address, 6 bytes. Saved: yes 00467 * \param subnet_mask device mac address, 6 bytes. Saved: yes 00468 * \param default_gateway device mac address, 6 bytes. Saved: yes 00469 * \param dns_server device mac address, 6 bytes. Saved: yes 00470 * \return 0 on success, otherwise error. 00471 * \note If the mode is altered, a reset of CC3000 device is required to apply the changes.\n 00472 * Also note that an asynchronous event of type 'DHCP_EVENT' is generated only when\n 00473 * a connection to the AP was established. This event is generated when an IP address\n 00474 * is allocated either by the DHCP server or by static allocation.\n 00475 */ 00476 int32_t dhcp(uint32_t *ip, uint32_t *subnet_mask,uint32_t *default_gateway, uint32_t *dns_server); 00477 #ifndef CC3000_TINY_DRIVER 00478 /** 00479 * \brief Get the CC3000 Network interface information. 00480 * This information is only available after establishing a WLAN connection.\n 00481 * Undefined values are returned when this function is called before association.\n 00482 * \param ipconfig pointer to a tNetappIpconfigRetArgs structure for storing the network interface configuration.\n 00483 * tNetappIpconfigRetArgs: aucIP - ip address,\n 00484 * aucSubnetMask - mask 00485 * aucDefaultGateway - default gateway address\n 00486 * aucDHCPServer - dhcp server address\n 00487 * aucDNSServer - dns server address\n 00488 * uaMacAddr - mac address\n 00489 * uaSSID - connected AP ssid\n 00490 * \return none 00491 * \note This function is useful for figuring out the IP Configuration of\n 00492 * the device when DHCP is used and for figuring out the SSID of\n 00493 * the Wireless network the device is associated with.\n 00494 */ 00495 void ipconfig(tNetappIpconfigRetArgs *ipconfig); 00496 /** 00497 * \brief Set new timeout values for DHCP lease timeout, ARP refresh timeout, keepalive event timeout and socket inactivity timeout 00498 * \param dhcp DHCP lease time request, also impact\n 00499 * the DHCP renew timeout.\n 00500 * Range: [0-0xffffffff] seconds,\n 00501 * 0 or 0xffffffff = infinite lease timeout.\n 00502 * Resolution: 10 seconds.\n 00503 * Influence: only after reconnecting to the AP. \n 00504 * Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds.\n 00505 * The parameter is saved into the CC3000 NVMEM.\n 00506 * The default value on CC3000 is 14400 seconds.\n 00507 * 00508 * \param arp ARP refresh timeout, if ARP entry is not updated by\n 00509 * incoming packet, the ARP entry will be deleted by\n 00510 * the end of the timeout. \n 00511 * Range: [0-0xffffffff] seconds, 0 = infinite ARP timeout\n 00512 * Resolution: 10 seconds.\n 00513 * Influence: at runtime.\n 00514 * Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds\n 00515 * The parameter is saved into the CC3000 NVMEM.\n 00516 * The default value on CC3000 is 3600 seconds.\n 00517 * 00518 * \param keep_alive Keepalive event sent by the end of keepalive timeout\n 00519 * Range: [0-0xffffffff] seconds, 0 == infinite timeout\n 00520 * Resolution: 10 seconds.\n 00521 * Influence: at runtime.\n 00522 * Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec\n 00523 * The parameter is saved into the CC3000 NVMEM. \n 00524 * The default value on CC3000 is 10 seconds.\n 00525 * 00526 * \param inactivity Socket inactivity timeout, socket timeout is\n 00527 * refreshed by incoming or outgoing packet, by the\n 00528 * end of the socket timeout the socket will be closed\n 00529 * Range: [0-0xffffffff] sec, 0 == infinite timeout.\n 00530 * Resolution: 10 seconds.\n 00531 * Influence: at runtime.\n 00532 * Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec\n 00533 * The parameter is saved into the CC3000 NVMEM.\n 00534 * The default value on CC3000 is 60 seconds.\n 00535 * 00536 * \return 0 on success,otherwise error. 00537 * 00538 * \note A parameter set to a non zero value less than 20s automatically changes to 20s. 00539 */ 00540 int32_t timeout_values(uint32_t *dhcp, uint32_t *arp,uint32_t *keep_alive, uint32_t *inactivity); 00541 /** 00542 * \brief send ICMP ECHO_REQUEST to network hosts 00543 * \param ip destination IP address 00544 * \param ping_attempts number of echo requests to send 00545 * \param ping_size send buffer size which may be up to 1400 bytes 00546 * \param ping_timeout Time to wait for a response,in milliseconds. 00547 * \return 0 on success, otherwise error. 00548 * 00549 * \note A succesful operation will generate an asynchronous ping report event.\n 00550 * The report structure is defined by structure netapp_pingreport_args_t.\n 00551 * \warning Calling this function while a Ping Request is in progress will kill the ping request in progress. 00552 */ 00553 int32_t ping_send(uint32_t *ip, uint32_t ping_attempts, uint32_t ping_size, uint32_t ping_timeout); 00554 /** 00555 * \brief Ping status request. 00556 * This API triggers the CC3000 to send asynchronous events: HCI_EVNT_WLAN_ASYNC_PING_REPORT.\n 00557 * This event will create the report structure in netapp_pingreport_args_t.\n 00558 * This structure is filled with ping results until the API is triggered.\n 00559 * netapp_pingreport_args_t: packets_sent - echo sent\n 00560 * packets_received - echo reply\n 00561 * min_round_time - minimum round time\n 00562 * max_round_time - max round time\n 00563 * avg_round_time - average round time\n 00564 * 00565 * \param none 00566 * \return none 00567 * \note When a ping operation is not active, the returned structure fields are 0. 00568 */ 00569 void ping_report(); 00570 /** 00571 * \brief Stop any ping request. 00572 * \param none 00573 * \return 0 on success 00574 * -1 on error 00575 */ 00576 int32_t ping_stop(); 00577 /** 00578 * \brief Flush ARP table 00579 * \param none 00580 * \return none 00581 */ 00582 int32_t arp_flush(); 00583 #endif 00584 private: 00585 cc3000_simple_link &_simple_link; 00586 cc3000_nvmem &_nvmem; 00587 cc3000_hci &_hci; 00588 cc3000_event &_event; 00589 }; 00590 00591 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG 00592 /** Security class used only if encrypted smart config is set 00593 */ 00594 class cc3000_security { 00595 public: 00596 /** 00597 * \brief Expand a 16 bytes key for AES128 implementation. 00598 * \param expanded_key expanded AES128 key 00599 * \param key AES128 key - 16 bytes 00600 * \return none 00601 */ 00602 void expandKey(uint8_t *expanded_key, uint8_t *key); 00603 /** 00604 * \brief multiply by 2 in the galois field. 00605 * \param value Argument to multiply 00606 * \return multiplied argument 00607 */ 00608 uint8_t galois_mul2(uint8_t value); 00609 /** 00610 * \brief internal implementation of AES128 encryption. 00611 * straight forward aes encryption implementation\n 00612 * first the group of operations 00613 * - addRoundKey 00614 * - subbytes 00615 * - shiftrows 00616 * - mixcolums\n 00617 * 00618 * is executed 9 times, after this addroundkey to finish the 9th\n 00619 * round, after that the 10th round without mixcolums\n 00620 * no further subfunctions to save cycles for function calls\n 00621 * no structuring with "for (....)" to save cycles.\n 00622 * \param[in] expanded_key expanded AES128 key 00623 * \param[in/out] state 16 bytes of plain text and cipher text 00624 * \return none 00625 */ 00626 void aes_encr(uint8_t *state, uint8_t *expanded_key); 00627 /** 00628 * \brief internal implementation of AES128 decryption. 00629 * straightforward aes decryption implementation\n 00630 * the order of substeps is the exact reverse of decryption\n 00631 * inverse functions: 00632 * - addRoundKey is its own inverse 00633 * - rsbox is inverse of sbox 00634 * - rightshift instead of leftshift 00635 * - invMixColumns = barreto + mixColumns\n 00636 * 00637 * no further subfunctions to save cycles for function calls\n 00638 * no structuring with "for (....)" to save cycles\n 00639 * \param[in] expanded_key expanded AES128 key 00640 * \param[in\out] state 16 bytes of cipher text and plain text 00641 * \return none 00642 */ 00643 void aes_decr(uint8_t *state, uint8_t *expanded_key); 00644 /** 00645 * \brief AES128 encryption. 00646 * Given AES128 key and 16 bytes plain text, cipher text of 16 bytes is computed.\n 00647 * The AES implementation is in mode ECB (Electronic Code Book).\n 00648 * \param[in] key AES128 key of size 16 bytes 00649 * \param[in\out] state 16 bytes of plain text and cipher text 00650 * \return none 00651 */ 00652 void aes_encrypt(uint8_t *state, uint8_t *key); 00653 /** 00654 * \brief AES128 decryption. 00655 * Given AES128 key and 16 bytes cipher text, plain text of 16 bytes is computed.\n 00656 * The AES implementation is in mode ECB (Electronic Code Book).\n 00657 * \param[in] key AES128 key of size 16 bytes 00658 * \param[in\out] state 16 bytes of cipher text and plain text 00659 * \return none 00660 */ 00661 void aes_decrypt(uint8_t *state, uint8_t *key); 00662 /** 00663 * \brief Read the AES128 key from fileID #12 in EEPROM. 00664 * \param[out] key AES128 key of size 16 bytes 00665 * \return 0 on success, error otherwise. 00666 */ 00667 int32_t aes_read_key(uint8_t *key); 00668 /** 00669 * \brief Write the AES128 key to fileID #12 in EEPROM. 00670 * \param[out] key AES128 key of size 16 bytes 00671 * \return on success 0, error otherwise. 00672 */ 00673 int32_t aes_write_key(uint8_t *key); 00674 private: 00675 uint8_t _expanded_key[176]; 00676 }; 00677 #endif 00678 00679 /** Socket layer 00680 */ 00681 class cc3000_socket { 00682 public: 00683 /** 00684 * \brief Ctor 00685 * \param simplelink Reference to simple link object. 00686 * \param hci Reference to hci object. 00687 * \param event Reference to event object. 00688 * \return none 00689 */ 00690 cc3000_socket(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_event &event); 00691 /** 00692 * \brief Dtor 00693 * \param 00694 * \return none 00695 */ 00696 ~cc3000_socket(); 00697 /** 00698 * \brief create an endpoint for communication. 00699 * The socket function creates a socket that is bound to a specific transport service provider.\n 00700 * This function is called by the application layer to obtain a socket handle.\n 00701 * 00702 * \param domain selects the protocol family which will be used for\n 00703 * communication. On this version only AF_INET is supported\n 00704 * \param type specifies the communication semantics. On this version\n 00705 * only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported\n 00706 * \param protocol specifies a particular protocol to be used with the\n 00707 * socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are supported.\n 00708 * \return On success, socket handle that is used for consequent socket operations\n 00709 * On error, -1 is returned.\n 00710 */ 00711 int32_t socket(int32_t domain, int32_t type, int32_t protocol); 00712 /** 00713 * \brief accept a connection on a socket. 00714 * This function is used with connection-based socket types\n 00715 * (SOCK_STREAM). It extracts the first connection request on the\n 00716 * queue of pending connections, creates a new connected socket, and\n 00717 * returns a new file descriptor referring to that socket.\n 00718 * The newly created socket is not in the listening state.\n 00719 * The original socket sd is unaffected by this call.\n 00720 * The argument sd is a socket that has been created with socket(),\n 00721 * bound to a local address with bind(), and is listening for \n 00722 * connections after a listen(). The argument addr is a pointer \n 00723 * to a sockaddr structure. This structure is filled in with the \n 00724 * address of the peer socket, as known to the communications layer.\n 00725 * The exact format of the address returned addr is determined by the \n 00726 * socket's address family. The addrlen argument is a value-result\n 00727 * argument: it should initially contain the size of the structure\n 00728 * pointed to by addr, on return it will contain the actual\n 00729 * length (in bytes) of the address returned.\n 00730 * 00731 * \param[in] sd socket descriptor (handle)\n 00732 * \param[out] addr the argument addr is a pointer to a sockaddr structure\n 00733 * This structure is filled in with the address of the \n 00734 * peer socket, as known to the communications layer. \n 00735 * determined. The exact format of the address returned \n 00736 * addr is by the socket's address sockaddr. \n 00737 * On this version only AF_INET is supported.\n 00738 * This argument returns in network order.\n 00739 * \param[out] addrlen the addrlen argument is a value-result argument: \n 00740 * it should initially contain the size of the structure\n 00741 * pointed to by addr.\n 00742 * \return For socket in blocking mode:\n 00743 * - On success, socket handle. on failure negative\n 00744 * For socket in non-blocking mode:\n 00745 * - On connection establishment, socket handle\n 00746 * - On connection pending, SOC_IN_PROGRESS (-2)\n 00747 * - On failure, SOC_ERROR (-1)\n 00748 * \sa socket ; bind ; listen 00749 */ 00750 int32_t accept(int32_t sd, sockaddr *addr, socklen_t *addrlen); 00751 /** 00752 * \brief assign a name to a socket. 00753 * This function gives the socket the local address addr.\n 00754 * addr is addrlen bytes long. Traditionally, this is called when a \n 00755 * socket is created with socket, it exists in a name space (address \n 00756 * family) but has no name assigned.\n 00757 * It is necessary to assign a local address before a SOCK_STREAM\n 00758 * socket may receive connections.\n 00759 * 00760 * \param[in] sd socket descriptor (handle) 00761 * \param[out] addr specifies the destination address. On this version\n 00762 * only AF_INET is supported.\n 00763 * \param[out] addrlen contains the size of the structure pointed to by addr.\n 00764 * \return On success, zero is returned.\n 00765 * On error, -1 is returned.\n 00766 * \sa socket ; accept ; listen 00767 */ 00768 int32_t bind(int32_t sd, const sockaddr *addr, int32_t addrlen); 00769 /** 00770 * \brief HostFlowControlConsumeBuff. 00771 * if SEND_NON_BLOCKING is not defined - block until a free buffer is available,\n 00772 * otherwise return the status of the available buffers.\n 00773 * 00774 * \param sd socket descriptor 00775 * \return 0 in case there are buffers available, \n 00776 * -1 in case of bad socket\n 00777 * -2 if there are no free buffers present (only when SEND_NON_BLOCKING is enabled)\n 00778 */ 00779 int32_t HostFlowControlConsumeBuff(int32_t sd); 00780 /** 00781 * \brief The socket function closes a created socket. 00782 * \param sd socket handle. 00783 * \return On success, zero is returned. On error, -1 is returned. 00784 */ 00785 int32_t closesocket(int32_t sd); 00786 /** 00787 * \brief listen for connections on a socket. 00788 * The willingness to accept incoming connections and a queue\n 00789 * limit for incoming connections are specified with listen(),\n 00790 * and then the connections are accepted with accept.\n 00791 * The listen() call applies only to sockets of type SOCK_STREAM\n 00792 * The backlog parameter defines the maximum length the queue of\n 00793 * pending connections may grow to. \n 00794 * 00795 * \param[in] sd socket descriptor (handle) 00796 * \param[in] backlog specifies the listen queue depth. On this version\n 00797 * backlog is not supported.\n 00798 * \return On success, zero is returned.\n 00799 * On error, -1 is returned.\n 00800 * \sa socket ; accept ; bind 00801 * \note On this version, backlog is not supported 00802 */ 00803 int32_t listen(int32_t sd, int32_t backlog); 00804 /** 00805 * \brief initiate a connection on a socket. 00806 * Function connects the socket referred to by the socket descriptor\n 00807 * sd, to the address specified by addr. The addrlen argument \n 00808 * specifies the size of addr. The format of the address in addr is \n 00809 * determined by the address space of the socket. If it is of type \n 00810 * SOCK_DGRAM, this call specifies the peer with which the socket is \n 00811 * to be associated; this address is that to which datagrams are to be\n 00812 * sent, and the only address from which datagrams are to be received. \n 00813 * If the socket is of type SOCK_STREAM, this call attempts to make a \n 00814 * connection to another socket. The other socket is specified by \n 00815 * address, which is an address in the communications space of the\n 00816 * socket. Note that the function implements only blocking behavior \n 00817 * thus the caller will be waiting either for the connection \n 00818 * establishment or for the connection establishment failure.\n 00819 * 00820 * \param[in] sd socket descriptor (handle) 00821 * \param[in] addr specifies the destination addr. On this version\n 00822 * only AF_INET is supported.\n 00823 * \param[out] addrlen contains the size of the structure pointed to by addr 00824 * \return On success, zero is returned.\n 00825 On error, -1 is returned\n 00826 * \sa socket 00827 */ 00828 int32_t connect(int32_t sd, const sockaddr *addr, int32_t addrlen); 00829 /** 00830 * \brief Monitor socket activity. 00831 * Select allow a program to monitor multiple file descriptors,\n 00832 * waiting until one or more of the file descriptors become \n 00833 * "ready" for some class of I/O operation \n 00834 * 00835 * \param[in] nfds the highest-numbered file descriptor in any of the\n 00836 * three sets, plus 1. \n 00837 * \param[out] readsds socket descriptors list for read monitoring\n 00838 * \param[out] writesds socket descriptors list for write monitoring\n 00839 * \param[out] exceptsds socket descriptors list for exception monitoring\n 00840 * \param[in] timeout is an upper bound on the amount of time elapsed\n 00841 * before select() returns. Null means infinity \n 00842 * timeout. The minimum timeout is 5 milliseconds,\n 00843 * less than 5 milliseconds will be set\n 00844 * automatically to 5 milliseconds.\n 00845 * \return On success, select() returns the number of file descriptors\n 00846 * contained in the three returned descriptor sets (that is, the\n 00847 * total number of bits that are set in readfds, writefds,\n 00848 * exceptfds) which may be zero if the timeout expires before\n 00849 * anything interesting happens.\n 00850 * On error, -1 is returned.\n 00851 * *readsds - return the sockets on which Read request will\n 00852 * return without delay with valid data.\n 00853 * *writesds - return the sockets on which Write request \n 00854 * will return without delay.\n 00855 * *exceptsds - return the sockets which closed recently.\n 00856 * \Note If the timeout value set to less than 5ms it will automatically\n 00857 * change to 5ms to prevent overload of the system\n 00858 * \sa socket 00859 */ 00860 int32_t select(int32_t nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout); 00861 /** 00862 * \brief get socket options. 00863 * This function manipulate the options associated with a socket.\n 00864 * Options may exist at multiple protocol levels; they are always\n 00865 * present at the uppermost socket level.\n 00866 * When manipulating socket options the level at which the option \n 00867 * resides and the name of the option must be specified. \n 00868 * To manipulate options at the socket level, level is specified as \n 00869 * SOL_SOCKET. To manipulate options at any other level the protocol \n 00870 * number of the appropriate protocol controlling the option is \n 00871 * supplied. For example, to indicate that an option is to be \n 00872 * interpreted by the TCP protocol, level should be set to the \n 00873 * protocol number of TCP; \n 00874 * The parameters optval and optlen are used to access optval -\n 00875 * use for setsockopt(). For getsockopt() they identify a buffer\n 00876 * in which the value for the requested option(s) are to \n 00877 * be returned. For getsockopt(), optlen is a value-result \n 00878 * parameter, initially containing the size of the buffer \n 00879 * pointed to by option_value, and modified on return to \n 00880 * indicate the actual size of the value returned. If no option \n 00881 * value is to be supplied or returned, option_value may be NULL.\n 00882 * 00883 * \param[in] sd socket handle 00884 * \param[in] level defines the protocol level for this option 00885 * \param[in] optname defines the option name to Interrogate 00886 * \param[out] optval specifies a value for the option 00887 * \param[out] optlen specifies the length of the option value 00888 * \return On success, zero is returned. On error, -1 is returned 00889 * 00890 * \Note On this version the following two socket options are enabled:\n 00891 * The only protocol level supported in this version is SOL_SOCKET (level).\n 00892 * 1. SOCKOPT_RECV_TIMEOUT (optname)\n 00893 * SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout in milliseconds.\n 00894 * In that case optval should be pointer to unsigned long.\n 00895 * 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on or off.\n 00896 * In that case optval should be SOCK_ON or SOCK_OFF (optval).\n 00897 * \sa setsockopt 00898 */ 00899 int32_t getsockopt (int32_t sd, int32_t level, int32_t optname, void *optval, socklen_t *optlen); 00900 /** 00901 * \brief Read data from socket (simple_link_recv). 00902 * Return the length of the message on successful completion.\n 00903 * If a message is too long to fit in the supplied buffer, excess bytes may\n 00904 * be discarded depending on the type of socket the message is received from.\n 00905 * 00906 * \param sd socket handle 00907 * \param buf read buffer 00908 * \param len buffer length 00909 * \param flags indicates blocking or non-blocking operation 00910 * \param from pointer to an address structure indicating source address 00911 * \param fromlen source address structure size 00912 * \return Return the number of bytes received, or -1 if an error occurred 00913 */ 00914 int32_t simple_link_recv(int32_t sd, void *buf, int32_t len, int32_t flags, sockaddr *from, socklen_t *fromlen, int32_t opcode); 00915 /** 00916 * \brief Transmit a message to another socket (simple_link_send). 00917 * \param sd socket handle 00918 * \param buf write buffer 00919 * \param len buffer length 00920 * \param flags On this version, this parameter is not supported 00921 * \param to pointer to an address structure indicating destination address 00922 * \param tolen destination address structure size 00923 * \return Return the number of bytes transmitted, or -1 if an error\n 00924 * occurred, or -2 in case there are no free buffers available\n 00925 * (only when SEND_NON_BLOCKING is enabled)\n 00926 */ 00927 int32_t simple_link_send(int32_t sd, const void *buf, int32_t len, int32_t flags, const sockaddr *to, int32_t tolen, int32_t opcode); 00928 /** 00929 * \brief Receive a message from a connection-mode socket. 00930 * \param[in] sd socket handle 00931 * \param[out] buf Points to the buffer where the message should be stored 00932 * \param[in] len Specifies the length in bytes of the buffer pointed to \n 00933 * by the buffer argument.\n 00934 * \param[in] flags Specifies the type of message reception. \n 00935 * On this version, this parameter is not supported.\n 00936 * \return Return the number of bytes received, or -1 if an error occurred 00937 * \sa recvfrom 00938 * \Note On this version, only blocking mode is supported. 00939 */ 00940 int32_t recv(int32_t sd, void *buf, int32_t len, int32_t flags); 00941 /** 00942 * \brief read data from socket (recvfrom). 00943 * Receives a message from a connection-mode or connectionless-mode socket.\n 00944 * Note that raw sockets are not supported.\n 00945 * 00946 * \param[in] sd socket handle 00947 * \param[out] buf Points to the buffer where the message should be stored 00948 * \param[in] len Specifies the length in bytes of the buffer pointed to \n 00949 * by the buffer argument.\n 00950 * \param[in] flags Specifies the type of message reception.\n 00951 * On this version, this parameter is not supported.\n 00952 * \param[in] from pointer to an address structure indicating the source\n 00953 * address: sockaddr. On this version only AF_INET is\n 00954 * supported.\n 00955 * \param[in] fromlen source address structure size 00956 * \return Return the number of bytes received, or -1 if an error occurred 00957 * \sa recv 00958 * \Note On this version, only blocking mode is supported. 00959 */ 00960 int32_t recvfrom(int32_t sd, void *buf, int32_t len, int32_t flags, sockaddr *from, socklen_t *fromlen); 00961 /** 00962 * \brief Transmit a message to another socket (send). 00963 * \param sd socket handle 00964 * \param buf Points to a buffer containing the message to be sent 00965 * \param len message size in bytes 00966 * \param flags On this version, this parameter is not supported 00967 * \return Return the number of bytes transmitted, or -1 if an\n 00968 * error occurred\n 00969 * \Note On this version, only blocking mode is supported. 00970 * \sa sendto 00971 */ 00972 int32_t send(int32_t sd, const void *buf, int32_t len, int32_t flags); 00973 /** 00974 * \brief Transmit a message to another socket (sendto). 00975 * \param sd socket handle 00976 * \param buf Points to a buffer containing the message to be sent 00977 * \param len message size in bytes 00978 * \param flags On this version, this parameter is not supported 00979 * \param to pointer to an address structure indicating the destination\n 00980 * address: sockaddr. On this version only AF_INET is\n 00981 * supported.\n 00982 * \param tolen destination address structure size 00983 * \return Return the number of bytes transmitted, or -1 if an error occurred 00984 * \Note On this version, only blocking mode is supported. 00985 * \sa send 00986 */ 00987 int32_t sendto(int32_t sd, const void *buf, int32_t len, int32_t flags, const sockaddr *to, socklen_t tolen); 00988 /** 00989 * \brief Set CC3000 in mDNS advertiser mode in order to advertise itself. 00990 * \param[in] mdns_enabled flag to enable/disable the mDNS feature 00991 * \param[in] device_service_name Service name as part of the published\n 00992 * canonical domain name\n 00993 * \param[in] device_service_name_length Length of the service name 00994 * \return On success, zero is returned,\n 00995 * return SOC_ERROR if socket was not opened successfully, or if an error occurred.\n 00996 */ 00997 int32_t mdns_advertiser(uint16_t mdns_enabled, uint8_t * device_service_name, uint16_t device_service_name_length); 00998 /** 00999 * \brief 01000 * \param[in] s_addr in host format ( little endian ) 01001 * \param[in] *buf buffer to write too 01002 * \param[in] buflen length of supplied buffer 01003 * \return pointer to buf \n 01004 */ 01005 char * inet_ntoa_r (uint32_t s_addr, char *buf, int buflen); 01006 #ifndef CC3000_TINY_DRIVER 01007 /** 01008 * \brief Get host IP by name.\n 01009 * Obtain the IP Address of machine on network\n 01010 * 01011 * \param[in] hostname host name 01012 * \param[in] name_length name length 01013 * \param[out] out_ip_addr This parameter is filled in with host IP address.\n 01014 * In case that host name is not resolved, \n 01015 * out_ip_addr is zero.\n 01016 * \return On success, positive is returned.\n 01017 * On error, negative is returned by its name.\n 01018 * \note On this version, only blocking mode is supported. Also note that\n 01019 * The function requires DNS server to be configured prior to its usage.\n 01020 */ 01021 int32_t gethostbyname(uint8_t *hostname, uint16_t name_length, uint32_t *out_ip_addr); 01022 /** 01023 * \brief set socket options. 01024 * This function manipulate the options associated with a socket.\n 01025 * Options may exist at multiple protocol levels; they are always\n 01026 * present at the uppermost socket level.\n 01027 * When manipulating socket options the level at which the option \n 01028 * resides and the name of the option must be specified.\n 01029 * To manipulate options at the socket level, level is specified as\n 01030 * SOL_SOCKET. To manipulate options at any other level the protocol \n 01031 * number of the appropriate protocol controlling the option is \n 01032 * supplied. For example, to indicate that an option is to be \n 01033 * interpreted by the TCP protocol, level should be set to the \n 01034 * protocol number of TCP; \n 01035 * The parameters optval and optlen are used to access optval - \n 01036 * use for setsockopt(). For getsockopt() they identify a buffer\n 01037 * in which the value for the requested option(s) are to \n 01038 * be returned. For getsockopt(), optlen is a value-result \n 01039 * parameter, initially containing the size of the buffer \n 01040 * pointed to by option_value, and modified on return to \n 01041 * indicate the actual size of the value returned. If no option \n 01042 * value is to be supplied or returned, option_value may be NULL.\n 01043 * 01044 * \param[in] sd socket handle 01045 * \param[in] level defines the protocol level for this option 01046 * \param[in] optname defines the option name to Interrogate 01047 * \param[in] optval specifies a value for the option 01048 * \param[in] optlen specifies the length of the option value 01049 * \return On success, zero is returned.\n 01050 * On error, -1 is returned\n 01051 * 01052 * \Note On this version the following two socket options are enabled:\n 01053 * The only protocol level supported in this version is SOL_SOCKET (level).\n 01054 * 1. SOCKOPT_RECV_TIMEOUT (optname)\n 01055 * SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout in milliseconds.\n 01056 * In that case optval should be pointer to unsigned long.\n 01057 * 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on or off.\n 01058 * In that case optval should be SOCK_ON or SOCK_OFF (optval).\n 01059 * \sa getsockopt 01060 */ 01061 int32_t setsockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen); 01062 #endif 01063 private: 01064 cc3000_simple_link &_simple_link; 01065 cc3000_hci &_hci; 01066 cc3000_event &_event; 01067 }; 01068 01069 /** SPI communication layer 01070 */ 01071 class cc3000_spi { 01072 public: 01073 /** 01074 * \brief Ctor 01075 * \param irq IRQ pin 01076 * \param cc3000_en Enable pin 01077 * \param cc3000_cs Chip select pin 01078 * \param cc3000_spi SPI object 01079 * \param irq_port Port for IRQ pin (needed for enable/disable interrupts) 01080 * \param event Reference to the event object. 01081 * \param simple_link Reference to the simple link object. 01082 * \return none 01083 */ 01084 cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, cc3000_event &event, cc3000_simple_link &simple_link); 01085 /** 01086 * \brief Dtor 01087 * \param none 01088 * \return none 01089 */ 01090 ~cc3000_spi(); 01091 /** 01092 * \brief Close SPI - disables IRQ and set received buffer to 0 01093 * \param none 01094 * \return none 01095 */ 01096 void close(); 01097 /** 01098 * \brief Open the SPI interface 01099 * \param none 01100 * \return none 01101 */ 01102 void open(); 01103 /** 01104 * \brief First SPI write after powerup (delay needed between SPI header and body) 01105 * \param buffer pointer to write buffer 01106 * \param length buffer length 01107 * \return 0 01108 */ 01109 uint32_t first_write(uint8_t *buffer, uint16_t length); 01110 /** 01111 * \brief SPI Write function 01112 * \param buffer pointer to write buffer 01113 * \param length buffer length 01114 * \return 0 01115 */ 01116 uint32_t write(uint8_t *buffer, uint16_t length); 01117 /** 01118 * \brief Low level SPI write 01119 * \param data pointer to data buffer 01120 * \param size number of bytes 01121 * \return none 01122 */ 01123 void write_synchronous(uint8_t *data, uint16_t size); 01124 /** 01125 * \brief Low level SPI read 01126 * \param data pointer to data buffer 01127 * \param size number of bytes 01128 * \return none 01129 */ 01130 void read_synchronous(uint8_t *data, uint16_t size); 01131 /** 01132 * \brief Process the received SPI Header and in accordance with it - continue reading the packet 01133 * \param None 01134 * \return 0 01135 */ 01136 uint32_t read_data_cont(); 01137 /** 01138 * \brief Enable WLAN interrutp 01139 * \param None 01140 * \return None 01141 */ 01142 void wlan_irq_enable(); 01143 /** 01144 * \brief Disable WLAN interrutp 01145 * \param None 01146 * \return None 01147 */ 01148 void wlan_irq_disable(); 01149 /** 01150 * \brief Get WLAN interrupt status 01151 * \param None 01152 * \return 0 : No interrupt occured 01153 * 1 : Interrupt occured 01154 */ 01155 uint32_t wlan_irq_read(); 01156 /** 01157 * \brief SPI interrupt Handler. 01158 * The external WLAN device asserts the IRQ line when data is ready.\n 01159 * The host CPU needs to acknowledges the IRQ by asserting CS.\n 01160 * 01161 * \param none 01162 * \return none 01163 */ 01164 void WLAN_IRQHandler(); 01165 /** 01166 * \brief Enable/Disable the WLAN module 01167 * \param value 1 : Enable 01168 * 0 : Disable 01169 * \return None 01170 */ 01171 void set_wlan_en(uint8_t value); 01172 private: 01173 tSpiInfo _spi_info; 01174 InterruptIn _wlan_irq; 01175 DigitalOut _wlan_en; 01176 DigitalOut _wlan_cs; 01177 SPI _wlan_spi; 01178 cc3000_event &_event; 01179 cc3000_simple_link &_simple_link; 01180 bool _process_irq; 01181 }; 01182 01183 /** HCI layer 01184 */ 01185 class cc3000_hci { 01186 public: 01187 /** 01188 * \brief Ctor 01189 * \param spi Reference to the spi object. 01190 * \return none 01191 */ 01192 cc3000_hci(cc3000_spi &spi); 01193 /** 01194 * \brief Dtor 01195 * \param none 01196 * \return none 01197 */ 01198 ~cc3000_hci(); 01199 /** 01200 * \brief Initiate an HCI command. 01201 * \param op_code command operation code 01202 * \param buffer pointer to the command's arguments buffer 01203 * \param length length of the arguments 01204 * \return 0 01205 */ 01206 uint16_t command_send(uint16_t op_code, uint8_t *buffer, uint8_t length); 01207 /** 01208 * \brief Initiate an HCI data write operation 01209 * \param op_code command operation code 01210 * \param args pointer to the command's arguments buffer 01211 * \param arg_length length of the arguments 01212 * \param data_length length od data 01213 * \param tail pointer to the data buffer 01214 * \param tail_length buffer length 01215 * \return ESUCCESS 01216 */ 01217 uint32_t data_send(uint8_t op_code, uint8_t *args, uint16_t arg_length, 01218 uint16_t data_length, const uint8_t *tail, uint16_t tail_length); 01219 /** 01220 * \brief Prepare HCI header and initiate an HCI data write operation. 01221 * \param op_code command operation code 01222 * \param buffer pointer to the data buffer 01223 * \param arg_length arguments length 01224 * \param data_length data length 01225 * \return none 01226 */ 01227 void data_command_send(uint16_t op_code, uint8_t *buffer, uint8_t arg_length, 01228 uint16_t data_length); 01229 /** 01230 * \brief Prepare HCI header and initiate an HCI patch write operation. 01231 * \param op_code command operation code 01232 * \param buffer pointer to the command's arguments buffer 01233 * \param patch pointer to patch content buffer 01234 * \param data_length data length 01235 * \return none 01236 */ 01237 void patch_send(uint8_t op_code, uint8_t *buffer, uint8_t *patch, uint16_t data_length); 01238 private: 01239 cc3000_spi &_spi; 01240 }; 01241 01242 /** NVMEM layer 01243 */ 01244 class cc3000_nvmem { 01245 public: 01246 /** 01247 * \brief Ctor 01248 * \param hci Reference to the hci object. 01249 * \param event Reference to the event object. 01250 * \param simple_link Reference to the simple link object. 01251 * \return none 01252 */ 01253 cc3000_nvmem(cc3000_hci &hci, cc3000_event &event, cc3000_simple_link &simple_link); 01254 /** 01255 * \brief Dtor 01256 * \param none 01257 * \return none 01258 */ 01259 ~cc3000_nvmem(); 01260 /** 01261 * \brief Reads data from the file referred by the file_id parameter. 01262 * Reads data from file offset till length. Err if the file can't be used, 01263 * is invalid, or if the read is out of bounds. 01264 * \param file_id nvmem file id. 01265 * \param length number of bytes to read. 01266 * \param offset offset in file from where to read. 01267 * \param buff output buffer pointer. 01268 * \return 01269 * Number of bytes read, otherwise error. 01270 */ 01271 int32_t read(uint32_t file_id, uint32_t length, uint32_t offset, uint8_t *buff); 01272 /** 01273 * \brief Write data to nvmem. 01274 * \param file_id Nvmem file id 01275 * \param length number of bytes to write 01276 * \param entry_offset offset in file to start write operation from 01277 * \param buff data to write 01278 * \return 01279 * On success 0, error otherwise. 01280 */ 01281 int32_t write(uint32_t file_id, uint32_t length, uint32_t entry_offset, uint8_t *buff); 01282 /** 01283 * \brief Write MAC address to EEPROM. 01284 * \param mac Mac address to be set 01285 * \return 01286 * On success 0, error otherwise. 01287 */ 01288 uint8_t set_mac_address(uint8_t *mac); 01289 /** 01290 * \brief Read MAC address from EEPROM. 01291 * \param mac Mac address 01292 * \return 01293 * On success 0, error otherwise. 01294 */ 01295 uint8_t get_mac_address(uint8_t *mac); 01296 /** 01297 * \brief Program a patch to a specific file ID. The SP data is assumed to be organized in 2-dimensional. 01298 * Each line is SP_PORTION_SIZE bytes long. 01299 * \param file_id nvmem file id/ 01300 * \param length number of bytes to write 01301 * \param data SP data to write 01302 * \return 01303 * On success 0, error otherwise. 01304 */ 01305 uint8_t write_patch(uint32_t file_id, uint32_t length, const uint8_t *data); 01306 /** 01307 * \brief Create new file entry and allocate space on the NVMEM. Applies only to user files. 01308 * \param file_id nvmem file Id 01309 * \param new_len entry ulLength 01310 * \return 01311 */ 01312 int32_t create_entry(uint32_t file_id, uint32_t new_len); 01313 #ifndef CC3000_TINY_DRIVER 01314 /** 01315 * \brief Read patch version. read package version (WiFi FW patch, river-supplicant-NS patch, 01316 * bootloader patch) 01317 * \param patch_ver First number indicates package ID and the second number indicates 01318 * package build number 01319 * \return 01320 * On success 0, error otherwise. 01321 */ 01322 uint8_t read_sp_version(uint8_t* patch_ver); 01323 #endif 01324 private: 01325 cc3000_hci &_hci; 01326 cc3000_event &_event; 01327 cc3000_simple_link &_simple_link; 01328 }; 01329 01330 /** WLAN layer 01331 */ 01332 class cc3000_wlan { 01333 public: 01334 /** 01335 * \brief Ctor 01336 * \param simple_link Reference to the simple link object. 01337 * \param event Reference to the event object. 01338 * \param spi Reference to the spi object. 01339 * \param hci Reference to the hci object. 01340 * \return none 01341 */ 01342 cc3000_wlan(cc3000_simple_link &simple_link, cc3000_event &event, cc3000_spi &spi, cc3000_hci &hci); 01343 /** 01344 * \brief Dtor 01345 * \param none 01346 * \return none 01347 */ 01348 ~cc3000_wlan(); 01349 /** 01350 * \brief Send SIMPLE LINK START to cc3000. 01351 * \param patches_available_host Flag to indicate if patches are available. 01352 * \return none 01353 */ 01354 void simpleLink_init_start(uint16_t patches_available_host); 01355 /** 01356 * \brief Start wlan device. Blocking call until init is completed. 01357 * \param patches_available_host Flag to indicate if patches are available. 01358 * \return none 01359 */ 01360 void start(uint16_t patches_available_host); 01361 /** 01362 * \brief Stop wlan device 01363 * \param none 01364 * \return none 01365 */ 01366 void stop(void); 01367 #ifndef CC3000_TINY_DRIVER 01368 /** 01369 * \brief Connect to AP. 01370 * \param sec_type Security option. 01371 * \param ssid up to 32 bytes, ASCII SSID 01372 * \param ssid_length length of SSID 01373 * \param b_ssid 6 bytes specified the AP bssid 01374 * \param key up to 16 bytes specified the AP security key 01375 * \param key_len key length 01376 * \return 01377 * On success, zero is returned. On error, negative is returned. 01378 */ 01379 int32_t connect(uint32_t sec_type, const uint8_t *ssid, int32_t ssid_length, uint8_t *b_ssid, uint8_t *key, int32_t key_len); 01380 /** 01381 * \brief Add profile. Up to 7 profiles are supported. 01382 * \param sec_type Security option. 01383 * \param ssid Up to 32 bytes, ASCII SSID 01384 * \param ssid_length Length of SSID 01385 * \param b_ssid 6 bytes specified the AP bssid 01386 * \param priority Up to 16 bytes specified the AP security key 01387 * \param pairwise_cipher_or_tx_key_len Key length 01388 * \param group_cipher_tx_key_index Key length for WEP security 01389 * \param key_mgmt KEY management 01390 * \param pf_or_key Security key 01391 * \param pass_phrase_length Security key length for WPA\WPA2 01392 * \return 01393 * On success, zero is returned. On error, negative is returned. 01394 */ 01395 int32_t add_profile(uint32_t sec_type, uint8_t* ssid, uint32_t ssid_length, uint8_t *b_ssid, uint32_t priority, uint32_t pairwise_cipher_or_tx_key_len, uint32_t group_cipher_tx_key_index, 01396 uint32_t key_mgmt, uint8_t* pf_or_key, uint32_t pass_phrase_length); 01397 /** 01398 * \brief Gets entry from scan result table. The scan results are returned 01399 * one by one, and each entry represents a single AP found in the area. 01400 * \param scan_timeout Not supported yet 01401 * \param results Scan result 01402 * \return 01403 * On success, zero is returned. On error, -1 is returned 01404 */ 01405 int32_t ioctl_get_scan_results(uint32_t scan_timeout, uint8_t *results); 01406 /** 01407 * \brief Start and stop scan procedure. Set scan parameters. 01408 * \param enable Start/stop application scan 01409 * \param min_dwell_time Minimum dwell time value to be used for each channel, in ms. (Default: 20) 01410 * \param max_dwell_time Maximum dwell time value to be used for each channel, in ms. (Default: 30) 01411 * \param num_probe_requests Max probe request between dwell time. (Default:2) 01412 * \param channel_mask Bitwise, up to 13 channels (0x1fff). 01413 * \param rssi_threshold RSSI threshold. Saved: yes (Default: -80) 01414 * \param snr_threshold NSR threshold. Saved: yes (Default: 0) 01415 * \param default_tx_power probe Tx power. Saved: yes (Default: 205) 01416 * \param interval_list Pointer to array with 16 entries (16 channels) 01417 * \return 01418 * On success, zero is returned. On error, -1 is returned. 01419 */ 01420 int32_t ioctl_set_scan_params(uint32_t enable, uint32_t min_dwell_time, uint32_t max_dwell_time, uint32_t num_probe_requests, 01421 uint32_t channel_mask, int32_t rssi_threshold, uint32_t snr_threshold, uint32_t default_tx_power, uint32_t *interval_list); 01422 /** 01423 * \brief Get wlan status: disconnected, scanning, connecting or connected 01424 * \param none 01425 * \return 01426 * WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING, STATUS_CONNECTING or WLAN_STATUS_CONNECTED 01427 */ 01428 int32_t ioctl_statusget(void); 01429 #else 01430 /** 01431 * \brief Connect to AP 01432 * \param ssid Up to 32 bytes and is ASCII SSID of the AP 01433 * \param ssid_length Length of the SSID 01434 * \return 01435 * On success, zero is returned. On error, negative is returned. 01436 */ 01437 int32_t connect(const uint8_t *ssid, int32_t ssid_length); 01438 /** 01439 * \brief When auto start is enabled, the device connects to station from the profiles table. 01440 * If several profiles configured the device choose the highest priority profile. 01441 * \param sec_type WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2 01442 * \param ssid SSID up to 32 bytes 01443 * \param ssid_length SSID length 01444 * \param b_ssid bssid 6 bytes 01445 * \param priority Profile priority. Lowest priority:0. 01446 * \param pairwise_cipher_or_tx_key_len Key length for WEP security 01447 * \param group_cipher_tx_key_index Key index 01448 * \param key_mgmt KEY management 01449 * \param pf_or_key Security key 01450 * \param pass_phrase_length Security key length for WPA\WPA2 01451 * \return 01452 * On success, zero is returned. On error, -1 is returned 01453 */ 01454 int32_t add_profile(uint32_t sec_type, uint8_t *ssid, uint32_t ssid_length, uint8_t *b_ssid, uint32_t priority, 01455 uint32_t pairwise_cipher_or_tx_key_len, uint32_t group_cipher_tx_key_index, uint32_t key_mgmt, 01456 uint8_t* pf_or_key, uint32_t pass_phrase_length); 01457 #endif 01458 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG 01459 /** 01460 * \brief Process the acquired data and store it as a profile. 01461 * \param none 01462 * \return 01463 * On success, zero is returned. On error, -1 is returned. 01464 */ 01465 int32_t smart_config_process(void); 01466 #endif 01467 /** 01468 * \brief Disconnect connection from AP. 01469 * \param none 01470 * \return 01471 * 0 if disconnected done, other CC3000 already disconnected. 01472 */ 01473 int32_t disconnect(); 01474 /** 01475 * \brief When auto is enabled, the device tries to connect according the following policy: 01476 * 1) If fast connect is enabled and last connection is valid, the device will try to 01477 * connect to it without the scanning procedure (fast). The last connection will be 01478 * marked as invalid, due to adding/removing profile. 01479 * 2) If profile exists, the device will try to connect it (Up to seven profiles). 01480 * 3) If fast and profiles are not found, and open mode is enabled, the device 01481 * will try to connect to any AP. 01482 * Note that the policy settings are stored in the CC3000 NVMEM. 01483 * \param should_connect_to_open_ap Enable(1), disable(0) connect to any available AP. 01484 * \param use_fast_connect Enable(1), disable(0). if enabled, tries to 01485 * connect to the last connected AP. 01486 * \param use_profiles Enable(1), disable(0) auto connect after reset. 01487 * and periodically reconnect if needed. 01488 * \return 01489 * On success, zero is returned. On error, -1 is returned 01490 */ 01491 int32_t ioctl_set_connection_policy(uint32_t should_connect_to_open_ap, uint32_t use_fast_connect, uint32_t use_profiles); 01492 /** 01493 * \brief Delete WLAN profile 01494 * \param index Number of profile to delete 01495 * \return 01496 * On success, zero is returned. On error, -1 is returned 01497 */ 01498 int32_t ioctl_del_profile(uint32_t index); 01499 /** 01500 * \brief Mask event according to bit mask. In case that event is 01501 * masked (1), the device will not send the masked event to host. 01502 * \param mask event mask 01503 * \return 01504 * On success, zero is returned. On error, -1 is returned 01505 */ 01506 int32_t set_event_mask(uint32_t mask); 01507 /** 01508 * \brief Start to acquire device profile. The device acquire its own 01509 * profile, if profile message is found. 01510 * \param encrypted_flag Indicates whether the information is encrypted 01511 * \return 01512 * On success, zero is returned. On error, -1 is returned. 01513 */ 01514 int32_t smart_config_start(uint32_t encrypted_flag); 01515 /** 01516 * \brief Stop the acquire profile procedure. 01517 * \param none 01518 * \return 01519 * On success, zero is returned. On error, -1 is returned 01520 */ 01521 int32_t smart_config_stop(void); 01522 /** 01523 * \brief Configure station ssid prefix. 01524 * \param new_prefix 3 bytes identify the SSID prefix for the Smart Config. 01525 * \return 01526 * On success, zero is returned. On error, -1 is returned. 01527 */ 01528 int32_t smart_config_set_prefix(uint8_t *new_prefix); 01529 private: 01530 cc3000_simple_link &_simple_link; 01531 cc3000_event &_event; 01532 cc3000_spi &_spi; 01533 cc3000_hci &_hci; 01534 }; 01535 01536 /** The main object of cc3000 implementation 01537 */ 01538 class cc3000 { 01539 public: 01540 /** status structure */ 01541 typedef struct { 01542 uint8_t socket; 01543 bool dhcp; 01544 bool connected; 01545 bool smart_config_complete; 01546 bool stop_smart_config; 01547 bool dhcp_configured; 01548 bool ok_to_shut_down; 01549 bool enabled; 01550 } tStatus; 01551 /** 01552 * \brief Ctor. 01553 * \param cc3000_irq IRQ pin 01554 * \param cc3000_en Enable pin 01555 * \param cc3000_cs Chip select pin 01556 * \param cc3000_spi SPI interface 01557 */ 01558 cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi); 01559 /** 01560 * \brief Dtor. 01561 */ 01562 ~cc3000(); 01563 /** 01564 * \brief Initiate cc3000. It starts the wlan communication. 01565 * \param patch Patch 01566 */ 01567 void start(uint8_t patch); 01568 /** 01569 * \brief Stops the wlan communication. 01570 */ 01571 void stop(); 01572 /** 01573 * \brief Restarts the wlan communication. 01574 */ 01575 void restart(uint8_t patch); 01576 /** 01577 * \brief Callback which is called from the event class. This updates status of cc3000. 01578 * \param event_type Type of the event 01579 * \param data Pointer to data 01580 * \param length Length of data 01581 * \return none 01582 */ 01583 void usync_callback(int32_t event_type, uint8_t *data, uint8_t length); 01584 /** 01585 * \brief Start connection to SSID (open/secured) non-blocking 01586 * \param ssid SSID name 01587 * \param key Security key (if key = 0, open connection) 01588 * \param security_mode Security mode 01589 * \return true if connection was established, false otherwise. 01590 */ 01591 bool connect_non_blocking(const uint8_t *ssid, const uint8_t *key, int32_t security_mode); 01592 /** 01593 * \brief Connect to SSID (open/secured) with timeout (10s). 01594 * \param ssid SSID name 01595 * \param key Security key (if key = 0, open connection) 01596 * \param security_mode Security mode 01597 * \return true if connection was established, false otherwise. 01598 */ 01599 bool connect_to_AP(const uint8_t *ssid, const uint8_t *key, int32_t security_mode); 01600 /** 01601 * \brief Connect to SSID which is secured 01602 * \param ssid SSID name 01603 * \param key Security key 01604 * \param security_mode Security mode 01605 * \return true if connection was established, false otherwise. 01606 */ 01607 bool connect_secure(const uint8_t *ssid, const uint8_t *key, int32_t security_mode); 01608 /** 01609 * \brief Connect to SSID which is open (no security) 01610 * \param ssid SSID name 01611 * \return true if connection was established, false otherwise. 01612 */ 01613 bool connect_open(const uint8_t *ssid); 01614 /** 01615 * \brief Status of the cc3000 module. 01616 * \return true if it's enabled, false otherwise. 01617 */ 01618 bool is_enabled(); 01619 /** 01620 * \brief Status of the cc3000 connection. 01621 * \return true if it's connected, false otherwise. 01622 */ 01623 bool is_connected(); 01624 /** 01625 * \brief Status of DHCP. 01626 * \param none 01627 * \return true if DCHP is configured, false otherwise. 01628 */ 01629 bool is_dhcp_configured(); 01630 /** 01631 * \brief Status of smart confing completation. 01632 * \param none 01633 * \return smart config was set, false otherwise. 01634 */ 01635 bool is_smart_confing_completed(); 01636 /** 01637 * \brief Return the cc3000's mac address. 01638 * \param address Retreived mac address. 01639 * \return 01640 */ 01641 uint8_t get_mac_address(uint8_t address[6]); 01642 /** 01643 * \brief Set the cc3000's mac address. 01644 * \param address Mac address to be set. 01645 * \return 01646 */ 01647 uint8_t set_mac_address(uint8_t address[6]); 01648 /** 01649 * \brief Get user file info. 01650 * \param info_file Pointer where info will be stored. 01651 * \param size Available size. 01652 * \return none 01653 */ 01654 void get_user_file_info(uint8_t *info_file, size_t size); 01655 /** 01656 * \brief Set user filo info. 01657 * \param info_file Pointer to user's info. 01658 * \return none 01659 */ 01660 void set_user_file_info(uint8_t *info_file, size_t size); 01661 /** 01662 * \brief Start smart config. 01663 * \param smart_config_key Pointer to smart config key. 01664 * \return none 01665 */ 01666 void start_smart_config(const uint8_t *smart_config_key); /* TODO enable AES ? */ 01667 #ifndef CC3000_TINY_DRIVER 01668 /** 01669 * \brief Return ip configuration. 01670 * \param ip_config Pointer to ipconfig data. 01671 * \return true if it's connected and info was retrieved, false otherwise. 01672 */ 01673 bool get_ip_config(tNetappIpconfigRetArgs *ip_config); 01674 #endif 01675 /** 01676 * \brief Delete all stored profiles. 01677 * \param none 01678 * \return none 01679 */ 01680 void delete_profiles(void); 01681 /** 01682 * \brief Ping an ip address. 01683 * \param ip Destination IP address 01684 * \param attempts Number of attempts 01685 * \param timeout Time to wait for a response,in milliseconds. 01686 * \param size Send buffer size which may be up to 1400 bytes 01687 */ 01688 uint32_t ping(uint32_t ip, uint8_t attempts, uint16_t timeout, uint8_t size); 01689 /** 01690 * \brief Returns cc3000 instance. Used in Socket interface. 01691 * \param none 01692 * \return Pointer to cc3000 object 01693 */ 01694 static cc3000* get_instance() { 01695 return _inst; 01696 } 01697 #if (CC3000_ETH_COMPAT == 1) 01698 /** 01699 * \brief Ctor for EthernetInterface 01700 * \param cc3000_irq IRQ pin 01701 * \param cc3000_en Enable pin 01702 * \param cc3000_cs Chip select pin 01703 * \param cc3000_spi SPI interface 01704 * \param ssid SSID 01705 * \param phrase Password 01706 * \param sec Security of the AP 01707 * \param smart_config Smart config selection 01708 */ 01709 cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, const char *ssid, const char *phrase, Security sec, bool smart_config); 01710 /** 01711 * \brief Disconnect wlan device. 01712 * \param none 01713 * \return 0 if successful, -1 otherwise. 01714 */ 01715 int disconnect(); 01716 /** 01717 * \brief Initialize the interface with DHCP. 01718 * \param none 01719 * \return none 01720 */ 01721 void init(); 01722 /** 01723 * \brief Initialize the interface with a static IP address. 01724 * \param ip the IP address to use. 01725 * \param mask the IP address mask 01726 * \param gateway the gateway to use 01727 * \return none 01728 */ 01729 void init(const char *ip, const char *mask, const char *gateway); 01730 /** 01731 * \brief Connect Bring the interface up. 01732 * \param timeout_ms timeout in ms 01733 * \return 0 if successful, -1 otherwise. 01734 */ 01735 int connect(unsigned int timeout_ms = 20000); 01736 /** 01737 * \brief Get the MAC address of your Ethernet interface. 01738 * \param none 01739 * \return 01740 * Pointer to a string containing the MAC address. 01741 */ 01742 char* getMACAddress(); 01743 /** 01744 * \brief Get the IP address of your Ethernet interface. 01745 * \param none 01746 * \return 01747 * Pointer to a string containing the IP address. 01748 */ 01749 char* getIPAddress(); 01750 01751 /** 01752 * \brief Return the CC3000's firmware version. 01753 * \param firmware Retreived firmware version. 01754 * \return 0 if successful, -1 otherwise. 01755 */ 01756 uint8_t read_sp_version(uint8_t firmware[2]); 01757 01758 /** 01759 * \brief routine to update firmware of CC3000 01760 * \param 01761 * \return 0 if successful, -1 otherwise. 01762 */ 01763 uint8_t write_patch(uint32_t file_id, uint32_t length, const uint8_t *data); 01764 01765 /** 01766 * \brief Get the Gateway address of your Ethernet interface 01767 * \param none 01768 * \return 01769 * Pointer to a string containing the Gateway address 01770 */ 01771 char* getGateway(); 01772 /** 01773 * \brief Get the Network mask of your Ethernet interface 01774 * \param none 01775 * \return 01776 * Pointer to a string containing the Network mask 01777 */ 01778 char* getNetworkMask(); 01779 #endif 01780 public: 01781 cc3000_simple_link _simple_link; 01782 cc3000_event _event; 01783 cc3000_socket _socket; 01784 cc3000_spi _spi; 01785 cc3000_hci _hci; 01786 cc3000_nvmem _nvmem; 01787 cc3000_netapp _netapp; 01788 cc3000_wlan _wlan; 01789 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG 01790 cc3000_security _security; 01791 #endif 01792 protected: 01793 static cc3000 *_inst; 01794 private: 01795 tStatus _status; 01796 netapp_pingreport_args_t _ping_report; 01797 bool _closed_sockets[MAX_SOCKETS]; 01798 #if (CC3000_ETH_COMPAT == 1) 01799 uint8_t _phrase[30]; 01800 uint8_t _ssid[30]; 01801 Security _sec; 01802 bool _smart_config; 01803 #endif 01804 }; 01805 01806 /** 01807 * Copy 32 bit to stream while converting to little endian format. 01808 * @param p pointer to the new stream 01809 * @param u32 pointer to the 32 bit 01810 * @return pointer to the new stream 01811 */ 01812 uint8_t *UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32); 01813 01814 /** 01815 * Copy 16 bit to stream while converting to little endian format. 01816 * @param p pointer to the new stream 01817 * @param u32 pointer to the 16 bit 01818 * @return pointer to the new stream 01819 */ 01820 uint8_t *UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16); 01821 01822 /** 01823 * Copy received stream to 16 bit in little endian format. 01824 * @param p pointer to the stream 01825 * @param offset offset in the stream 01826 * @return pointer to the new 16 bit 01827 */ 01828 uint16_t STREAM_TO_UINT16_f(uint8_t* p, uint16_t offset); 01829 01830 /** 01831 * Copy received stream to 32 bit in little endian format. 01832 * @param p pointer to the stream 01833 * @param offset offset in the stream 01834 * @return pointer to the new 32 bit 01835 */ 01836 uint32_t STREAM_TO_UINT32_f(uint8_t* p, uint16_t offset); 01837 01838 } /* end of mbed_cc3000 namespace */ 01839 01840 01841 #endif
Generated on Tue Jul 12 2022 23:07:36 by 1.7.2