summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorchenyong <[email protected]>2019-05-28 11:03:36 +0800
committerchenyong <[email protected]>2019-05-28 16:25:42 +0800
commit1f9a668607be01db25695bdfa34f90905de3e4c3 (patch)
tree4b19575e23c727599413b6b4083c0b3e9f5e7b71 /components
parentb5ad12573fe92b710eefc862b1d0891e97a25d18 (diff)
[net][at] Fix socket create failed issue when default netdev mismatch.
Signed-off-by: chenyong <[email protected]>
Diffstat (limited to 'components')
-rw-r--r--components/net/at/at_socket/at_socket.c11
-rw-r--r--components/net/netdev/include/netdev.h1
-rw-r--r--components/net/netdev/src/netdev.c14
3 files changed, 21 insertions, 5 deletions
diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c
index a3b36a06ae..993ec33506 100644
--- a/components/net/at/at_socket/at_socket.c
+++ b/components/net/at/at_socket/at_socket.c
@@ -359,20 +359,21 @@ __err:
return RT_NULL;
}
-static struct at_socket *alloc_socket(int domain)
+static struct at_socket *alloc_socket(void)
{
extern struct netdev *netdev_default;
struct netdev *netdev = RT_NULL;
struct at_device *device = RT_NULL;
- if (netdev_default && netdev_is_up(netdev_default))
+ if (netdev_default && netdev_is_up(netdev_default) &&
+ netdev_family_get(netdev_default) == AF_AT)
{
netdev = netdev_default;
}
else
{
- /* get network interface device by protocol family */
- netdev = netdev_get_by_family(domain);
+ /* get network interface device by protocol family AF_AT */
+ netdev = netdev_get_by_family(AF_AT);
if (netdev == RT_NULL)
{
return RT_NULL;
@@ -414,7 +415,7 @@ int at_socket(int domain, int type, int protocol)
}
/* allocate and initialize a new AT socket */
- sock = alloc_socket(domain);
+ sock = alloc_socket();
if (sock == RT_NULL)
{
return -1;
diff --git a/components/net/netdev/include/netdev.h b/components/net/netdev/include/netdev.h
index e9d8e38658..0be2a2bda3 100644
--- a/components/net/netdev/include/netdev.h
+++ b/components/net/netdev/include/netdev.h
@@ -138,6 +138,7 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr);
struct netdev *netdev_get_by_name(const char *name);
#ifdef RT_USING_SAL
struct netdev *netdev_get_by_family(int family);
+int netdev_family_get(struct netdev *netdev);
#endif /* RT_USING_SAL */
/* Set default network interface device in list */
diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c
index 71b1ec7ccd..5f49a46f17 100644
--- a/components/net/netdev/src/netdev.c
+++ b/components/net/netdev/src/netdev.c
@@ -294,6 +294,20 @@ struct netdev *netdev_get_by_family(int family)
return RT_NULL;
}
+/**
+ * This function will get the family type from network interface device
+ *
+ * @param netdev network interface device object
+ *
+ * @return the network interface device family type
+ */
+int netdev_family_get(struct netdev *netdev)
+{
+ RT_ASSERT(netdev);
+
+ return ((struct sal_proto_family *)netdev->sal_user_data)->family;
+}
+
#endif /* RT_USING_SAL */
/**