LingaoM commented on code in PR #20108:
URL: https://github.com/apache/nuttx/pull/20108#discussion_r3986742086


##########
arch/sim/src/sim/posix/sim_hosthcisocket.c:
##########
@@ -60,10 +64,139 @@ struct sockaddr_hci
   unsigned short  hci_channel;
 };
 
+enum bthcisock_target_e
+{
+  BTHCISOCK_TARGET_DEFAULT = 0,
+  BTHCISOCK_TARGET_BLUEZ,
+  BTHCISOCK_TARGET_UNIX
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static enum bthcisock_target_e g_bthcisock_target;
+static int g_bthcisock_devid;
+static char g_bthcisock_path[sizeof(((struct sockaddr_un *)0)->sun_path)];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int host_bthcisock_parse_devid(const char *target, int *devid)
+{
+  unsigned long value;
+  char *endptr;
+
+  if (strncmp(target, "hci", 3) != 0 || target[3] == '\0')
+    {
+      return -EINVAL;
+    }
+
+  target += 3;
+  if (target[0] == '\0')

Review Comment:
   Removed.



##########
arch/sim/src/sim/posix/sim_hosthcisocket.c:
##########
@@ -60,10 +64,139 @@ struct sockaddr_hci
   unsigned short  hci_channel;
 };
 
+enum bthcisock_target_e
+{
+  BTHCISOCK_TARGET_DEFAULT = 0,
+  BTHCISOCK_TARGET_BLUEZ,
+  BTHCISOCK_TARGET_UNIX
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static enum bthcisock_target_e g_bthcisock_target;
+static int g_bthcisock_devid;
+static char g_bthcisock_path[sizeof(((struct sockaddr_un *)0)->sun_path)];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int host_bthcisock_parse_devid(const char *target, int *devid)
+{
+  unsigned long value;
+  char *endptr;
+
+  if (strncmp(target, "hci", 3) != 0 || target[3] == '\0')
+    {
+      return -EINVAL;
+    }
+
+  target += 3;
+  if (target[0] == '\0')
+    {
+      return -EINVAL;
+    }
+
+  errno = 0;
+  value = strtoul(target, &endptr, 10);
+  if (errno != 0 || endptr == target || endptr[0] != '\0' ||
+      value > USHRT_MAX)
+    {
+      return -EINVAL;
+    }
+
+  *devid = (int)value;
+  return 0;
+}
+
+static int host_bthcisock_open_unix(const char *path)
+{
+  struct sockaddr_un addr;
+  size_t len;
+  int ret;
+  int fd;
+
+  len = strlen(path);
+  if (len == 0)
+    {
+      return -EINVAL;
+    }
+
+  if (len >= sizeof(addr.sun_path))
+    {
+      return -ENAMETOOLONG;
+    }
+
+  fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
+  if (fd < 0)
+    {
+      return fd;

Review Comment:
   Changed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to