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