Skip to content

Commit 688a9f7

Browse files
authored
Merge pull request #3755 from luhuadong/develop
[at_socket] support alloc socket dynamically with at device
2 parents e22bbf9 + f56af40 commit 688a9f7

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

components/net/at/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ if RT_USING_AT
8282

8383
config AT_SW_VERSION_NUM
8484
hex
85-
default 0x10300
85+
default 0x10301
8686
help
8787
software module version number
8888

components/net/at/at_socket/at_socket.c

+15-8
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static int alloc_empty_socket(rt_slist_t *l)
302302
return idx;
303303
}
304304

305-
static struct at_socket *alloc_socket_by_device(struct at_device *device)
305+
static struct at_socket *alloc_socket_by_device(struct at_device *device, enum at_socket_type type)
306306
{
307307
static rt_mutex_t at_slock = RT_NULL;
308308
struct at_socket *sock = RT_NULL;
@@ -323,14 +323,21 @@ static struct at_socket *alloc_socket_by_device(struct at_device *device)
323323
rt_mutex_take(at_slock, RT_WAITING_FOREVER);
324324

325325
/* find an empty at socket entry */
326-
for (idx = 0; idx < device->class->socket_num && device->sockets[idx].magic; idx++);
326+
if (device->class->socket_ops->at_socket != RT_NULL)
327+
{
328+
idx = device->class->socket_ops->at_socket(device, type);
329+
}
330+
else
331+
{
332+
for (idx = 0; idx < device->class->socket_num && device->sockets[idx].magic; idx++);
333+
}
327334

328335
/* can't find an empty protocol family entry */
329-
if (idx == device->class->socket_num)
336+
if (idx < 0 || idx >= device->class->socket_num)
330337
{
331338
goto __err;
332339
}
333-
340+
334341
sock = &(device->sockets[idx]);
335342
/* the socket descriptor is the number of sockte lists */
336343
sock->socket = alloc_empty_socket(&(sock->list));
@@ -374,7 +381,7 @@ static struct at_socket *alloc_socket_by_device(struct at_device *device)
374381
return RT_NULL;
375382
}
376383

377-
static struct at_socket *alloc_socket(void)
384+
static struct at_socket *alloc_socket(enum at_socket_type type)
378385
{
379386
extern struct netdev *netdev_default;
380387
struct netdev *netdev = RT_NULL;
@@ -401,7 +408,7 @@ static struct at_socket *alloc_socket(void)
401408
return RT_NULL;
402409
}
403410

404-
return alloc_socket_by_device(device);
411+
return alloc_socket_by_device(device, type);
405412
}
406413

407414
static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, const char *buff, size_t bfsz);
@@ -433,7 +440,7 @@ int at_socket(int domain, int type, int protocol)
433440
}
434441

435442
/* allocate and initialize a new AT socket */
436-
sock = alloc_socket();
443+
sock = alloc_socket(socket_type);
437444
if (sock == RT_NULL)
438445
{
439446
return -1;
@@ -615,7 +622,7 @@ int at_bind(int socket, const struct sockaddr *name, socklen_t namelen)
615622
}
616623

617624
/* allocate new socket */
618-
new_sock = alloc_socket_by_device(new_device);
625+
new_sock = alloc_socket_by_device(new_device, type);
619626
if (new_sock == RT_NULL)
620627
{
621628
return -1;

components/net/at/at_socket/at_socket.h

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef enum
5656
} at_socket_evt_t;
5757

5858
struct at_socket;
59+
struct at_device;
5960

6061
typedef void (*at_evt_cb_t)(struct at_socket *socket, at_socket_evt_t event, const char *buff, size_t bfsz);
6162

@@ -70,6 +71,7 @@ struct at_socket_ops
7071
int (*at_send)(struct at_socket *socket, const char *buff, size_t bfsz, enum at_socket_type type);
7172
int (*at_domain_resolve)(const char *name, char ip[16]);
7273
void (*at_set_event_cb)(at_socket_evt_t event, at_evt_cb_t cb);
74+
int (*at_socket)(struct at_device *device, enum at_socket_type type);
7375
};
7476

7577
/* AT receive package list structure */

components/net/at/include/at.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
extern "C" {
1919
#endif
2020

21-
#define AT_SW_VERSION "1.3.0"
21+
#define AT_SW_VERSION "1.3.1"
2222

2323
#define AT_CMD_NAME_LEN 16
2424
#define AT_END_MARK_LEN 4

0 commit comments

Comments
 (0)