version_2.0
Dependents: cc3000_ping_demo_try_2
Fork of cc3000_hostdriver_mbedsocket by
cc3000.h@19:9fdf8b4e41bf, 2013-10-03 (annotated)
- Committer:
- Kojto
- Date:
- Thu Oct 03 09:49:03 2013 +0200
- Revision:
- 19:9fdf8b4e41bf
- Parent:
- 17:14b6a3a2b622
- Child:
- 20:30b6ed7bf8fd
return values from get_mac/set_mac
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 0:615c697c33b0 | 1 | /***************************************************************************** |
Kojto | 0:615c697c33b0 | 2 | * |
Kojto | 0:615c697c33b0 | 3 | * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to |
Kojto | 0:615c697c33b0 | 4 | * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and |
Kojto | 0:615c697c33b0 | 5 | * provided help. |
Kojto | 0:615c697c33b0 | 6 | * |
Kojto | 0:615c697c33b0 | 7 | * This version of "host driver" uses CC3000 Host Driver Implementation. Thus |
Kojto | 0:615c697c33b0 | 8 | * read the following copyright: |
Kojto | 0:615c697c33b0 | 9 | * |
Kojto | 0:615c697c33b0 | 10 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
Kojto | 0:615c697c33b0 | 11 | * |
Kojto | 0:615c697c33b0 | 12 | * Redistribution and use in source and binary forms, with or without |
Kojto | 0:615c697c33b0 | 13 | * modification, are permitted provided that the following conditions |
Kojto | 0:615c697c33b0 | 14 | * are met: |
Kojto | 0:615c697c33b0 | 15 | * |
Kojto | 0:615c697c33b0 | 16 | * Redistributions of source code must retain the above copyright |
Kojto | 0:615c697c33b0 | 17 | * notice, this list of conditions and the following disclaimer. |
Kojto | 0:615c697c33b0 | 18 | * |
Kojto | 0:615c697c33b0 | 19 | * Redistributions in binary form must reproduce the above copyright |
Kojto | 0:615c697c33b0 | 20 | * notice, this list of conditions and the following disclaimer in the |
Kojto | 0:615c697c33b0 | 21 | * documentation and/or other materials provided with the |
Kojto | 0:615c697c33b0 | 22 | * distribution. |
Kojto | 0:615c697c33b0 | 23 | * |
Kojto | 0:615c697c33b0 | 24 | * Neither the name of Texas Instruments Incorporated nor the names of |
Kojto | 0:615c697c33b0 | 25 | * its contributors may be used to endorse or promote products derived |
Kojto | 0:615c697c33b0 | 26 | * from this software without specific prior written permission. |
Kojto | 0:615c697c33b0 | 27 | * |
Kojto | 0:615c697c33b0 | 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
Kojto | 0:615c697c33b0 | 29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
Kojto | 0:615c697c33b0 | 30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
Kojto | 0:615c697c33b0 | 31 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
Kojto | 0:615c697c33b0 | 32 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
Kojto | 0:615c697c33b0 | 33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
Kojto | 0:615c697c33b0 | 34 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
Kojto | 0:615c697c33b0 | 35 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
Kojto | 0:615c697c33b0 | 36 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Kojto | 0:615c697c33b0 | 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Kojto | 0:615c697c33b0 | 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 0:615c697c33b0 | 39 | * |
Kojto | 0:615c697c33b0 | 40 | *****************************************************************************/ |
Kojto | 0:615c697c33b0 | 41 | #ifndef CC3000_H |
Kojto | 0:615c697c33b0 | 42 | #define CC3000_H |
Kojto | 0:615c697c33b0 | 43 | |
Kojto | 0:615c697c33b0 | 44 | #include "mbed.h" |
Kojto | 0:615c697c33b0 | 45 | #include "cc3000_common.h" |
Kojto | 0:615c697c33b0 | 46 | #include "cc3000_spi.h" |
Kojto | 0:615c697c33b0 | 47 | #include "cc3000_simplelink.h" |
Kojto | 0:615c697c33b0 | 48 | #include "cc3000_netapp.h" |
Kojto | 0:615c697c33b0 | 49 | #include "cc3000_nvmem.h" |
Kojto | 0:615c697c33b0 | 50 | #include "cc3000_socket.h" |
Kojto | 0:615c697c33b0 | 51 | |
Kojto | 0:615c697c33b0 | 52 | #define MAX_SOCKETS 4 |
Kojto | 0:615c697c33b0 | 53 | |
Kojto | 0:615c697c33b0 | 54 | /** Enable debug messages |
Kojto | 0:615c697c33b0 | 55 | */ |
Kojto | 0:615c697c33b0 | 56 | #define CC3000_DEBUG 1 |
Kojto | 0:615c697c33b0 | 57 | |
SolderSplashLabs | 13:5e36c267e62f | 58 | #if CC3000_DEBUG == 1 |
SolderSplashLabs | 14:28c8bbbea025 | 59 | |
SolderSplashLabs | 14:28c8bbbea025 | 60 | // DBG_SOCKET, mbed socket specific debug messages |
Kojto | 17:14b6a3a2b622 | 61 | #define DBG_SOCKET(x, ...) std::printf("[CC3000 : SOCKET] "x"\r\n", ##__VA_ARGS__); |
Kojto | 17:14b6a3a2b622 | 62 | |
SolderSplashLabs | 14:28c8bbbea025 | 63 | // DBG_HCI, prints a message for every recieved HCI event, quite a lot of debug |
Kojto | 17:14b6a3a2b622 | 64 | #define DBG_HCI(x, ...) std::printf("[CC3000 : HCI] "x"\r\n", ##__VA_ARGS__); |
Kojto | 17:14b6a3a2b622 | 65 | |
SolderSplashLabs | 14:28c8bbbea025 | 66 | // DBG_CC, General cc3000 debug messages |
Kojto | 17:14b6a3a2b622 | 67 | #define DBG_CC(x, ...) std::printf("[CC3000] "x"\r\n", ##__VA_ARGS__); |
SolderSplashLabs | 13:5e36c267e62f | 68 | #else |
Kojto | 17:14b6a3a2b622 | 69 | #define DBG_SOCKET(x, ...) |
SolderSplashLabs | 13:5e36c267e62f | 70 | #define DBG_HCI(x, ...) |
SolderSplashLabs | 15:aae737ca3dd2 | 71 | #define DBG_CC(x, ...) |
SolderSplashLabs | 13:5e36c267e62f | 72 | #endif |
SolderSplashLabs | 13:5e36c267e62f | 73 | |
Kojto | 0:615c697c33b0 | 74 | namespace mbed_cc3000 { |
Kojto | 0:615c697c33b0 | 75 | |
Kojto | 0:615c697c33b0 | 76 | /** User info structure |
Kojto | 0:615c697c33b0 | 77 | */ |
Kojto | 0:615c697c33b0 | 78 | typedef struct { |
Kojto | 0:615c697c33b0 | 79 | uint8_t FTC; // First time config performed |
Kojto | 0:615c697c33b0 | 80 | uint8_t PP_version[2]; // Patch Programmer version |
Kojto | 0:615c697c33b0 | 81 | uint8_t SERV_PACK[2]; // Service Pack Version |
Kojto | 0:615c697c33b0 | 82 | uint8_t DRV_VER[3]; // Driver Version |
Kojto | 0:615c697c33b0 | 83 | uint8_t FW_VER[3]; // Firmware Version |
Kojto | 0:615c697c33b0 | 84 | uint8_t validCIK; // CIK[] is valid (Client Interface Key) |
Kojto | 0:615c697c33b0 | 85 | uint8_t CIK[40]; |
Kojto | 0:615c697c33b0 | 86 | } tUserFS; |
Kojto | 0:615c697c33b0 | 87 | |
Kojto | 0:615c697c33b0 | 88 | /** Function pointers which are not yet implemented |
Kojto | 0:615c697c33b0 | 89 | */ |
Kojto | 0:615c697c33b0 | 90 | enum FunctionNumber { |
Kojto | 0:615c697c33b0 | 91 | FW_PATCHES = 0, |
Kojto | 0:615c697c33b0 | 92 | DRIVER_PATCHES = 1, |
Kojto | 0:615c697c33b0 | 93 | BOOTLOADER_PATCHES = 2, |
Kojto | 0:615c697c33b0 | 94 | }; |
Kojto | 0:615c697c33b0 | 95 | |
Kojto | 0:615c697c33b0 | 96 | /** CC3000 Simple Link class which contains status of cc3000. |
Kojto | 0:615c697c33b0 | 97 | */ |
Kojto | 0:615c697c33b0 | 98 | class cc3000_simple_link { |
Kojto | 0:615c697c33b0 | 99 | public: |
Kojto | 0:615c697c33b0 | 100 | /** ctor - sets magic number in the buffers (overflow mark). |
Kojto | 0:615c697c33b0 | 101 | */ |
Kojto | 0:615c697c33b0 | 102 | cc3000_simple_link(); |
Kojto | 0:615c697c33b0 | 103 | /** dtor |
Kojto | 0:615c697c33b0 | 104 | */ |
Kojto | 0:615c697c33b0 | 105 | ~cc3000_simple_link(); |
Kojto | 0:615c697c33b0 | 106 | /** Returns data received flag. |
Kojto | 0:615c697c33b0 | 107 | * \return |
Kojto | 0:615c697c33b0 | 108 | * if data have been received. |
Kojto | 0:615c697c33b0 | 109 | */ |
Kojto | 0:615c697c33b0 | 110 | uint8_t get_data_received_flag(); |
Kojto | 0:615c697c33b0 | 111 | /** Set data received flag. |
Kojto | 0:615c697c33b0 | 112 | * \param value The value to be set. |
Kojto | 0:615c697c33b0 | 113 | */ |
Kojto | 0:615c697c33b0 | 114 | void set_data_received_flag(uint8_t value); |
Kojto | 0:615c697c33b0 | 115 | /** Returns if tx was completed. |
Kojto | 0:615c697c33b0 | 116 | * \return |
Kojto | 0:615c697c33b0 | 117 | * true if tx was completed, |
Kojto | 0:615c697c33b0 | 118 | * false otherwise. |
Kojto | 0:615c697c33b0 | 119 | */ |
Kojto | 0:615c697c33b0 | 120 | bool get_tx_complete_signal(); |
Kojto | 0:615c697c33b0 | 121 | /** |
Kojto | 0:615c697c33b0 | 122 | */ |
Kojto | 0:615c697c33b0 | 123 | void set_tx_complete_signal(bool value); |
Kojto | 0:615c697c33b0 | 124 | /** |
Kojto | 0:615c697c33b0 | 125 | */ |
Kojto | 0:615c697c33b0 | 126 | uint8_t *get_received_buffer(); |
Kojto | 0:615c697c33b0 | 127 | /** |
Kojto | 0:615c697c33b0 | 128 | */ |
Kojto | 0:615c697c33b0 | 129 | void set_received_buffer(uint8_t value); |
Kojto | 0:615c697c33b0 | 130 | /** |
Kojto | 0:615c697c33b0 | 131 | */ |
Kojto | 0:615c697c33b0 | 132 | uint8_t *get_transmit_buffer(); |
Kojto | 0:615c697c33b0 | 133 | /** |
Kojto | 0:615c697c33b0 | 134 | */ |
Kojto | 0:615c697c33b0 | 135 | void set_transmit_buffer(uint8_t value); |
Kojto | 0:615c697c33b0 | 136 | /** |
Kojto | 0:615c697c33b0 | 137 | */ |
Kojto | 0:615c697c33b0 | 138 | uint16_t get_number_free_buffers(); |
Kojto | 0:615c697c33b0 | 139 | /** |
Kojto | 0:615c697c33b0 | 140 | */ |
Kojto | 0:615c697c33b0 | 141 | void set_number_free_buffers(uint16_t value); |
Kojto | 0:615c697c33b0 | 142 | /** |
Kojto | 0:615c697c33b0 | 143 | */ |
Kojto | 0:615c697c33b0 | 144 | uint16_t get_buffer_length(); |
Kojto | 0:615c697c33b0 | 145 | /** |
Kojto | 0:615c697c33b0 | 146 | */ |
Kojto | 0:615c697c33b0 | 147 | void set_buffer_length(uint16_t value); |
Kojto | 0:615c697c33b0 | 148 | /** |
Kojto | 0:615c697c33b0 | 149 | */ |
Kojto | 0:615c697c33b0 | 150 | uint16_t get_pending_data(); |
Kojto | 0:615c697c33b0 | 151 | /** |
Kojto | 0:615c697c33b0 | 152 | */ |
Kojto | 0:615c697c33b0 | 153 | void set_pending_data(uint16_t value); |
Kojto | 0:615c697c33b0 | 154 | /** |
Kojto | 0:615c697c33b0 | 155 | */ |
Kojto | 0:615c697c33b0 | 156 | uint16_t get_op_code(); |
Kojto | 0:615c697c33b0 | 157 | /** |
Kojto | 0:615c697c33b0 | 158 | */ |
Kojto | 0:615c697c33b0 | 159 | void set_op_code(uint16_t code); |
Kojto | 0:615c697c33b0 | 160 | /** |
Kojto | 0:615c697c33b0 | 161 | */ |
Kojto | 0:615c697c33b0 | 162 | uint16_t get_released_packets(); |
Kojto | 0:615c697c33b0 | 163 | /** |
Kojto | 0:615c697c33b0 | 164 | */ |
Kojto | 0:615c697c33b0 | 165 | void set_number_of_released_packets(uint16_t value); |
Kojto | 0:615c697c33b0 | 166 | /** |
Kojto | 0:615c697c33b0 | 167 | */ |
Kojto | 0:615c697c33b0 | 168 | uint16_t get_sent_packets(); |
Kojto | 0:615c697c33b0 | 169 | /** |
Kojto | 0:615c697c33b0 | 170 | */ |
Kojto | 0:615c697c33b0 | 171 | void set_sent_packets(uint16_t value); |
Kojto | 0:615c697c33b0 | 172 | |
Kojto | 0:615c697c33b0 | 173 | int32_t get_transmit_error(); |
Kojto | 0:615c697c33b0 | 174 | void set_transmit_error(int32_t value); |
Kojto | 0:615c697c33b0 | 175 | |
Kojto | 0:615c697c33b0 | 176 | uint16_t get_buffer_size(void); |
Kojto | 0:615c697c33b0 | 177 | void set_buffer_size(uint16_t value); |
Kojto | 0:615c697c33b0 | 178 | |
Kojto | 0:615c697c33b0 | 179 | void *get_func_pointer(FunctionNumber function); |
Kojto | 0:615c697c33b0 | 180 | |
Kojto | 0:615c697c33b0 | 181 | uint8_t *get_received_data(void); |
Kojto | 0:615c697c33b0 | 182 | void set_received_data(uint8_t *pointer); |
Kojto | 0:615c697c33b0 | 183 | |
Kojto | 0:615c697c33b0 | 184 | private: |
Kojto | 0:615c697c33b0 | 185 | uint8_t _data_received_flag; |
Kojto | 0:615c697c33b0 | 186 | bool _tx_complete_signal; |
Kojto | 0:615c697c33b0 | 187 | uint16_t _rx_event_opcode; |
Kojto | 0:615c697c33b0 | 188 | uint16_t _free_buffers; |
Kojto | 0:615c697c33b0 | 189 | uint16_t _buffer_length; |
Kojto | 0:615c697c33b0 | 190 | uint16_t _buffer_size; |
Kojto | 0:615c697c33b0 | 191 | uint16_t _rx_data_pending; |
Kojto | 0:615c697c33b0 | 192 | uint16_t _sent_packets; |
Kojto | 0:615c697c33b0 | 193 | uint16_t _released_packets; |
Kojto | 0:615c697c33b0 | 194 | int32_t _transmit_data_error; |
Kojto | 0:615c697c33b0 | 195 | uint8_t *_received_data; |
Kojto | 0:615c697c33b0 | 196 | uint8_t _rx_buffer[CC3000_RX_BUFFER_SIZE]; |
Kojto | 0:615c697c33b0 | 197 | uint8_t _tx_buffer[CC3000_TX_BUFFER_SIZE]; |
Kojto | 0:615c697c33b0 | 198 | private: |
Kojto | 0:615c697c33b0 | 199 | int8_t *(* _fFWPatches)(uint32_t *length); |
Kojto | 0:615c697c33b0 | 200 | int8_t *(* _fDriverPatches)(uint32_t *length); |
Kojto | 0:615c697c33b0 | 201 | int8_t *(* _fBootLoaderPatches)(uint32_t *length); |
Kojto | 0:615c697c33b0 | 202 | }; |
Kojto | 0:615c697c33b0 | 203 | |
Kojto | 0:615c697c33b0 | 204 | /** Forward declaration classes |
Kojto | 0:615c697c33b0 | 205 | */ |
Kojto | 0:615c697c33b0 | 206 | class cc3000_hci; |
Kojto | 0:615c697c33b0 | 207 | class cc3000_nvmem; |
Kojto | 0:615c697c33b0 | 208 | class cc3000_spi; |
Kojto | 0:615c697c33b0 | 209 | class cc3000; |
Kojto | 0:615c697c33b0 | 210 | |
Kojto | 0:615c697c33b0 | 211 | /** |
Kojto | 0:615c697c33b0 | 212 | */ |
Kojto | 0:615c697c33b0 | 213 | class cc3000_event { |
Kojto | 0:615c697c33b0 | 214 | public: |
Kojto | 0:615c697c33b0 | 215 | cc3000_event(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_spi &spi, cc3000 &cc3000); |
Kojto | 0:615c697c33b0 | 216 | ~cc3000_event(); |
Kojto | 0:615c697c33b0 | 217 | |
Kojto | 0:615c697c33b0 | 218 | void hci_unsol_handle_patch_request(uint8_t *event_hdr); |
Kojto | 0:615c697c33b0 | 219 | uint8_t *hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen); |
Kojto | 0:615c697c33b0 | 220 | int32_t hci_unsol_event_handler(uint8_t *event_hdr); |
Kojto | 0:615c697c33b0 | 221 | int32_t hci_unsolicited_event_handler(void); |
Kojto | 0:615c697c33b0 | 222 | int32_t get_socket_active_status(int32_t sd); |
Kojto | 0:615c697c33b0 | 223 | void set_socket_active_status(int32_t sd, int32_t status); |
Kojto | 0:615c697c33b0 | 224 | int32_t hci_event_unsol_flowcontrol_handler(uint8_t *event); |
Kojto | 0:615c697c33b0 | 225 | void update_socket_active_status(uint8_t *resp_params); |
Kojto | 0:615c697c33b0 | 226 | void simplelink_wait_event(uint16_t op_code, void *ret_param); |
Kojto | 0:615c697c33b0 | 227 | void simplelink_wait_data(uint8_t *buffer, uint8_t *from, uint8_t *fromlen); |
Kojto | 0:615c697c33b0 | 228 | |
Kojto | 0:615c697c33b0 | 229 | void received_handler(uint8_t *buffer); |
Kojto | 0:615c697c33b0 | 230 | private: |
Kojto | 0:615c697c33b0 | 231 | uint32_t socket_active_status; |
Kojto | 0:615c697c33b0 | 232 | cc3000_simple_link &_simple_link; |
Kojto | 0:615c697c33b0 | 233 | cc3000_hci &_hci; |
Kojto | 0:615c697c33b0 | 234 | cc3000_spi &_spi; |
Kojto | 0:615c697c33b0 | 235 | cc3000 &_cc3000; |
Kojto | 0:615c697c33b0 | 236 | }; |
Kojto | 0:615c697c33b0 | 237 | |
Kojto | 0:615c697c33b0 | 238 | class cc3000_netapp { |
Kojto | 0:615c697c33b0 | 239 | public: |
Kojto | 0:615c697c33b0 | 240 | cc3000_netapp(cc3000_simple_link &simple_link, cc3000_nvmem &nvmem, cc3000_hci &hci, cc3000_event &event); |
Kojto | 0:615c697c33b0 | 241 | ~cc3000_netapp(); |
Kojto | 0:615c697c33b0 | 242 | int32_t config_mac_adrress(uint8_t *mac); |
Kojto | 0:615c697c33b0 | 243 | int32_t dhcp(uint32_t *ip, uint32_t *subnet_mask,uint32_t *default_gateway, uint32_t *dns_server); |
Kojto | 0:615c697c33b0 | 244 | #ifndef CC3000_TINY_DRIVER |
Kojto | 0:615c697c33b0 | 245 | void ipconfig(tNetappIpconfigRetArgs *ipconfig); |
Kojto | 0:615c697c33b0 | 246 | int32_t timeout_values(uint32_t *dhcp, uint32_t *arp,uint32_t *keep_alive, uint32_t *inactivity); |
Kojto | 0:615c697c33b0 | 247 | int32_t ping_send(uint32_t *ip, uint32_t ping_attempts, uint32_t ping_size, uint32_t ping_timeout); |
Kojto | 0:615c697c33b0 | 248 | void ping_report(); |
Kojto | 0:615c697c33b0 | 249 | int32_t ping_stop(); |
Kojto | 0:615c697c33b0 | 250 | int32_t arp_flush(); |
Kojto | 0:615c697c33b0 | 251 | #endif |
Kojto | 0:615c697c33b0 | 252 | private: |
Kojto | 0:615c697c33b0 | 253 | cc3000_simple_link &_simple_link; |
Kojto | 0:615c697c33b0 | 254 | cc3000_nvmem &_nvmem; |
Kojto | 0:615c697c33b0 | 255 | cc3000_hci &_hci; |
Kojto | 0:615c697c33b0 | 256 | cc3000_event &_event; |
Kojto | 0:615c697c33b0 | 257 | }; |
Kojto | 0:615c697c33b0 | 258 | |
Kojto | 0:615c697c33b0 | 259 | #ifndef CC3000_UNENCRYPTED_SMART_CONFIG |
Kojto | 0:615c697c33b0 | 260 | class cc3000_security { |
Kojto | 0:615c697c33b0 | 261 | public: |
Kojto | 0:615c697c33b0 | 262 | void expandKey(uint8_t *expanded_key, uint8_t *key); |
Kojto | 0:615c697c33b0 | 263 | uint8_t galois_mul2(uint8_t value); |
Kojto | 0:615c697c33b0 | 264 | void aes_encr(uint8_t *state, uint8_t *expanded_key); |
Kojto | 0:615c697c33b0 | 265 | void aes_decr(uint8_t *state, uint8_t *expanded_key); |
Kojto | 0:615c697c33b0 | 266 | void aes_encrypt(uint8_t *state, uint8_t *key); |
Kojto | 0:615c697c33b0 | 267 | void aes_decrypt(uint8_t *state, uint8_t *key); |
Kojto | 0:615c697c33b0 | 268 | int32_t aes_read_key(uint8_t *key); |
Kojto | 0:615c697c33b0 | 269 | int32_t aes_write_key(uint8_t *key); |
Kojto | 0:615c697c33b0 | 270 | private: |
Kojto | 0:615c697c33b0 | 271 | uint8_t _expanded_key[176]; |
Kojto | 0:615c697c33b0 | 272 | }; |
Kojto | 0:615c697c33b0 | 273 | #endif |
Kojto | 0:615c697c33b0 | 274 | |
Kojto | 0:615c697c33b0 | 275 | class cc3000_socket { |
Kojto | 0:615c697c33b0 | 276 | public: |
Kojto | 0:615c697c33b0 | 277 | cc3000_socket(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_event &event); |
Kojto | 0:615c697c33b0 | 278 | ~cc3000_socket(); |
Kojto | 0:615c697c33b0 | 279 | int32_t socket(int32_t domain, int32_t type, int32_t protocol); |
Kojto | 0:615c697c33b0 | 280 | int32_t accept(int32_t sd, sockaddr *addr, socklen_t *addrlen); |
Kojto | 0:615c697c33b0 | 281 | int32_t bind(int32_t sd, const sockaddr *addr, int32_t addrlen); |
Martin Kojtal |
12:1c2a856c618a | 282 | int32_t HostFlowControlConsumeBuff(int32_t sd); |
Martin Kojtal |
12:1c2a856c618a | 283 | int32_t closesocket(int32_t sd); |
Kojto | 0:615c697c33b0 | 284 | int32_t listen(int32_t sd, int32_t backlog); |
Kojto | 0:615c697c33b0 | 285 | int32_t connect(int32_t sd, const sockaddr *addr, int32_t addrlen); |
Kojto | 0:615c697c33b0 | 286 | int32_t select(int32_t nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout); |
Martin Kojtal |
12:1c2a856c618a | 287 | int32_t getsockopt (int32_t sd, int32_t level, int32_t optname, void *optval, socklen_t *optlen); |
Kojto | 0:615c697c33b0 | 288 | int32_t simple_link_recv(int32_t sd, void *buf, int32_t len, int32_t flags, sockaddr *from, socklen_t *fromlen, int32_t opcode); |
Martin Kojtal |
12:1c2a856c618a | 289 | 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); |
Kojto | 0:615c697c33b0 | 290 | int32_t recv(int32_t sd, void *buf, int32_t len, int32_t flags); |
Kojto | 0:615c697c33b0 | 291 | int32_t recvfrom(int32_t sd, void *buf, int32_t len, int32_t flags, sockaddr *from, socklen_t *fromlen); |
Kojto | 0:615c697c33b0 | 292 | int32_t send(int32_t sd, const void *buf, int32_t len, int32_t flags); |
Kojto | 0:615c697c33b0 | 293 | int32_t sendto(int32_t sd, const void *buf, int32_t len, int32_t flags, const sockaddr *to, socklen_t tolen); |
Kojto | 0:615c697c33b0 | 294 | int32_t mdns_advertiser(uint16_t mdns_enabled, uint8_t * device_service_name, uint16_t device_service_name_length); |
Martin Kojtal |
12:1c2a856c618a | 295 | #ifndef CC3000_TINY_DRIVER |
Martin Kojtal |
12:1c2a856c618a | 296 | int32_t gethostbyname(uint8_t *hostname, uint16_t name_length, uint32_t *out_ip_addr); |
Martin Kojtal |
12:1c2a856c618a | 297 | int32_t setsockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen); |
Martin Kojtal |
12:1c2a856c618a | 298 | #endif |
Kojto | 0:615c697c33b0 | 299 | private: |
Kojto | 0:615c697c33b0 | 300 | cc3000_simple_link &_simple_link; |
Kojto | 0:615c697c33b0 | 301 | cc3000_hci &_hci; |
Kojto | 0:615c697c33b0 | 302 | cc3000_event &_event; |
Kojto | 0:615c697c33b0 | 303 | }; |
Kojto | 0:615c697c33b0 | 304 | |
Kojto | 0:615c697c33b0 | 305 | /** SPI communication class |
Kojto | 0:615c697c33b0 | 306 | */ |
Kojto | 0:615c697c33b0 | 307 | class cc3000_spi { |
Kojto | 0:615c697c33b0 | 308 | public: |
Kojto | 0:615c697c33b0 | 309 | /** ctor |
Kojto | 0:615c697c33b0 | 310 | */ |
Kojto | 0:615c697c33b0 | 311 | cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, IRQn_Type irq_port, cc3000_event &event, cc3000_simple_link &simple_link); |
Kojto | 0:615c697c33b0 | 312 | /** dtor |
Kojto | 0:615c697c33b0 | 313 | */ |
Kojto | 0:615c697c33b0 | 314 | ~cc3000_spi(); |
Kojto | 0:615c697c33b0 | 315 | /** Close SPI - disables IRQ and set received buffer to 0 |
Kojto | 0:615c697c33b0 | 316 | * \param none |
Kojto | 0:615c697c33b0 | 317 | * \return none |
Kojto | 0:615c697c33b0 | 318 | */ |
Kojto | 0:615c697c33b0 | 319 | void close(); |
Kojto | 0:615c697c33b0 | 320 | /** |
Kojto | 0:615c697c33b0 | 321 | * \param none |
Kojto | 0:615c697c33b0 | 322 | * \return none |
Kojto | 0:615c697c33b0 | 323 | */ |
Kojto | 0:615c697c33b0 | 324 | void open(); |
Kojto | 0:615c697c33b0 | 325 | /** |
Kojto | 0:615c697c33b0 | 326 | * \param buffer |
Kojto | 0:615c697c33b0 | 327 | * \param length |
Kojto | 0:615c697c33b0 | 328 | * \return none |
Kojto | 0:615c697c33b0 | 329 | */ |
Kojto | 0:615c697c33b0 | 330 | uint32_t first_write(uint8_t *buffer, uint16_t length); |
Kojto | 0:615c697c33b0 | 331 | /** |
Kojto | 0:615c697c33b0 | 332 | */ |
Kojto | 0:615c697c33b0 | 333 | uint32_t write(uint8_t *buffer, uint16_t length); |
Kojto | 0:615c697c33b0 | 334 | /** |
Kojto | 0:615c697c33b0 | 335 | */ |
Kojto | 0:615c697c33b0 | 336 | void write_synchronous(uint8_t *data, uint16_t size); |
Kojto | 0:615c697c33b0 | 337 | /** |
Kojto | 0:615c697c33b0 | 338 | */ |
Kojto | 0:615c697c33b0 | 339 | void read_synchronous(uint8_t *data, uint16_t size); |
Kojto | 0:615c697c33b0 | 340 | /** |
Kojto | 0:615c697c33b0 | 341 | */ |
Kojto | 0:615c697c33b0 | 342 | uint32_t read_data_cont(); |
Kojto | 0:615c697c33b0 | 343 | /** |
Kojto | 0:615c697c33b0 | 344 | */ |
Kojto | 0:615c697c33b0 | 345 | void wlan_irq_enable(); |
Kojto | 0:615c697c33b0 | 346 | /** |
Kojto | 0:615c697c33b0 | 347 | */ |
Kojto | 0:615c697c33b0 | 348 | void wlan_irq_disable(); |
Kojto | 0:615c697c33b0 | 349 | /** |
Kojto | 0:615c697c33b0 | 350 | */ |
Kojto | 0:615c697c33b0 | 351 | void wlan_irq_set(uint8_t value); |
Kojto | 0:615c697c33b0 | 352 | /** |
Kojto | 0:615c697c33b0 | 353 | */ |
Kojto | 0:615c697c33b0 | 354 | uint32_t wlan_irq_read(); |
Kojto | 0:615c697c33b0 | 355 | /** |
Kojto | 0:615c697c33b0 | 356 | */ |
Kojto | 0:615c697c33b0 | 357 | void WLAN_IRQHandler(); |
Kojto | 0:615c697c33b0 | 358 | /** |
Kojto | 0:615c697c33b0 | 359 | */ |
Kojto | 0:615c697c33b0 | 360 | void write_wlan_en(uint8_t value); |
Kojto | 0:615c697c33b0 | 361 | private: |
Kojto | 0:615c697c33b0 | 362 | tSpiInfo _spi_info; |
Kojto | 0:615c697c33b0 | 363 | InterruptIn _wlan_irq; |
Kojto | 0:615c697c33b0 | 364 | DigitalOut _wlan_en; |
Kojto | 0:615c697c33b0 | 365 | DigitalOut _wlan_cs; |
Kojto | 0:615c697c33b0 | 366 | SPI _wlan_spi; |
Kojto | 0:615c697c33b0 | 367 | IRQn_Type _irq_port; |
Kojto | 0:615c697c33b0 | 368 | pFunctionPointer_t _function_pointer; |
Kojto | 0:615c697c33b0 | 369 | cc3000_event &_event; |
Kojto | 0:615c697c33b0 | 370 | cc3000_simple_link &_simple_link; |
Kojto | 0:615c697c33b0 | 371 | }; |
Kojto | 0:615c697c33b0 | 372 | |
Kojto | 0:615c697c33b0 | 373 | class cc3000_hci { |
Kojto | 0:615c697c33b0 | 374 | public: |
Kojto | 0:615c697c33b0 | 375 | cc3000_hci(cc3000_spi &spi); |
Kojto | 0:615c697c33b0 | 376 | ~cc3000_hci(); |
Kojto | 0:615c697c33b0 | 377 | uint16_t command_send(uint16_t op_code, uint8_t *buffer, uint8_t length); |
Kojto | 0:615c697c33b0 | 378 | uint32_t data_send(uint8_t op_code, uint8_t *args, uint16_t arg_length, |
Kojto | 0:615c697c33b0 | 379 | uint16_t data_length, const uint8_t *tail, uint16_t tail_length); |
Kojto | 0:615c697c33b0 | 380 | void data_command_send(uint16_t op_code, uint8_t *buffer, uint8_t arg_length, |
Kojto | 0:615c697c33b0 | 381 | uint16_t data_length); |
Kojto | 0:615c697c33b0 | 382 | void patch_send(uint8_t op_code, uint8_t *buffer, uint8_t *patch, uint16_t data_length); |
Kojto | 0:615c697c33b0 | 383 | private: |
Kojto | 0:615c697c33b0 | 384 | cc3000_spi &_spi; |
Kojto | 0:615c697c33b0 | 385 | }; |
Kojto | 0:615c697c33b0 | 386 | |
Kojto | 0:615c697c33b0 | 387 | class cc3000_nvmem { |
Kojto | 0:615c697c33b0 | 388 | public: |
Kojto | 0:615c697c33b0 | 389 | cc3000_nvmem(cc3000_hci &hci, cc3000_event &_event,cc3000_simple_link &simple_link); |
Kojto | 0:615c697c33b0 | 390 | ~cc3000_nvmem(); |
Kojto | 0:615c697c33b0 | 391 | int32_t read(uint32_t file_id, uint32_t length, uint32_t offset, uint8_t *buff); |
Kojto | 0:615c697c33b0 | 392 | int32_t write(uint32_t file_id, uint32_t length, uint32_t entry_offset, uint8_t *buff); |
Kojto | 0:615c697c33b0 | 393 | uint8_t set_mac_address(uint8_t *mac); |
Kojto | 0:615c697c33b0 | 394 | uint8_t get_mac_address(uint8_t *mac); |
Kojto | 0:615c697c33b0 | 395 | uint8_t write_patch(uint32_t file_id, uint32_t length, const uint8_t *data); |
Kojto | 0:615c697c33b0 | 396 | int32_t create_entry(uint32_t file_id, uint32_t new_len); |
Kojto | 0:615c697c33b0 | 397 | #ifndef CC3000_TINY_DRIVER |
Kojto | 0:615c697c33b0 | 398 | uint8_t read_sp_version(uint8_t* patch_ver); |
Kojto | 0:615c697c33b0 | 399 | #endif |
Kojto | 0:615c697c33b0 | 400 | private: |
Kojto | 0:615c697c33b0 | 401 | cc3000_hci &_hci; |
Kojto | 0:615c697c33b0 | 402 | cc3000_event &_event; |
Kojto | 0:615c697c33b0 | 403 | cc3000_simple_link &_simple_link; |
Kojto | 0:615c697c33b0 | 404 | }; |
Kojto | 0:615c697c33b0 | 405 | |
Kojto | 0:615c697c33b0 | 406 | class cc3000_wlan { |
Kojto | 0:615c697c33b0 | 407 | public: |
Kojto | 0:615c697c33b0 | 408 | cc3000_wlan(cc3000_simple_link &simple_link, cc3000_event &event, cc3000_spi &spi, cc3000_hci &hci); |
Kojto | 0:615c697c33b0 | 409 | ~cc3000_wlan(); |
Kojto | 0:615c697c33b0 | 410 | /** Send SIMPLE LINK START to cc3000 |
Kojto | 0:615c697c33b0 | 411 | * \param patches_available_host Flag to indicate if patches are available |
Kojto | 0:615c697c33b0 | 412 | * \return none |
Kojto | 0:615c697c33b0 | 413 | */ |
Kojto | 0:615c697c33b0 | 414 | void simpleLink_init_start(uint16_t patches_available_host); |
Kojto | 0:615c697c33b0 | 415 | /** Start wlan device. Blocking call until init is completed |
Kojto | 0:615c697c33b0 | 416 | * \param patches_available_host Flag to indicate if patches are available |
Kojto | 0:615c697c33b0 | 417 | * \return none |
Kojto | 0:615c697c33b0 | 418 | */ |
Kojto | 0:615c697c33b0 | 419 | void start(uint16_t patches_available_host); |
Kojto | 0:615c697c33b0 | 420 | /** Stop wlan device |
Kojto | 0:615c697c33b0 | 421 | * \param none |
Kojto | 0:615c697c33b0 | 422 | * \return none |
Kojto | 0:615c697c33b0 | 423 | */ |
Kojto | 0:615c697c33b0 | 424 | void stop(void); |
Kojto | 0:615c697c33b0 | 425 | #ifndef CC3000_TINY_DRIVER |
Kojto | 0:615c697c33b0 | 426 | 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); |
Kojto | 0:615c697c33b0 | 427 | 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, |
Kojto | 0:615c697c33b0 | 428 | uint32_t key_mgmt, uint8_t* pf_or_key, uint32_t pass_phrase_length); |
Kojto | 0:615c697c33b0 | 429 | int32_t ioctl_get_scan_results(uint32_t scan_timeout, uint8_t *results); |
Kojto | 0:615c697c33b0 | 430 | int32_t ioctl_set_scan_params(uint32_t enable, uint32_t min_dwell_time, uint32_t max_dwell_time, uint32_t num_probe_requests, |
Kojto | 0:615c697c33b0 | 431 | uint32_t channel_mask, int32_t rssi_threshold, uint32_t snr_threshold, uint32_t default_tx_power, uint32_t *interval_list); |
Kojto | 0:615c697c33b0 | 432 | int32_t ioctl_statusget(void); |
Kojto | 0:615c697c33b0 | 433 | #else |
Kojto | 0:615c697c33b0 | 434 | int32_t connect(const uint8_t *ssid, int32_t ssid_length); |
Kojto | 0:615c697c33b0 | 435 | int32_t add_profile(uint32_t sec_type, uint8_t *ssid, uint32_t ssid_length, uint8_t *b_ssid, uint32_t priority, |
Kojto | 0:615c697c33b0 | 436 | uint32_t pairwise_cipher_or_tx_key_len, uint32_t group_cipher_tx_key_index, uint32_t key_mgmt, |
Kojto | 0:615c697c33b0 | 437 | uint8_t* pf_or_key, uint32_t pass_phrase_length); |
Kojto | 0:615c697c33b0 | 438 | #endif |
Kojto | 0:615c697c33b0 | 439 | #ifndef CC3000_UNENCRYPTED_SMART_CONFIG |
Kojto | 0:615c697c33b0 | 440 | int32_t smart_config_process(void); |
Kojto | 0:615c697c33b0 | 441 | #endif |
Kojto | 0:615c697c33b0 | 442 | int32_t disconnect(); |
Kojto | 0:615c697c33b0 | 443 | int32_t ioctl_set_connection_policy(uint32_t should_connect_to_open_ap, uint32_t use_fast_connect, uint32_t use_profiles); |
Kojto | 0:615c697c33b0 | 444 | int32_t ioctl_del_profile(uint32_t index); |
Kojto | 0:615c697c33b0 | 445 | int32_t set_event_mask(uint32_t mask); |
Kojto | 0:615c697c33b0 | 446 | int32_t smart_config_start(uint32_t encrypted_flag); |
Kojto | 0:615c697c33b0 | 447 | int32_t smart_config_stop(void); |
Kojto | 0:615c697c33b0 | 448 | int32_t smart_config_set_prefix(uint8_t *new_prefix); |
Kojto | 0:615c697c33b0 | 449 | private: |
Kojto | 0:615c697c33b0 | 450 | cc3000_simple_link &_simple_link; |
Kojto | 0:615c697c33b0 | 451 | cc3000_event &_event; |
Kojto | 0:615c697c33b0 | 452 | cc3000_spi &_spi; |
Kojto | 0:615c697c33b0 | 453 | cc3000_hci &_hci; |
Kojto | 0:615c697c33b0 | 454 | }; |
Kojto | 0:615c697c33b0 | 455 | |
Kojto | 0:615c697c33b0 | 456 | /** Client TCP/UDP class - TODO - not complete client |
Kojto | 0:615c697c33b0 | 457 | */ |
Kojto | 0:615c697c33b0 | 458 | class cc3000_client { |
Kojto | 0:615c697c33b0 | 459 | public: |
Kojto | 0:615c697c33b0 | 460 | /** |
Kojto | 0:615c697c33b0 | 461 | */ |
Kojto | 0:615c697c33b0 | 462 | cc3000_client(cc3000 &cc3000_ref); |
Kojto | 0:615c697c33b0 | 463 | /** |
Kojto | 0:615c697c33b0 | 464 | */ |
Kojto | 0:615c697c33b0 | 465 | cc3000_client(cc3000 &cc3000_ref, int16_t socket); |
Kojto | 0:615c697c33b0 | 466 | /** |
Kojto | 0:615c697c33b0 | 467 | */ |
Kojto | 0:615c697c33b0 | 468 | bool connected(void); |
Kojto | 0:615c697c33b0 | 469 | /** |
Kojto | 0:615c697c33b0 | 470 | */ |
Kojto | 0:615c697c33b0 | 471 | int16_t write(const void *buffer, uint16_t length, uint32_t flags); |
Kojto | 0:615c697c33b0 | 472 | /** |
Kojto | 0:615c697c33b0 | 473 | */ |
Kojto | 0:615c697c33b0 | 474 | int16_t read(void *buffer, uint16_t length, uint32_t flags); |
Kojto | 0:615c697c33b0 | 475 | /** |
Kojto | 0:615c697c33b0 | 476 | */ |
Kojto | 0:615c697c33b0 | 477 | void close(void); |
Kojto | 0:615c697c33b0 | 478 | |
Kojto | 0:615c697c33b0 | 479 | private: |
Kojto | 0:615c697c33b0 | 480 | int16_t _current_socket; |
Kojto | 0:615c697c33b0 | 481 | cc3000 &_cc3000; |
Kojto | 0:615c697c33b0 | 482 | }; |
Kojto | 0:615c697c33b0 | 483 | |
Kojto | 0:615c697c33b0 | 484 | /** Server TCP/UDP |
Kojto | 0:615c697c33b0 | 485 | */ |
Kojto | 0:615c697c33b0 | 486 | class cc3000_server { |
Kojto | 0:615c697c33b0 | 487 | public: |
Kojto | 0:615c697c33b0 | 488 | /** ctor (server was not created successfully) |
Kojto | 0:615c697c33b0 | 489 | */ |
Kojto | 0:615c697c33b0 | 490 | cc3000_server(cc3000 &cc3000_ref, sockaddr socket_add); |
Kojto | 0:615c697c33b0 | 491 | /** ctor |
Kojto | 0:615c697c33b0 | 492 | */ |
Kojto | 0:615c697c33b0 | 493 | cc3000_server(cc3000 &cc3000_ref, sockaddr socket_add, int16_t socket); |
Kojto | 0:615c697c33b0 | 494 | /** Blocking accept |
Kojto | 0:615c697c33b0 | 495 | */ |
Kojto | 0:615c697c33b0 | 496 | int32_t accept(void); |
Kojto | 0:615c697c33b0 | 497 | /** |
Kojto | 0:615c697c33b0 | 498 | */ |
Kojto | 0:615c697c33b0 | 499 | int32_t receive(void *buffer, uint16_t length, uint32_t flags); |
Kojto | 0:615c697c33b0 | 500 | /** |
Kojto | 0:615c697c33b0 | 501 | */ |
Kojto | 0:615c697c33b0 | 502 | int32_t send(void *buffer, uint16_t length, uint32_t flags); |
Kojto | 0:615c697c33b0 | 503 | /** |
Kojto | 0:615c697c33b0 | 504 | */ |
Kojto | 0:615c697c33b0 | 505 | void bind(void); |
Kojto | 0:615c697c33b0 | 506 | /** |
Kojto | 0:615c697c33b0 | 507 | */ |
Kojto | 0:615c697c33b0 | 508 | void listen(uint32_t backlog); |
Kojto | 0:615c697c33b0 | 509 | /** |
Kojto | 0:615c697c33b0 | 510 | */ |
Kojto | 0:615c697c33b0 | 511 | void close(void); |
Kojto | 0:615c697c33b0 | 512 | private: |
Kojto | 0:615c697c33b0 | 513 | int16_t _current_socket; |
Kojto | 0:615c697c33b0 | 514 | sockaddr _socket_address; |
Kojto | 0:615c697c33b0 | 515 | cc3000 &_cc3000; |
Kojto | 0:615c697c33b0 | 516 | }; |
Kojto | 0:615c697c33b0 | 517 | |
Kojto | 0:615c697c33b0 | 518 | /** The main class of entire cc3000 implementation |
Kojto | 0:615c697c33b0 | 519 | */ |
Kojto | 0:615c697c33b0 | 520 | class cc3000 { |
Kojto | 0:615c697c33b0 | 521 | public: |
Kojto | 0:615c697c33b0 | 522 | typedef struct { |
Kojto | 0:615c697c33b0 | 523 | bool dhcp; |
Kojto | 0:615c697c33b0 | 524 | bool connected; |
Kojto | 0:615c697c33b0 | 525 | uint8_t socket; |
Kojto | 0:615c697c33b0 | 526 | bool smart_config_complete; |
Kojto | 0:615c697c33b0 | 527 | bool stop_smart_config; |
Kojto | 0:615c697c33b0 | 528 | bool dhcp_configured; |
Kojto | 0:615c697c33b0 | 529 | bool ok_to_shut_down; |
Kojto | 0:615c697c33b0 | 530 | } tStatus; |
Kojto | 0:615c697c33b0 | 531 | /** ctor for cc3000 class. |
Kojto | 0:615c697c33b0 | 532 | * \param cc3000_irq IRQ pin |
Kojto | 0:615c697c33b0 | 533 | * \param cc3000_en Enable pin |
Kojto | 0:615c697c33b0 | 534 | * \param cc3000_cs Chip select pin |
Kojto | 0:615c697c33b0 | 535 | * \param cc3000_spi SPI interface |
Kojto | 0:615c697c33b0 | 536 | * \param irq_port IRQ pin's port |
Kojto | 0:615c697c33b0 | 537 | */ |
Kojto | 0:615c697c33b0 | 538 | cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, IRQn_Type irq_port); |
Kojto | 0:615c697c33b0 | 539 | /** dtor |
Kojto | 0:615c697c33b0 | 540 | */ |
Kojto | 0:615c697c33b0 | 541 | ~cc3000(); |
Kojto | 0:615c697c33b0 | 542 | /** Initiate cc3000. It starts the wlan communication and deletes profiles. |
Kojto | 0:615c697c33b0 | 543 | * \param patch Patch |
Kojto | 0:615c697c33b0 | 544 | */ |
Kojto | 0:615c697c33b0 | 545 | void start(uint8_t patch); |
Kojto | 0:615c697c33b0 | 546 | /** Stops the wlan communication. |
Kojto | 0:615c697c33b0 | 547 | */ |
Kojto | 0:615c697c33b0 | 548 | void stop(); |
Kojto | 0:615c697c33b0 | 549 | /** Restarts the wlan communication. |
Kojto | 0:615c697c33b0 | 550 | */ |
Kojto | 0:615c697c33b0 | 551 | void restart(uint8_t patch); |
Kojto | 0:615c697c33b0 | 552 | /** Disconnect wlan device |
Kojto | 0:615c697c33b0 | 553 | * |
Kojto | 0:615c697c33b0 | 554 | */ |
Kojto | 0:615c697c33b0 | 555 | bool disconnect(void); |
Kojto | 0:615c697c33b0 | 556 | /** Callback which is called from the event class. This updates status of cc3000. |
Kojto | 0:615c697c33b0 | 557 | * \param event_type Type of the event |
Kojto | 0:615c697c33b0 | 558 | * \param data Pointer to data |
Kojto | 0:615c697c33b0 | 559 | * \param length Length of data |
Kojto | 0:615c697c33b0 | 560 | * \return none |
Kojto | 0:615c697c33b0 | 561 | */ |
Kojto | 0:615c697c33b0 | 562 | void usync_callback(int32_t event_type, uint8_t *data, uint8_t length); |
Kojto | 0:615c697c33b0 | 563 | /** Connect to SSID (open/secured) with timeout (10ms). |
Kojto | 0:615c697c33b0 | 564 | * \param ssid SSID name |
Kojto | 0:615c697c33b0 | 565 | * \param key Security key (if key = 0, open connection) |
Kojto | 0:615c697c33b0 | 566 | * \param security_mode Security mode |
Kojto | 0:615c697c33b0 | 567 | * \return true if connection was established, false otherwise. |
Kojto | 0:615c697c33b0 | 568 | */ |
Kojto | 0:615c697c33b0 | 569 | bool connect_to_AP(const uint8_t *ssid, const uint8_t *key, int32_t security_mode); |
Kojto | 0:615c697c33b0 | 570 | /** Connect to SSID which is secured |
Kojto | 0:615c697c33b0 | 571 | * \param ssid SSID name |
Kojto | 0:615c697c33b0 | 572 | * \param key Security key |
Kojto | 0:615c697c33b0 | 573 | * \param security_mode Security mode |
Kojto | 0:615c697c33b0 | 574 | * \return true if connection was established, false otherwise. |
Kojto | 0:615c697c33b0 | 575 | */ |
Kojto | 0:615c697c33b0 | 576 | bool connect_secure(const uint8_t *ssid, const uint8_t *key, int32_t security_mode); |
Kojto | 0:615c697c33b0 | 577 | /** Connect to SSID which is open (no security) |
Kojto | 0:615c697c33b0 | 578 | * \param ssid SSID name |
Kojto | 0:615c697c33b0 | 579 | * \return true if connection was established, false otherwise. |
Kojto | 0:615c697c33b0 | 580 | */ |
Kojto | 0:615c697c33b0 | 581 | bool connect_open(const uint8_t *ssid); |
Kojto | 0:615c697c33b0 | 582 | /** Status of the cc3000 connection. |
Kojto | 0:615c697c33b0 | 583 | * \return true if it's connected, false otherwise. |
Kojto | 0:615c697c33b0 | 584 | */ |
Kojto | 0:615c697c33b0 | 585 | bool is_connected(); |
Kojto | 0:615c697c33b0 | 586 | /** Status of DHCP. |
Kojto | 0:615c697c33b0 | 587 | * \param none |
Kojto | 0:615c697c33b0 | 588 | * \return true if DCHP is configured, false otherwise. |
Kojto | 0:615c697c33b0 | 589 | */ |
Kojto | 0:615c697c33b0 | 590 | bool is_dhcp_configured(); |
Kojto | 0:615c697c33b0 | 591 | /** Status of smart confing completation. |
Kojto | 0:615c697c33b0 | 592 | * \param none |
Kojto | 0:615c697c33b0 | 593 | * \return smart config was set, false otherwise. |
Kojto | 0:615c697c33b0 | 594 | */ |
Kojto | 0:615c697c33b0 | 595 | bool is_smart_confing_completed(); |
Kojto | 0:615c697c33b0 | 596 | /** Return the cc3000's mac address. |
Kojto | 0:615c697c33b0 | 597 | * \param address Retreived mac address. |
Kojto | 19:9fdf8b4e41bf | 598 | * \return |
Kojto | 0:615c697c33b0 | 599 | */ |
Kojto | 19:9fdf8b4e41bf | 600 | uint8_t get_mac_address(uint8_t address[6]); |
Kojto | 0:615c697c33b0 | 601 | /** Set the cc3000's mac address |
Kojto | 0:615c697c33b0 | 602 | * \param address Mac address to be set |
Kojto | 19:9fdf8b4e41bf | 603 | * \return |
Kojto | 0:615c697c33b0 | 604 | */ |
Kojto | 19:9fdf8b4e41bf | 605 | uint8_t set_mac_address(uint8_t address[6]); |
Kojto | 0:615c697c33b0 | 606 | /** Get user file info |
Kojto | 0:615c697c33b0 | 607 | * \param info_file Pointer where info will be stored |
Kojto | 0:615c697c33b0 | 608 | * \param size Available size |
Kojto | 0:615c697c33b0 | 609 | * \return none |
Kojto | 0:615c697c33b0 | 610 | */ |
Kojto | 0:615c697c33b0 | 611 | void get_user_file_info(uint8_t *info_file, size_t size); |
Kojto | 0:615c697c33b0 | 612 | /** Set user filo info |
Kojto | 0:615c697c33b0 | 613 | * \param info_file Pointer to user's info |
Kojto | 0:615c697c33b0 | 614 | * \return none |
Kojto | 0:615c697c33b0 | 615 | */ |
Kojto | 0:615c697c33b0 | 616 | void set_user_file_info(uint8_t *info_file, size_t size); |
Kojto | 0:615c697c33b0 | 617 | /** Start smart config |
Kojto | 0:615c697c33b0 | 618 | * \param smart_config_key Pointer to smart config key |
Kojto | 0:615c697c33b0 | 619 | * \return none |
Kojto | 0:615c697c33b0 | 620 | */ |
Kojto | 0:615c697c33b0 | 621 | void start_smart_config(const uint8_t *smart_config_key); /* TODO enable AES ? */ |
Kojto | 0:615c697c33b0 | 622 | #ifndef CC3000_TINY_DRIVER |
Kojto | 0:615c697c33b0 | 623 | /** Return ip configuration |
Kojto | 0:615c697c33b0 | 624 | * \param ip_config Pointer to ipconfig data |
Kojto | 0:615c697c33b0 | 625 | * \return true if it's connected and info was retrieved, false otherwise. |
Kojto | 0:615c697c33b0 | 626 | */ |
Kojto | 0:615c697c33b0 | 627 | bool get_ip_config(tNetappIpconfigRetArgs *ip_config); |
Kojto | 0:615c697c33b0 | 628 | #endif |
Kojto | 0:615c697c33b0 | 629 | /** Creates tcp client |
Kojto | 0:615c697c33b0 | 630 | * \param ip_address Client's IP address |
Kojto | 0:615c697c33b0 | 631 | * \param port Client's PORT |
Kojto | 0:615c697c33b0 | 632 | * \return client with socket != -1 |
Kojto | 0:615c697c33b0 | 633 | */ |
Kojto | 0:615c697c33b0 | 634 | cc3000_client create_tcp_client(uint32_t ip_address, uint16_t port); |
Kojto | 0:615c697c33b0 | 635 | /** Creates tcp server |
Kojto | 0:615c697c33b0 | 636 | * \param ip_address Server's IP address |
Kojto | 0:615c697c33b0 | 637 | * \param port Server's PORT |
Kojto | 0:615c697c33b0 | 638 | * \return server with socket != -1 |
Kojto | 0:615c697c33b0 | 639 | */ |
Kojto | 0:615c697c33b0 | 640 | cc3000_server create_tcp_server(uint32_t ip_address, uint16_t port); |
Kojto | 0:615c697c33b0 | 641 | /** Creates udp client |
Kojto | 0:615c697c33b0 | 642 | * \param ip_address Server's IP address |
Kojto | 0:615c697c33b0 | 643 | * \param port Server's PORT |
Kojto | 0:615c697c33b0 | 644 | * \return client with socket != -1 |
Kojto | 0:615c697c33b0 | 645 | */ |
Kojto | 0:615c697c33b0 | 646 | cc3000_client create_udp_client(uint32_t ip_address, uint16_t port); |
Kojto | 0:615c697c33b0 | 647 | /** Delete all stored profiles |
Kojto | 0:615c697c33b0 | 648 | * \param none |
Kojto | 0:615c697c33b0 | 649 | * \return none |
Kojto | 0:615c697c33b0 | 650 | */ |
Kojto | 0:615c697c33b0 | 651 | void delete_profiles(void); |
Kojto | 0:615c697c33b0 | 652 | /** |
Kojto | 0:615c697c33b0 | 653 | * |
Kojto | 0:615c697c33b0 | 654 | */ |
Kojto | 0:615c697c33b0 | 655 | uint32_t ping(uint32_t ip, uint8_t attempts, uint16_t timeout, uint8_t size); |
Kojto | 0:615c697c33b0 | 656 | |
Kojto | 0:615c697c33b0 | 657 | static cc3000 *get_instance() { |
Kojto | 0:615c697c33b0 | 658 | return _inst; |
Kojto | 0:615c697c33b0 | 659 | } |
Kojto | 0:615c697c33b0 | 660 | public: |
Kojto | 0:615c697c33b0 | 661 | cc3000_simple_link _simple_link; |
Kojto | 0:615c697c33b0 | 662 | cc3000_event _event; |
Kojto | 0:615c697c33b0 | 663 | #ifndef CC3000_UNENCRYPTED_SMART_CONFIG |
Kojto | 0:615c697c33b0 | 664 | cc3000_security _security; |
Kojto | 0:615c697c33b0 | 665 | #endif |
Kojto | 0:615c697c33b0 | 666 | cc3000_socket _socket; |
Kojto | 0:615c697c33b0 | 667 | cc3000_spi _spi; |
Kojto | 0:615c697c33b0 | 668 | cc3000_hci _hci; |
Kojto | 0:615c697c33b0 | 669 | cc3000_nvmem _nvmem; |
Kojto | 0:615c697c33b0 | 670 | cc3000_netapp _netapp; |
Kojto | 0:615c697c33b0 | 671 | cc3000_wlan _wlan; |
Kojto | 0:615c697c33b0 | 672 | protected: |
Kojto | 0:615c697c33b0 | 673 | static cc3000 *_inst; |
Kojto | 0:615c697c33b0 | 674 | private: |
Kojto | 0:615c697c33b0 | 675 | tStatus _status; |
Kojto | 0:615c697c33b0 | 676 | netapp_pingreport_args_t _ping_report; |
Kojto | 0:615c697c33b0 | 677 | bool _closed_sockets[MAX_SOCKETS]; |
Kojto | 0:615c697c33b0 | 678 | }; |
Kojto | 0:615c697c33b0 | 679 | |
Kojto | 0:615c697c33b0 | 680 | /** |
Kojto | 0:615c697c33b0 | 681 | * Copy 32 bit to stream while converting to little endian format. |
Kojto | 0:615c697c33b0 | 682 | * @param p pointer to the new stream |
Kojto | 0:615c697c33b0 | 683 | * @param u32 pointer to the 32 bit |
Kojto | 0:615c697c33b0 | 684 | * @return pointer to the new stream |
Kojto | 0:615c697c33b0 | 685 | */ |
Kojto | 0:615c697c33b0 | 686 | uint8_t *UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32); |
Kojto | 0:615c697c33b0 | 687 | |
Kojto | 0:615c697c33b0 | 688 | /** |
Kojto | 0:615c697c33b0 | 689 | * Copy 16 bit to stream while converting to little endian format. |
Kojto | 0:615c697c33b0 | 690 | * @param p pointer to the new stream |
Kojto | 0:615c697c33b0 | 691 | * @param u32 pointer to the 16 bit |
Kojto | 0:615c697c33b0 | 692 | * @return pointer to the new stream |
Kojto | 0:615c697c33b0 | 693 | */ |
Kojto | 0:615c697c33b0 | 694 | uint8_t *UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16); |
Kojto | 0:615c697c33b0 | 695 | |
Kojto | 0:615c697c33b0 | 696 | /** |
Kojto | 0:615c697c33b0 | 697 | * Copy received stream to 16 bit in little endian format. |
Kojto | 0:615c697c33b0 | 698 | * @param p pointer to the stream |
Kojto | 0:615c697c33b0 | 699 | * @param offset offset in the stream |
Kojto | 0:615c697c33b0 | 700 | * @return pointer to the new 16 bit |
Kojto | 0:615c697c33b0 | 701 | */ |
Kojto | 0:615c697c33b0 | 702 | uint16_t STREAM_TO_UINT16_f(uint8_t* p, uint16_t offset); |
Kojto | 0:615c697c33b0 | 703 | |
Kojto | 0:615c697c33b0 | 704 | /** |
Kojto | 0:615c697c33b0 | 705 | * Copy received stream to 32 bit in little endian format. |
Kojto | 0:615c697c33b0 | 706 | * @param p pointer to the stream |
Kojto | 0:615c697c33b0 | 707 | * @param offset offset in the stream |
Kojto | 0:615c697c33b0 | 708 | * @return pointer to the new 32 bit |
Kojto | 0:615c697c33b0 | 709 | */ |
Kojto | 0:615c697c33b0 | 710 | uint32_t STREAM_TO_UINT32_f(uint8_t* p, uint16_t offset); |
Kojto | 0:615c697c33b0 | 711 | |
Kojto | 0:615c697c33b0 | 712 | } /* end of mbed_cc3000 namespace */ |
Kojto | 0:615c697c33b0 | 713 | |
Kojto | 0:615c697c33b0 | 714 | |
Kojto | 0:615c697c33b0 | 715 | #endif |