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



##########
File path: arch/sim/src/sim/up_hcisocket.c
##########
@@ -0,0 +1,235 @@
+/****************************************************************************
+ * 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/socket.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <nuttx/wireless/bluetooth/bt_driver.h>
+#include <nuttx/net/bluetooth.h>
+
+#include "up_internal.h"
+#include "up_hcisocket_host.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* HCI data types as defined by Linux Kernel */
+
+#define HCI_COMMAND_PKT   0x01
+#define HCI_ACLDATA_PKT   0x02
+#define HCI_SCODATA_PKT   0x03
+#define HCI_EVENT_PKT     0x04
+#define HCI_ISODATA_PKT   0x05
+#define HCI_DIAG_PKT      0xf0
+#define HCI_VENDOR_PKT    0xff
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int bthcisock_send(FAR const struct bt_driver_s *dev,
+                          FAR struct bt_buf_s *buf);
+static int bthcisock_open(FAR const struct bt_driver_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct bt_driver_s g_bt_hcisock =
+{
+  0,               /* head_reserve */
+  bthcisock_open,  /* open */
+  bthcisock_send   /* send */
+};
+
+static int bt_fd = -1;       /* Host HCI socket fd */
+static int host_dev_id = 0;  /* Host HCI interface number */
+
+/* This frame buffer is used to handle the frame read from the host
+ * NOTE: This is smaller than what the Linux kernel lists as its max frame
+ * so we will need to resolve that at some point.
+ */
+
+static uint8_t bt_frame[BLUETOOTH_MAX_FRAMELEN + 1];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int bthcisock_send(FAR const struct bt_driver_s *dev,
+                          FAR struct bt_buf_s *buf)
+{
+  uint8_t pkt_type;
+
+  switch (buf->type)
+    {
+      case BT_CMD:
+        {
+          pkt_type = HCI_COMMAND_PKT;
+          break;
+        }
+
+      case BT_ACL_OUT:
+        {
+          pkt_type = HCI_ACLDATA_PKT;
+          break;
+        }
+
+      default:
+        {
+          wlerr("Unexpected HCI packet type %d", buf->type);
+          return buf->len;
+        }
+    }
+
+  if (bthcisock_host_send(bt_fd, pkt_type, buf->data, buf->len) < 0)
+    {
+      return -1;
+    }
+
+  bthcisock_read();

Review comment:
       should we centralize the read to the idle loop?




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