xiaoxiang781216 commented on a change in pull request #1655:
URL: https://github.com/apache/incubator-nuttx/pull/1655#discussion_r478188288



##########
File path: arch/sim/src/sim/up_hcisocket_host.c
##########
@@ -0,0 +1,181 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_hcisocket.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "up_internal.h"
+#include "up_hcisocket_host.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BTPROTO_HCI 1
+
+#define HCI_CHANNEL_RAW   0
+#define HCI_CHANNEL_USER  1
+
+#define HCIDEVDOWN  0x400448ca
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sockaddr_hci
+{
+  sa_family_t     hci_family;
+  unsigned short  hci_dev;
+  unsigned short  hci_channel;
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: bthcisock_host_send
+ *
+ * Description:
+ *   Send a Bluetooth packet out via the host user socket.
+ *
+ * Input Parameters:
+ *   fd: Host Bluetooth socket fd
+ *   pkt_type: Packet type as known to the Linux Bluetooth stack
+ *   data: Pointer to the HCI packet
+ *   len: Length of packet
+ *
+ * Returned Value:
+ *   Zero is returned on success; a negated errno value is returned on any
+ *   failure.
+ *
+ ****************************************************************************/
+
+int bthcisock_host_send(int fd, uint8_t pkt_type, uint8_t *data, size_t len)
+{
+  struct iovec iv[2];
+
+  iv[0].iov_base = &pkt_type;
+  iv[0].iov_len = 1;
+  iv[1].iov_base = data;
+  iv[1].iov_len = len;
+
+  while (writev(fd, iv, 2) < 0)
+    {
+      if (errno == EAGAIN || errno == EINTR)
+        continue;
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: bthcisock_host_read
+ *
+ * Description:
+ *   Read from the Host HCI socket interface.
+ *
+ * Input Parameters:
+ *   fd: Host Bluetooth socket fd
+ *   data: Pointer to store HCI packet
+ *   len: Maximum length of packet
+ *
+ * Returned Value:
+ *   Zero is returned on success; a negated errno value is returned on any
+ *   failure.
+ *
+ ****************************************************************************/
+
+int bthcisock_host_read(int fd, uint8_t *type, void *buf, size_t len)
+{
+  int err;
+  while ((err = recv(fd, buf, len, 0)) < 0 && (errno == EINTR));

Review comment:
       Does it make sense to use readv so the first byte of buf don't contain 
the type? and bthcisock_host_read is symetric with bthcisock_host_send.

##########
File path: arch/sim/src/sim/up_idle.c
##########
@@ -116,4 +116,8 @@ void up_idle(void)
 
   up_timer_update();
 #endif
+
+#ifdef CONFIG_SIM_HCISOCKET

Review comment:
       it's better to move bthcisock_loop before up_timer_update because 
up_timer_update will:
   1.Update the timestamp to the next tick
   2.May switch the execution to the high priority task.




----------------------------------------------------------------
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.

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


Reply via email to