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