Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
netapp.cpp
00001 /***************************************************************************** 00002 * 00003 * netapp.c - CC3000 Host Driver Implementation. 00004 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 00013 * Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the 00016 * distribution. 00017 * 00018 * Neither the name of Texas Instruments Incorporated nor the names of 00019 * its contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00026 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 *****************************************************************************/ 00035 #include <string.h> 00036 #include "netapp.h" 00037 #include "hci.h" 00038 #include "socket.h" 00039 #include "evnt_handler.h" 00040 #include "nvmem.h" 00041 00042 #define MIN_TIMER_VAL_SECONDS 20 00043 #define MIN_TIMER_SET(t) if ((0 != t) && (t < MIN_TIMER_VAL_SECONDS)) \ 00044 { \ 00045 t = MIN_TIMER_VAL_SECONDS; \ 00046 } 00047 00048 00049 #define NETAPP_DHCP_PARAMS_LEN (20) 00050 #define NETAPP_SET_TIMER_PARAMS_LEN (20) 00051 #define NETAPP_SET_DEBUG_LEVEL_PARAMS_LEN (4) 00052 #define NETAPP_PING_SEND_PARAMS_LEN (16) 00053 00054 00055 //***************************************************************************** 00056 // 00057 //! netapp_config_mac_adrress 00058 //! 00059 //! @param mac device mac address, 6 bytes. Saved: yes 00060 //! 00061 //! @return return on success 0, otherwise error. 00062 //! 00063 //! @brief Configure device MAC address and store it in NVMEM. 00064 //! The value of the MAC address configured through the API will 00065 //! be stored in CC3000 non volatile memory, thus preserved 00066 //! over resets. 00067 // 00068 //***************************************************************************** 00069 long netapp_config_mac_adrress(unsigned char * mac) 00070 { 00071 return nvmem_set_mac_address(mac); 00072 } 00073 00074 //***************************************************************************** 00075 // 00076 //! netapp_dhcp 00077 //! 00078 //! @param aucIP device mac address, 6 bytes. Saved: yes 00079 //! @param aucSubnetMask device mac address, 6 bytes. Saved: yes 00080 //! @param aucDefaultGateway device mac address, 6 bytes. Saved: yes 00081 //! @param aucDNSServer device mac address, 6 bytes. Saved: yes 00082 //! 00083 //! @return return on success 0, otherwise error. 00084 //! 00085 //! @brief netapp_dhcp is used to configure the network interface, 00086 //! static or dynamic (DHCP).\n In order to activate DHCP mode, 00087 //! aucIP, aucSubnetMask, aucDefaultGateway must be 0. 00088 //! The default mode of CC3000 is DHCP mode. 00089 //! Note that the configuration is saved in non volatile memory 00090 //! and thus preserved over resets. 00091 //! 00092 //! @note If the mode is altered a reset of CC3000 device is required 00093 //! in order to apply changes.\nAlso note that asynchronous event 00094 //! of DHCP_EVENT, which is generated when an IP address is 00095 //! allocated either by the DHCP server or due to static 00096 //! allocation is generated only upon a connection to the 00097 //! AP was established. 00098 //! 00099 //***************************************************************************** 00100 long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,unsigned long *aucDefaultGateway, unsigned long *aucDNSServer) 00101 { 00102 signed char scRet; 00103 unsigned char *ptr; 00104 unsigned char *args; 00105 00106 scRet = EFAIL; 00107 ptr = tSLInformation.pucTxCommandBuffer; 00108 args = (ptr + HEADERS_SIZE_CMD); 00109 00110 // Fill in temporary command buffer 00111 ARRAY_TO_STREAM(args,aucIP,4); 00112 ARRAY_TO_STREAM(args,aucSubnetMask,4); 00113 ARRAY_TO_STREAM(args,aucDefaultGateway,4); 00114 args = UINT32_TO_STREAM(args, 0); 00115 ARRAY_TO_STREAM(args,aucDNSServer,4); 00116 00117 // Initiate a HCI command 00118 hci_command_send(HCI_NETAPP_DHCP, ptr, NETAPP_DHCP_PARAMS_LEN); 00119 00120 // Wait for command complete event 00121 SimpleLinkWaitEvent(HCI_NETAPP_DHCP, (long*)&scRet); 00122 00123 return(scRet); 00124 } 00125 00126 00127 //***************************************************************************** 00128 // 00129 //! netapp_timeout_values 00130 //! 00131 //! @param aucDHCP DHCP lease time request, also impact 00132 //! the DHCP renew timeout. Range: [0-0xffffffff] seconds, 00133 //! 0 or 0xffffffff == infinity lease timeout. 00134 //! Resolution:10 seconds. Influence: only after 00135 //! reconnecting to the AP. 00136 //! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds. 00137 //! The parameter is saved into the CC3000 NVMEM. 00138 //! The default value on CC3000 is 14400 seconds. 00139 //! 00140 //! @param aucARP ARP refresh timeout, if ARP entry is not updated by 00141 //! incoming packet, the ARP entry will be deleted by 00142 //! the end of the timeout. 00143 //! Range: [0-0xffffffff] seconds, 0 == infinity ARP timeout 00144 //! Resolution: 10 seconds. Influence: on runtime. 00145 //! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 seconds 00146 //! The parameter is saved into the CC3000 NVMEM. 00147 //! The default value on CC3000 is 3600 seconds. 00148 //! 00149 //! @param aucKeepalive Keepalive event sent by the end of keepalive timeout 00150 //! Range: [0-0xffffffff] seconds, 0 == infinity timeout 00151 //! Resolution: 10 seconds. 00152 //! Influence: on runtime. 00153 //! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec 00154 //! The parameter is saved into the CC3000 NVMEM. 00155 //! The default value on CC3000 is 10 seconds. 00156 //! 00157 //! @param aucInactivity Socket inactivity timeout, socket timeout is 00158 //! refreshed by incoming or outgoing packet, by the 00159 //! end of the socket timeout the socket will be closed 00160 //! Range: [0-0xffffffff] sec, 0 == infinity timeout. 00161 //! Resolution: 10 seconds. Influence: on runtime. 00162 //! Minimal bound value: MIN_TIMER_VAL_SECONDS - 20 sec 00163 //! The parameter is saved into the CC3000 NVMEM. 00164 //! The default value on CC3000 is 60 seconds. 00165 //! 00166 //! @return return on success 0, otherwise error. 00167 //! 00168 //! @brief Set new timeout values. Function set new timeout values for: 00169 //! DHCP lease timeout, ARP refresh timeout, keepalive event 00170 //! timeout and socket inactivity timeout 00171 //! 00172 //! @note If a parameter set to non zero value which is less than 20s, 00173 //! it will be set automatically to 20s. 00174 //! 00175 //***************************************************************************** 00176 00177 #ifndef CC3000_TINY_DRIVER 00178 long 00179 netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,unsigned long *aucKeepalive, unsigned long *aucInactivity) 00180 { 00181 signed char scRet; 00182 unsigned char *ptr; 00183 unsigned char *args; 00184 00185 scRet = EFAIL; 00186 ptr = tSLInformation.pucTxCommandBuffer; 00187 args = (ptr + HEADERS_SIZE_CMD); 00188 00189 // Set minimal values of timers 00190 MIN_TIMER_SET(*aucDHCP) 00191 MIN_TIMER_SET(*aucARP) 00192 MIN_TIMER_SET(*aucKeepalive) 00193 MIN_TIMER_SET(*aucInactivity) 00194 00195 // Fill in temporary command buffer 00196 args = UINT32_TO_STREAM(args, *aucDHCP); 00197 args = UINT32_TO_STREAM(args, *aucARP); 00198 args = UINT32_TO_STREAM(args, *aucKeepalive); 00199 args = UINT32_TO_STREAM(args, *aucInactivity); 00200 00201 // Initiate a HCI command 00202 hci_command_send(HCI_NETAPP_SET_TIMERS, ptr, NETAPP_SET_TIMER_PARAMS_LEN); 00203 00204 // Wait for command complete event 00205 SimpleLinkWaitEvent(HCI_NETAPP_SET_TIMERS, (long*)&scRet); 00206 00207 return(scRet); 00208 } 00209 #endif 00210 00211 00212 //***************************************************************************** 00213 // 00214 //! netapp_ping_send 00215 //! 00216 //! @param ip destination IP address 00217 //! @param pingAttempts number of echo requests to send 00218 //! @param pingSize send buffer size which may be up to 1400 bytes 00219 //! @param pingTimeout Time to wait for a response,in milliseconds. 00220 //! 00221 //! @return return on success 0, otherwise error. 00222 //! 00223 //! @brief send ICMP ECHO_REQUEST to network hosts 00224 //! 00225 //! @note If an operation finished successfully asynchronous ping report 00226 //! event will be generated. The report structure is as defined 00227 //! by structure netapp_pingreport_args_t. 00228 //! 00229 //! @warning Calling this function while a previous Ping Requests are in 00230 //! progress will stop the previous ping request. 00231 //***************************************************************************** 00232 00233 #ifndef CC3000_TINY_DRIVER 00234 long 00235 netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout) 00236 { 00237 signed char scRet; 00238 unsigned char *ptr, *args; 00239 00240 scRet = EFAIL; 00241 ptr = tSLInformation.pucTxCommandBuffer; 00242 args = (ptr + HEADERS_SIZE_CMD); 00243 00244 // Fill in temporary command buffer 00245 args = UINT32_TO_STREAM(args, *ip); 00246 args = UINT32_TO_STREAM(args, ulPingAttempts); 00247 args = UINT32_TO_STREAM(args, ulPingSize); 00248 args = UINT32_TO_STREAM(args, ulPingTimeout); 00249 00250 // Initiate a HCI command 00251 hci_command_send(HCI_NETAPP_PING_SEND, ptr, NETAPP_PING_SEND_PARAMS_LEN); 00252 00253 // Wait for command complete event 00254 SimpleLinkWaitEvent(HCI_NETAPP_PING_SEND, (long*)&scRet); 00255 00256 return(scRet); 00257 } 00258 #endif 00259 00260 //***************************************************************************** 00261 // 00262 //! netapp_ping_report 00263 //! 00264 //! @param none 00265 //! 00266 //! @return none 00267 //! 00268 //! @brief Request for ping status. This API triggers the CC3000 to send 00269 //! asynchronous events: HCI_EVNT_WLAN_ASYNC_PING_REPORT. 00270 //! This event will carry the report structure: 00271 //! netapp_pingreport_args_t. This structure is filled in with ping 00272 //! results up till point of triggering API. 00273 //! netapp_pingreport_args_t:\n packets_sent - echo sent, 00274 //! packets_received - echo reply, min_round_time - minimum 00275 //! round time, max_round_time - max round time, 00276 //! avg_round_time - average round time 00277 //! 00278 //! @note When a ping operation is not active, the returned structure 00279 //! fields are 0. 00280 //! 00281 //***************************************************************************** 00282 00283 00284 #ifndef CC3000_TINY_DRIVER 00285 void netapp_ping_report() 00286 { 00287 unsigned char *ptr; 00288 ptr = tSLInformation.pucTxCommandBuffer; 00289 signed char scRet; 00290 00291 scRet = EFAIL; 00292 00293 // Initiate a HCI command 00294 hci_command_send(HCI_NETAPP_PING_REPORT, ptr, 0); 00295 00296 // Wait for command complete event 00297 SimpleLinkWaitEvent(HCI_NETAPP_PING_REPORT, (long*)&scRet); 00298 } 00299 #endif 00300 00301 //***************************************************************************** 00302 // 00303 //! netapp_ping_stop 00304 //! 00305 //! @param none 00306 //! 00307 //! @return On success, zero is returned. On error, -1 is returned. 00308 //! 00309 //! @brief Stop any ping request. 00310 //! 00311 //! 00312 //***************************************************************************** 00313 00314 #ifndef CC3000_TINY_DRIVER 00315 long netapp_ping_stop() 00316 { 00317 signed char scRet; 00318 unsigned char *ptr; 00319 00320 scRet = EFAIL; 00321 ptr = tSLInformation.pucTxCommandBuffer; 00322 00323 // Initiate a HCI command 00324 hci_command_send(HCI_NETAPP_PING_STOP, ptr, 0); 00325 00326 // Wait for command complete event 00327 SimpleLinkWaitEvent(HCI_NETAPP_PING_STOP, (long*)&scRet); 00328 00329 return(scRet); 00330 } 00331 #endif 00332 00333 //***************************************************************************** 00334 // 00335 //! netapp_ipconfig 00336 //! 00337 //! @param[out] ipconfig This argument is a pointer to a 00338 //! tNetappIpconfigRetArgs structure. This structure is 00339 //! filled in with the network interface configuration. 00340 //! tNetappIpconfigRetArgs:\n aucIP - ip address, 00341 //! aucSubnetMask - mask, aucDefaultGateway - default 00342 //! gateway address, aucDHCPServer - dhcp server address 00343 //! aucDNSServer - dns server address, uaMacAddr - mac 00344 //! address, uaSSID - connected AP ssid 00345 //! 00346 //! @return none 00347 //! 00348 //! @brief Obtain the CC3000 Network interface information. 00349 //! Note that the information is available only after the WLAN 00350 //! connection was established. Calling this function before 00351 //! associated, will cause non-defined values to be returned. 00352 //! 00353 //! @note The function is useful for figuring out the IP Configuration of 00354 //! the device when DHCP is used and for figuring out the SSID of 00355 //! the Wireless network the device is associated with. 00356 //! 00357 //***************************************************************************** 00358 00359 #ifndef CC3000_TINY_DRIVER 00360 void netapp_ipconfig( tNetappIpconfigRetArgs * ipconfig ) 00361 { 00362 unsigned char *ptr; 00363 00364 ptr = tSLInformation.pucTxCommandBuffer; 00365 00366 // Initiate a HCI command 00367 hci_command_send(HCI_NETAPP_IPCONFIG, ptr, 0); 00368 00369 // Wait for command complete event 00370 SimpleLinkWaitEvent(HCI_NETAPP_IPCONFIG, (long*)ipconfig ); 00371 00372 } 00373 #else 00374 void netapp_ipconfig( tNetappIpconfigRetArgs * ipconfig ) 00375 { 00376 00377 } 00378 #endif 00379 00380 //***************************************************************************** 00381 // 00382 //! netapp_arp_flush 00383 //! 00384 //! @param none 00385 //! 00386 //! @return none 00387 //! 00388 //! @brief Flushes ARP table 00389 //! 00390 //***************************************************************************** 00391 00392 #ifndef CC3000_TINY_DRIVER 00393 long netapp_arp_flush(void) 00394 { 00395 signed char scRet; 00396 unsigned char *ptr; 00397 00398 scRet = EFAIL; 00399 ptr = tSLInformation.pucTxCommandBuffer; 00400 00401 // Initiate a HCI command 00402 hci_command_send(HCI_NETAPP_ARP_FLUSH, ptr, 0); 00403 00404 // Wait for command complete event 00405 SimpleLinkWaitEvent(HCI_NETAPP_ARP_FLUSH, (long*)&scRet); 00406 00407 return(scRet); 00408 } 00409 #endif 00410 00411 //***************************************************************************** 00412 // 00413 //! netapp_set_debug_level 00414 //! 00415 //! @param[in] level debug level. Bitwise [0-8], 00416 //! 0(disable)or 1(enable).\n Bitwise map: 0 - Critical 00417 //! message, 1 information message, 2 - core messages, 3 - 00418 //! HCI messages, 4 - Network stack messages, 5 - wlan 00419 //! messages, 6 - wlan driver messages, 7 - epprom messages, 00420 //! 8 - general messages. Default: 0x13f. Saved: no 00421 //! 00422 //! @return On success, zero is returned. On error, -1 is returned 00423 //! 00424 //! @brief Debug messages sent via the UART debug channel, this function 00425 //! enable/disable the debug level 00426 //! 00427 //***************************************************************************** 00428 00429 00430 #ifndef CC3000_TINY_DRIVER 00431 long netapp_set_debug_level(unsigned long ulLevel) 00432 { 00433 signed char scRet; 00434 unsigned char *ptr, *args; 00435 00436 scRet = EFAIL; 00437 ptr = tSLInformation.pucTxCommandBuffer; 00438 args = (ptr + HEADERS_SIZE_CMD); 00439 00440 // 00441 // Fill in temporary command buffer 00442 // 00443 args = UINT32_TO_STREAM(args, ulLevel); 00444 00445 00446 // 00447 // Initiate a HCI command 00448 // 00449 hci_command_send(HCI_NETAPP_SET_DEBUG_LEVEL, ptr, NETAPP_SET_DEBUG_LEVEL_PARAMS_LEN); 00450 00451 // 00452 // Wait for command complete event 00453 // 00454 SimpleLinkWaitEvent(HCI_NETAPP_SET_DEBUG_LEVEL, (long*)&scRet); 00455 00456 return(scRet); 00457 00458 } 00459 #endif 00460
Generated on Tue Jul 12 2022 19:26:44 by
1.7.2