@@ -24,11 +24,9 @@ CC3220SFInterface::CC3220SFInterface():
24
24
_initialized(false ),
25
25
_started(false )
26
26
{
27
- // memset(_ids, 0, sizeof(_ids));
28
27
// memset(_cbs, 0, sizeof(_cbs));
29
28
memset (_ssid, 0 , sizeof (_ssid));
30
29
memset (_pass, 0 , sizeof (_pass));
31
- // memset(_local_ports, 0, sizeof(_local_ports));
32
30
_security = NSAPI_SECURITY_UNKNOWN;
33
31
_cc3200_simplelink.initialize ();
34
32
}
@@ -213,35 +211,72 @@ nsapi_connection_status_t CC3220SFInterface::get_connection_status() const
213
211
return _cc3200_simplelink.get_connection_status ();
214
212
}
215
213
216
- #if 0
217
- WiFiInterface *WiFiInterface::get_default_instance() {
218
- static CC3220SF_WiFiInterface cc3220_wifi;
219
- return &cc3220_wifi;
220
- }
221
- #endif
214
+ struct cc3200_socket {
215
+ int id;
216
+ nsapi_protocol_t proto;
217
+ bool connected;
218
+ // SocketAddress addr;
219
+ int keepalive; // TCP
220
+ };
222
221
223
222
int CC3220SFInterface::socket_open (void **handle, nsapi_protocol_t proto)
224
223
{
225
- return 0 ;
224
+ if (handle)
225
+ {
226
+ *(int32_t *)handle = _cc3200_simplelink.open_socket (proto);
227
+ if (*(int32_t *)handle >= 0 )
228
+ {
229
+ return 0 ;
230
+ }
231
+ }
232
+ return -1 ;
226
233
}
234
+
227
235
int CC3220SFInterface::socket_close (void *handle)
228
236
{
229
- return 0 ;
237
+ return (_cc3200_simplelink.close_socket ((uint32_t )handle));
238
+ }
239
+
240
+ nsapi_error_t CC3220SFInterface::setsockopt (nsapi_socket_t handle, int level,
241
+ int optname, const void *optval, unsigned optlen)
242
+ {
243
+ nsapi_error_t retcode = _cc3200_simplelink.setsockopt ((uint32_t )handle, level, optname, optval, optlen);
244
+ return retcode;
245
+ }
246
+
247
+ nsapi_error_t CC3220SFInterface::getsockopt (nsapi_socket_t handle, int level, int optname,
248
+ void *optval, unsigned *optlen)
249
+ {
250
+ nsapi_error_t retcode = _cc3200_simplelink.getsockopt ((uint32_t )handle, level, optname, optval, optlen);
251
+ return retcode;
230
252
}
231
253
232
254
int CC3220SFInterface::socket_bind (void *handle, const SocketAddress &address)
233
255
{
234
- return 0 ;
256
+ bool ipv6 = false ;
257
+ nsapi_addr_t nsapi_address = address.get_addr ();
258
+ if (nsapi_address.version == NSAPI_IPv6)
259
+ {
260
+ ipv6 = true ;
261
+ }
262
+ return _cc3200_simplelink.bind_socket ((uint32_t )handle, ipv6, nsapi_address.bytes , address.get_port ());
235
263
}
236
264
237
265
int CC3220SFInterface::socket_listen (void *handle, int backlog)
238
266
{
239
267
return 0 ;
240
268
}
241
269
242
- int CC3220SFInterface::socket_connect (void *handle, const SocketAddress &address )
270
+ int CC3220SFInterface::socket_connect (void *handle, const SocketAddress &addr )
243
271
{
244
- return 0 ;
272
+ bool ipv6 = false ;
273
+ nsapi_addr_t nsapi_address = addr.get_addr ();
274
+ if (nsapi_address.version == NSAPI_IPv6)
275
+ {
276
+ ipv6 = true ;
277
+ }
278
+
279
+ return _cc3200_simplelink.connect_socket ((uint32_t )handle, ipv6, nsapi_address.bytes , addr.get_port ());
245
280
}
246
281
247
282
int CC3220SFInterface::socket_accept (void *handle, void **socket, SocketAddress *address)
@@ -251,22 +286,41 @@ int CC3220SFInterface::socket_accept(void *handle, void **socket, SocketAddress
251
286
252
287
int CC3220SFInterface::socket_send (void *handle, const void *data, unsigned size)
253
288
{
254
- return 0 ;
289
+ return _cc3200_simplelink. send (( uint32_t )handle, data, size) ;
255
290
}
256
291
257
292
int CC3220SFInterface::socket_recv (void *handle, void *data, unsigned size)
258
293
{
259
- return 0 ;
294
+ return _cc3200_simplelink. recv (( uint32_t )handle, data, size) ;
260
295
}
261
296
262
297
int CC3220SFInterface::socket_sendto (void *handle, const SocketAddress &address, const void *data, unsigned size)
263
298
{
264
- return 0 ;
299
+ bool ipv6 = false ;
300
+ nsapi_addr_t nsapi_address = address.get_addr ();
301
+ if (nsapi_address.version == NSAPI_IPv6)
302
+ {
303
+ ipv6 = true ;
304
+ }
305
+ return _cc3200_simplelink.sendto_socket ((uint32_t )handle, ipv6, data, size, nsapi_address.bytes , address.get_port ());
265
306
}
266
307
267
308
int CC3220SFInterface::socket_recvfrom (void *handle, SocketAddress *address, void *buffer, unsigned size)
268
309
{
269
- return 0 ;
310
+ bool ipv6 = false ;
311
+ if (address)
312
+ {
313
+ nsapi_addr_t nsapi_address = address->get_addr ();
314
+ if (nsapi_address.version == NSAPI_IPv6)
315
+ {
316
+ ipv6 = true ;
317
+ }
318
+ return _cc3200_simplelink.recvfrom ((uint32_t )handle, ipv6, buffer, size, nsapi_address.bytes , address->get_port ());
319
+ }
320
+ else
321
+ {
322
+ return _cc3200_simplelink.recv ((uint32_t )handle, buffer, size);
323
+ }
270
324
}
271
325
272
326
void CC3220SFInterface::socket_attach (void *handle, void (*callback)(void *), void *data)
0 commit comments