Skip to content

Commit

Permalink
Merge pull request ARMmbed#61 from linlingao/socket
Browse files Browse the repository at this point in the history
Add socket implementation
  • Loading branch information
linlingao authored Sep 6, 2018
2 parents 9438658 + f0325bf commit 87ef66c
Show file tree
Hide file tree
Showing 4 changed files with 446 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ CC3220SFInterface::CC3220SFInterface():
_initialized(false),
_started(false)
{
//memset(_ids, 0, sizeof(_ids));
//memset(_cbs, 0, sizeof(_cbs));
memset(_ssid, 0, sizeof(_ssid));
memset(_pass, 0, sizeof(_pass));
//memset(_local_ports, 0, sizeof(_local_ports));
_security = NSAPI_SECURITY_UNKNOWN;
_cc3200_simplelink.initialize();
}
Expand Down Expand Up @@ -213,35 +211,72 @@ nsapi_connection_status_t CC3220SFInterface::get_connection_status() const
return _cc3200_simplelink.get_connection_status();
}

#if 0
WiFiInterface *WiFiInterface::get_default_instance() {
static CC3220SF_WiFiInterface cc3220_wifi;
return &cc3220_wifi;
}
#endif
struct cc3200_socket {
int id;
nsapi_protocol_t proto;
bool connected;
// SocketAddress addr;
int keepalive; // TCP
};

int CC3220SFInterface::socket_open(void **handle, nsapi_protocol_t proto)
{
return 0;
if (handle)
{
*(int32_t*)handle = _cc3200_simplelink.open_socket(proto);
if (*(int32_t*)handle >= 0)
{
return 0;
}
}
return -1;
}

int CC3220SFInterface::socket_close(void *handle)
{
return 0;
return (_cc3200_simplelink.close_socket((uint32_t)handle));
}

nsapi_error_t CC3220SFInterface::setsockopt(nsapi_socket_t handle, int level,
int optname, const void *optval, unsigned optlen)
{
nsapi_error_t retcode = _cc3200_simplelink.setsockopt((uint32_t)handle, level, optname, optval, optlen);
return retcode;
}

nsapi_error_t CC3220SFInterface::getsockopt(nsapi_socket_t handle, int level, int optname,
void *optval, unsigned *optlen)
{
nsapi_error_t retcode = _cc3200_simplelink.getsockopt((uint32_t)handle, level, optname, optval, optlen);
return retcode;
}

int CC3220SFInterface::socket_bind(void *handle, const SocketAddress &address)
{
return 0;
bool ipv6 = false;
nsapi_addr_t nsapi_address = address.get_addr();
if (nsapi_address.version == NSAPI_IPv6)
{
ipv6 = true;
}
return _cc3200_simplelink.bind_socket((uint32_t)handle, ipv6, nsapi_address.bytes, address.get_port());
}

int CC3220SFInterface::socket_listen(void *handle, int backlog)
{
return 0;
}

int CC3220SFInterface::socket_connect(void *handle, const SocketAddress &address)
int CC3220SFInterface::socket_connect(void *handle, const SocketAddress &addr)
{
return 0;
bool ipv6 = false;
nsapi_addr_t nsapi_address = addr.get_addr();
if (nsapi_address.version == NSAPI_IPv6)
{
ipv6 = true;
}

return _cc3200_simplelink.connect_socket((uint32_t)handle, ipv6, nsapi_address.bytes, addr.get_port());
}

int CC3220SFInterface::socket_accept(void *handle, void **socket, SocketAddress *address)
Expand All @@ -251,22 +286,41 @@ int CC3220SFInterface::socket_accept(void *handle, void **socket, SocketAddress

int CC3220SFInterface::socket_send(void *handle, const void *data, unsigned size)
{
return 0;
return _cc3200_simplelink.send((uint32_t)handle, data, size);
}

int CC3220SFInterface::socket_recv(void *handle, void *data, unsigned size)
{
return 0;
return _cc3200_simplelink.recv((uint32_t)handle, data, size);
}

int CC3220SFInterface::socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size)
{
return 0;
bool ipv6 = false;
nsapi_addr_t nsapi_address = address.get_addr();
if (nsapi_address.version == NSAPI_IPv6)
{
ipv6 = true;
}
return _cc3200_simplelink.sendto_socket((uint32_t)handle, ipv6, data, size, nsapi_address.bytes, address.get_port());
}

int CC3220SFInterface::socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size)
{
return 0;
bool ipv6 = false;
if (address)
{
nsapi_addr_t nsapi_address = address->get_addr();
if (nsapi_address.version == NSAPI_IPv6)
{
ipv6 = true;
}
return _cc3200_simplelink.recvfrom((uint32_t)handle, ipv6, buffer, size, nsapi_address.bytes, address->get_port());
}
else
{
return _cc3200_simplelink.recv((uint32_t)handle, buffer, size);
}
}

void CC3220SFInterface::socket_attach(void *handle, void (*callback)(void *), void *data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include "mbed.h"
#include "cc3200_simplelink.h"

// TODO: check this
#define CC3220SF_SOCKET_COUNT 5

/** TI (CC3220SF) interface class
* Implementation of the NetworkStack for TI CC3200 Simplelink stack
*/
Expand Down Expand Up @@ -143,7 +140,7 @@ class CC3220SFInterface: public NetworkStack, public WiFiInterface
*/
virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count);

#if 0

/** Translates a hostname to an IP address with specific version
*
* The hostname may be either a domain name or an IP address. If the
Expand Down Expand Up @@ -200,7 +197,6 @@ class CC3220SFInterface: public NetworkStack, public WiFiInterface
*/
virtual nsapi_error_t getsockopt(nsapi_socket_t handle, int level, int optname,
void *optval, unsigned *optlen);
#endif

/** Register callback for status reporting
*
Expand Down Expand Up @@ -332,28 +328,14 @@ class CC3220SFInterface: public NetworkStack, public WiFiInterface
static const int CC3220SF_PASSPHRASE_MIN_LENGTH = 8; /* The shortest allowed passphrase */

CC3200_SIMPLELINK _cc3200_simplelink;
//bool _ids[CC3220SF_SOCKET_COUNT];
int _initialized;
int _started;

char _ssid[CC3220SF_SSID_MAX_LENGTH + 1]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */
nsapi_security_t _security;
uint8_t _channel;
char _pass[CC3220SF_PASSPHRASE_MAX_LENGTH + 1];
#if 0
uint16_t _local_ports[CC3220SF_SOCKET_COUNT];

bool _disable_default_softap();
void event();
bool _get_firmware_ok();
#endif
nsapi_error_t _init(void);
nsapi_error_t _startup(const int8_t wifi_mode);
#if 0
struct {
void (*callback)(void *);
void *data;
} _cbs[CC3220SF_SOCKET_COUNT];
#endif
};
#endif
Loading

0 comments on commit 87ef66c

Please sign in to comment.