cc3000 hostdriver with the mbed socket interface
Dependents: cc3000_hello_world_demo cc3000_simple_socket_demo cc3000_ntp_demo cc3000_ping_demo ... more
Revision 16:f3676ae62f96, committed 2013-10-02
- Comitter:
- SolderSplashLabs
- Date:
- Wed Oct 02 16:00:41 2013 +0000
- Parent:
- 15:aae737ca3dd2
- Parent:
- 12:1c2a856c618a
- Child:
- 17:14b6a3a2b622
- Commit message:
- Merged martins changes with mine
Changed in this revision
--- a/Helper/def.h Wed Oct 02 15:29:26 2013 +0000 +++ b/Helper/def.h Wed Oct 02 16:00:41 2013 +0000 @@ -1,28 +1,24 @@ -/* Copyright (C) 2013 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef DEF_H -#define DEF_H - -#include "cmsis.h" -//#define htons(x) __REV16(x) -//#define ntohs(x) __REV16(x) -//#define htonl(x) __REV(x) -//#define ntohl(x) __REV(x) - -#endif +/* Copyright (C) 2013 mbed.org, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef DEF_H +#define DEF_H + +#include "cmsis.h" + +#endif
--- a/Socket/Endpoint.cpp Wed Oct 02 15:29:26 2013 +0000 +++ b/Socket/Endpoint.cpp Wed Oct 02 16:00:41 2013 +0000 @@ -93,7 +93,7 @@ if (result != 4) { //Resolve DNS address or populate hard-coded IP address uint32_t address_integer; - _cc3000_module->_socket.get_host_by_name((uint8_t *)host, strlen(host) , &address_integer); + _cc3000_module->_socket.gethostbyname((uint8_t *)host, strlen(host) , &address_integer); uint32_t ip = 0; ip = (ip | (address_integer >> 24)); @@ -116,7 +116,7 @@ int((_remote_host.sin_addr.s_addr & 0xFF0000) >> 16), int((_remote_host.sin_addr.s_addr & 0xFF000000) >> 24)); DBG_SOCKET("port: %d", port); - + return 0; }
--- a/Socket/Socket.cpp Wed Oct 02 15:29:26 2013 +0000 +++ b/Socket/Socket.cpp Wed Oct 02 16:00:41 2013 +0000 @@ -50,11 +50,11 @@ } int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) { - return _cc3000_module->_socket.set_sockopt(_sock_fd, level, optname, optval, optlen); + return _cc3000_module->_socket.setsockopt(_sock_fd, level, optname, optval, optlen); } int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) { - return _cc3000_module->_socket.get_sockopt(_sock_fd, level, optname, optval, optlen); + return _cc3000_module->_socket.getsockopt(_sock_fd, level, optname, optval, optlen); } int Socket::select(struct timeval *timeout, bool read, bool write) { @@ -70,9 +70,9 @@ fd_set* writeset = (write) ? (&fdSet) : (NULL); int ret = _cc3000_module->_socket.select(_sock_fd+1, readset, writeset, NULL, timeout); - + DBG_SOCKET("Select on sock_fd: %d, returns %d. fdSet: %d", _sock_fd, ret, fdSet); - + // TODO //return (ret <= 0 || !FD_ISSET(_sock_fd, &fdSet)) ? (-1) : (0); if (FD_ISSET(_sock_fd, &fdSet)) {
--- a/Socket/UDPSocket.cpp Wed Oct 02 15:29:26 2013 +0000 +++ b/Socket/UDPSocket.cpp Wed Oct 02 16:00:41 2013 +0000 @@ -57,15 +57,13 @@ return -1; } -// if (!_blocking) { -// TimeInterval timeout(_timeout); -// if (wait_writable(timeout) != 0) { -//#if (CC3000_DEBUG == 1) -// printf("DEBUG: The socket is not writeable. _sock_fd: %d.\n", _sock_fd); -//#endif -// return 0; -// } -// } + if (!_blocking) { + TimeInterval timeout(_timeout); + if (wait_writable(timeout) != 0) { + DBG_SOCKET("The socket is not writeable. _sock_fd: %d", _sock_fd); + return 0; + } + } return _cc3000_module->_socket.sendto(_sock_fd, packet, length, 0, (sockaddr *)&remote._remote_host, sizeof(sockaddr)); }
--- a/cc3000.cpp Wed Oct 02 15:29:26 2013 +0000 +++ b/cc3000.cpp Wed Oct 02 16:00:41 2013 +0000 @@ -141,9 +141,9 @@ wait_ms(100); } - + DBG_CC("Smartconfig finished"); - + #ifndef CC3000_UNENCRYPTED_SMART_CONFIG // create new entry for AES encryption key _nvmem.create_entry(NVMEM_AES128_KEY_FILEID, 16); @@ -204,9 +204,9 @@ /* timeout 10 seconds */ if (t.read_ms() > 10000){ ret = false; - + DBG_CC("Connection to AP failed"); - + break; } }
--- a/cc3000.h Wed Oct 02 15:29:26 2013 +0000 +++ b/cc3000.h Wed Oct 02 16:00:41 2013 +0000 @@ -277,27 +277,26 @@ public: cc3000_socket(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_event &event); ~cc3000_socket(); - int32_t HostFlowControlConsumeBuff(int32_t sd); int32_t socket(int32_t domain, int32_t type, int32_t protocol); - int32_t closesocket(int32_t sd); int32_t accept(int32_t sd, sockaddr *addr, socklen_t *addrlen); int32_t bind(int32_t sd, const sockaddr *addr, int32_t addrlen); + int32_t HostFlowControlConsumeBuff(int32_t sd); + int32_t closesocket(int32_t sd); int32_t listen(int32_t sd, int32_t backlog); -#ifndef CC3000_TINY_DRIVER - int32_t gethostbyname(uint8_t * hostname, uint16_t name_length, uint32_t* out_ip_addr); - int32_t get_host_by_name(uint8_t * hostname, uint16_t name_length, uint32_t* out_ip_addr); - int32_t set_sockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen); -#endif int32_t connect(int32_t sd, const sockaddr *addr, int32_t addrlen); int32_t select(int32_t nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout); - int32_t get_sockopt (int32_t sd, int32_t level, int32_t optname, void *optval, socklen_t *optlen); + int32_t getsockopt (int32_t sd, int32_t level, int32_t optname, void *optval, socklen_t *optlen); int32_t simple_link_recv(int32_t sd, void *buf, int32_t len, int32_t flags, sockaddr *from, socklen_t *fromlen, int32_t opcode); + 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); int32_t recv(int32_t sd, void *buf, int32_t len, int32_t flags); int32_t recvfrom(int32_t sd, void *buf, int32_t len, int32_t flags, sockaddr *from, socklen_t *fromlen); - 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); int32_t send(int32_t sd, const void *buf, int32_t len, int32_t flags); int32_t sendto(int32_t sd, const void *buf, int32_t len, int32_t flags, const sockaddr *to, socklen_t tolen); int32_t mdns_advertiser(uint16_t mdns_enabled, uint8_t * device_service_name, uint16_t device_service_name_length); +#ifndef CC3000_TINY_DRIVER + int32_t gethostbyname(uint8_t *hostname, uint16_t name_length, uint32_t *out_ip_addr); + int32_t setsockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen); +#endif private: cc3000_simple_link &_simple_link; cc3000_hci &_hci;
--- a/cc3000_socket.cpp Wed Oct 02 15:29:26 2013 +0000 +++ b/cc3000_socket.cpp Wed Oct 02 16:00:41 2013 +0000 @@ -347,7 +347,7 @@ } } -int32_t cc3000_socket::get_sockopt (int32_t sd, int32_t level, int32_t optname, void *optval, socklen_t *optlen) { +int32_t cc3000_socket::getsockopt (int32_t sd, int32_t level, int32_t optname, void *optval, socklen_t *optlen) { uint8_t *ptr, *args; tBsdGetSockOptReturnParams tRetParams; @@ -534,12 +534,7 @@ #ifndef CC3000_TINY_DRIVER - int32_t cc3000_socket::gethostbyname(uint8_t *hostname, uint16_t name_length, uint32_t *out_ip_addr) { - return (get_host_by_name(hostname, name_length, out_ip_addr)); -} - -int32_t cc3000_socket::get_host_by_name(uint8_t *hostname, uint16_t name_length, uint32_t *out_ip_addr) { tBsdGethostbynameParams ret; uint8_t *ptr, *args; @@ -571,7 +566,7 @@ return (errno); } -int32_t cc3000_socket::set_sockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen) { +int32_t cc3000_socket::setsockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen) { int32_t ret; uint8_t *ptr, *args;