You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2023/01/06 08:40:25 UTC

[GitHub] [nuttx] chengkai15 opened a new pull request, #8045: wireless/bluetooth: add interrupt_context hander for netsnoop

chengkai15 opened a new pull request, #8045:
URL: https://github.com/apache/nuttx/pull/8045

   Signed-off-by: chengkai <ch...@xiaomi.com>
   Change-Id: Icdadbeca9e11c21e73de2c4ef6d1434f3662edae
   
   ## Summary
   
   ## Impact
   
   ## Testing
   
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] chengkai15 commented on a diff in pull request #8045: wireless/bluetooth: add interrupt_context hander for netsnoop

Posted by GitBox <gi...@apache.org>.
chengkai15 commented on code in PR #8045:
URL: https://github.com/apache/nuttx/pull/8045#discussion_r1064115574


##########
net/utils/net_snoop.c:
##########
@@ -161,76 +161,128 @@ begin_packed_struct struct snoop_packet_header_s
  ****************************************************************************/
 
 /****************************************************************************
- * Name: snoop_dump_packet_header
+ * Name: snoop_fill_packet_header
  *
  * Description:
- *   This function fill snoop headr info.
+ *   This function fill snoop packet header info.
  *
  ****************************************************************************/
 
-static int snoop_dump_packet_header(FAR struct snoop_s *snoop,
-                                    uint32_t bytes, uint32_t drops,
-                                    uint32_t flags)
+static void snoop_fill_packet_header(FAR struct snoop_s *snoop,
+                                     uint32_t bytes, uint32_t drops,
+                                     uint32_t flags, FAR struct
+                                     snoop_packet_header_s *header)
 {
-  struct snoop_packet_header_s header;
-  int ret;
-
-  if (!snoop)
-    {
-      return -EINVAL;
-    }
+  struct timeval tv;
 
   switch (snoop->datalink)
     {
-    case SNOOP_DATALINK_HCI_UNENCAP:
-    case SNOOP_DATALINK_HCI_UART:
-    case SNOOP_DATALINK_HCI_BSCP:
-    case SNOOP_DATALINK_HCI_SERIAL:
-      {
-        struct timeval tv;
-
+      case SNOOP_DATALINK_HCI_UNENCAP:
+      case SNOOP_DATALINK_HCI_UART:
+      case SNOOP_DATALINK_HCI_BSCP:
+      case SNOOP_DATALINK_HCI_SERIAL:
         gettimeofday(&tv, NULL);
-        header.ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
-        header.flags = htobe32(flags);
+        header->ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
+        header->flags = htobe32(flags);
         break;
-      }
-
-    case SNOOP_DATALINK_TYPE_TOKENBUS:
-    case SNOOP_DATALINK_TYPE_TOKERING:
-    case SNOOP_DATALINK_TYPE_METRONET:
-    case SNOOP_DATALINK_TYPE_ETHERNET:
-    case SNOOP_DATALINK_TYPE_HDLC:
-    case SNOOP_DATALINK_TYPE_CHARSYNC:
-    case SNOOP_DATALINK_TYPE_IBMC2C:
-    case SNOOP_DATALINK_TYPE_FDDI:
-    case SNOOP_DATALINK_TYPE_OTHER:
-      {
-        struct timeval tv;
 
+      case SNOOP_DATALINK_TYPE_TOKENBUS:
+      case SNOOP_DATALINK_TYPE_TOKERING:
+      case SNOOP_DATALINK_TYPE_METRONET:
+      case SNOOP_DATALINK_TYPE_ETHERNET:
+      case SNOOP_DATALINK_TYPE_HDLC:
+      case SNOOP_DATALINK_TYPE_CHARSYNC:
+      case SNOOP_DATALINK_TYPE_IBMC2C:
+      case SNOOP_DATALINK_TYPE_FDDI:
+      case SNOOP_DATALINK_TYPE_OTHER:
         gettimeofday(&tv, NULL);
-        header.ts.ts_sec = htobe32(tv.tv_sec);
-        header.ts.ts_usec = htobe32(tv.tv_usec);
-        header.rec_len = htobe32(flags);
+        header->ts.ts_sec = htobe32(tv.tv_sec);
+        header->ts.ts_usec = htobe32(tv.tv_usec);
+        header->rec_len = htobe32(flags);
         break;
-      }
 
-    default:
-      {
-        return -EINVAL;
-      }
+      default:
+        DEBUGASSERT(false);
     }
 
-  header.orig_len = htobe32(bytes);
-  header.incl_len = htobe32(bytes);
-  header.cum_drops = htobe32(drops);
+  header->orig_len = htobe32(bytes);
+  header->incl_len = htobe32(bytes);
+  header->cum_drops = htobe32(drops);
+}
 
-  ret = file_write(&snoop->filep, &header, sizeof(header));
-  if (ret != sizeof(header))
+/****************************************************************************
+ * Name: snoop_flush
+ *
+ * Description:
+ *   This function could flush snoop buf into file.
+ *
+ ****************************************************************************/
+
+static int snoop_flush(FAR struct snoop_s *snoop)
+{
+  ssize_t ret;
+
+  if (snoop->next == 0)
     {
-      return ret < 0 ? ret : -EINVAL;
+      return 0;
     }
 
-  return OK;
+  do
+    {
+      ret = file_write(&snoop->filep, snoop->buf, snoop->next);
+      if (ret < 0)
+        {
+          break;
+        }
+
+      snoop->next -= ret;
+      memmove(snoop->buf, snoop->buf + ret, snoop->next);
+    }
+  while (snoop->next > 0);
+
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+  if (snoop->autosync)
+    {
+      ret = file_fsync(&snoop->filep);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: snoop_flush_lock
+ *
+ * Description:
+ *   Snoop flush atomic
+ *
+ ****************************************************************************/
+
+static int snoop_flush_lock(FAR struct snoop_s *snoop)
+{
+  irqstate_t flags;
+  int ret;
+
+  flags = enter_critical_section();
+  nxmutex_lock(&snoop->mutex);

Review Comment:
   snoop_flush could be called by interrupt context or app context. 
   when in interrupt context case, snoop_flush involves with file sync and write operations,which could switch from interrupt context to app context, causing data race. 
   so here need enter_critical_section and nxmutex_lock double check
   



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #8045: wireless/bluetooth: add interrupt_context hander for netsnoop

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #8045:
URL: https://github.com/apache/nuttx/pull/8045#discussion_r1063536073


##########
net/utils/net_snoop.c:
##########
@@ -161,76 +161,128 @@ begin_packed_struct struct snoop_packet_header_s
  ****************************************************************************/
 
 /****************************************************************************
- * Name: snoop_dump_packet_header
+ * Name: snoop_fill_packet_header
  *
  * Description:
- *   This function fill snoop headr info.
+ *   This function fill snoop packet header info.
  *
  ****************************************************************************/
 
-static int snoop_dump_packet_header(FAR struct snoop_s *snoop,
-                                    uint32_t bytes, uint32_t drops,
-                                    uint32_t flags)
+static void snoop_fill_packet_header(FAR struct snoop_s *snoop,
+                                     uint32_t bytes, uint32_t drops,
+                                     uint32_t flags, FAR struct
+                                     snoop_packet_header_s *header)
 {
-  struct snoop_packet_header_s header;
-  int ret;
-
-  if (!snoop)
-    {
-      return -EINVAL;
-    }
+  struct timeval tv;
 
   switch (snoop->datalink)
     {
-    case SNOOP_DATALINK_HCI_UNENCAP:
-    case SNOOP_DATALINK_HCI_UART:
-    case SNOOP_DATALINK_HCI_BSCP:
-    case SNOOP_DATALINK_HCI_SERIAL:
-      {
-        struct timeval tv;
-
+      case SNOOP_DATALINK_HCI_UNENCAP:
+      case SNOOP_DATALINK_HCI_UART:
+      case SNOOP_DATALINK_HCI_BSCP:
+      case SNOOP_DATALINK_HCI_SERIAL:
         gettimeofday(&tv, NULL);
-        header.ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
-        header.flags = htobe32(flags);
+        header->ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
+        header->flags = htobe32(flags);
         break;
-      }
-
-    case SNOOP_DATALINK_TYPE_TOKENBUS:
-    case SNOOP_DATALINK_TYPE_TOKERING:
-    case SNOOP_DATALINK_TYPE_METRONET:
-    case SNOOP_DATALINK_TYPE_ETHERNET:
-    case SNOOP_DATALINK_TYPE_HDLC:
-    case SNOOP_DATALINK_TYPE_CHARSYNC:
-    case SNOOP_DATALINK_TYPE_IBMC2C:
-    case SNOOP_DATALINK_TYPE_FDDI:
-    case SNOOP_DATALINK_TYPE_OTHER:
-      {
-        struct timeval tv;
 
+      case SNOOP_DATALINK_TYPE_TOKENBUS:
+      case SNOOP_DATALINK_TYPE_TOKERING:
+      case SNOOP_DATALINK_TYPE_METRONET:
+      case SNOOP_DATALINK_TYPE_ETHERNET:
+      case SNOOP_DATALINK_TYPE_HDLC:
+      case SNOOP_DATALINK_TYPE_CHARSYNC:
+      case SNOOP_DATALINK_TYPE_IBMC2C:
+      case SNOOP_DATALINK_TYPE_FDDI:
+      case SNOOP_DATALINK_TYPE_OTHER:
         gettimeofday(&tv, NULL);
-        header.ts.ts_sec = htobe32(tv.tv_sec);
-        header.ts.ts_usec = htobe32(tv.tv_usec);
-        header.rec_len = htobe32(flags);
+        header->ts.ts_sec = htobe32(tv.tv_sec);
+        header->ts.ts_usec = htobe32(tv.tv_usec);
+        header->rec_len = htobe32(flags);
         break;
-      }
 
-    default:
-      {
-        return -EINVAL;
-      }
+      default:
+        DEBUGASSERT(false);
     }
 
-  header.orig_len = htobe32(bytes);
-  header.incl_len = htobe32(bytes);
-  header.cum_drops = htobe32(drops);
+  header->orig_len = htobe32(bytes);
+  header->incl_len = htobe32(bytes);
+  header->cum_drops = htobe32(drops);
+}
 
-  ret = file_write(&snoop->filep, &header, sizeof(header));
-  if (ret != sizeof(header))
+/****************************************************************************
+ * Name: snoop_flush
+ *
+ * Description:
+ *   This function could flush snoop buf into file.
+ *
+ ****************************************************************************/
+
+static int snoop_flush(FAR struct snoop_s *snoop)
+{
+  ssize_t ret;
+
+  if (snoop->next == 0)
     {
-      return ret < 0 ? ret : -EINVAL;
+      return 0;
     }
 
-  return OK;
+  do
+    {
+      ret = file_write(&snoop->filep, snoop->buf, snoop->next);
+      if (ret < 0)
+        {
+          break;
+        }
+
+      snoop->next -= ret;
+      memmove(snoop->buf, snoop->buf + ret, snoop->next);
+    }
+  while (snoop->next > 0);
+
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+  if (snoop->autosync)
+    {
+      ret = file_fsync(&snoop->filep);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: snoop_flush_lock
+ *
+ * Description:
+ *   Snoop flush atomic
+ *
+ ****************************************************************************/
+
+static int snoop_flush_lock(FAR struct snoop_s *snoop)
+{
+  irqstate_t flags;
+  int ret;
+
+  flags = enter_critical_section();
+  nxmutex_lock(&snoop->mutex);

Review Comment:
   why use both critical section and nxmutex



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] chengkai15 commented on a diff in pull request #8045: wireless/bluetooth: add interrupt_context hander for netsnoop

Posted by GitBox <gi...@apache.org>.
chengkai15 commented on code in PR #8045:
URL: https://github.com/apache/nuttx/pull/8045#discussion_r1064120214


##########
net/utils/net_snoop.c:
##########
@@ -161,76 +161,128 @@ begin_packed_struct struct snoop_packet_header_s
  ****************************************************************************/
 
 /****************************************************************************
- * Name: snoop_dump_packet_header
+ * Name: snoop_fill_packet_header
  *
  * Description:
- *   This function fill snoop headr info.
+ *   This function fill snoop packet header info.
  *
  ****************************************************************************/
 
-static int snoop_dump_packet_header(FAR struct snoop_s *snoop,
-                                    uint32_t bytes, uint32_t drops,
-                                    uint32_t flags)
+static void snoop_fill_packet_header(FAR struct snoop_s *snoop,
+                                     uint32_t bytes, uint32_t drops,
+                                     uint32_t flags, FAR struct
+                                     snoop_packet_header_s *header)
 {
-  struct snoop_packet_header_s header;
-  int ret;
-
-  if (!snoop)
-    {
-      return -EINVAL;
-    }
+  struct timeval tv;
 
   switch (snoop->datalink)
     {
-    case SNOOP_DATALINK_HCI_UNENCAP:
-    case SNOOP_DATALINK_HCI_UART:
-    case SNOOP_DATALINK_HCI_BSCP:
-    case SNOOP_DATALINK_HCI_SERIAL:
-      {
-        struct timeval tv;
-
+      case SNOOP_DATALINK_HCI_UNENCAP:
+      case SNOOP_DATALINK_HCI_UART:
+      case SNOOP_DATALINK_HCI_BSCP:
+      case SNOOP_DATALINK_HCI_SERIAL:
         gettimeofday(&tv, NULL);
-        header.ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
-        header.flags = htobe32(flags);
+        header->ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
+        header->flags = htobe32(flags);
         break;
-      }
-
-    case SNOOP_DATALINK_TYPE_TOKENBUS:
-    case SNOOP_DATALINK_TYPE_TOKERING:
-    case SNOOP_DATALINK_TYPE_METRONET:
-    case SNOOP_DATALINK_TYPE_ETHERNET:
-    case SNOOP_DATALINK_TYPE_HDLC:
-    case SNOOP_DATALINK_TYPE_CHARSYNC:
-    case SNOOP_DATALINK_TYPE_IBMC2C:
-    case SNOOP_DATALINK_TYPE_FDDI:
-    case SNOOP_DATALINK_TYPE_OTHER:
-      {
-        struct timeval tv;
 
+      case SNOOP_DATALINK_TYPE_TOKENBUS:
+      case SNOOP_DATALINK_TYPE_TOKERING:
+      case SNOOP_DATALINK_TYPE_METRONET:
+      case SNOOP_DATALINK_TYPE_ETHERNET:
+      case SNOOP_DATALINK_TYPE_HDLC:
+      case SNOOP_DATALINK_TYPE_CHARSYNC:
+      case SNOOP_DATALINK_TYPE_IBMC2C:
+      case SNOOP_DATALINK_TYPE_FDDI:
+      case SNOOP_DATALINK_TYPE_OTHER:
         gettimeofday(&tv, NULL);
-        header.ts.ts_sec = htobe32(tv.tv_sec);
-        header.ts.ts_usec = htobe32(tv.tv_usec);
-        header.rec_len = htobe32(flags);
+        header->ts.ts_sec = htobe32(tv.tv_sec);
+        header->ts.ts_usec = htobe32(tv.tv_usec);
+        header->rec_len = htobe32(flags);
         break;
-      }
 
-    default:
-      {
-        return -EINVAL;
-      }
+      default:
+        DEBUGASSERT(false);
     }
 
-  header.orig_len = htobe32(bytes);
-  header.incl_len = htobe32(bytes);
-  header.cum_drops = htobe32(drops);
+  header->orig_len = htobe32(bytes);
+  header->incl_len = htobe32(bytes);
+  header->cum_drops = htobe32(drops);
+}
 
-  ret = file_write(&snoop->filep, &header, sizeof(header));
-  if (ret != sizeof(header))
+/****************************************************************************
+ * Name: snoop_flush
+ *
+ * Description:
+ *   This function could flush snoop buf into file.
+ *
+ ****************************************************************************/
+
+static int snoop_flush(FAR struct snoop_s *snoop)
+{
+  ssize_t ret;
+
+  if (snoop->next == 0)
     {
-      return ret < 0 ? ret : -EINVAL;
+      return 0;
     }
 
-  return OK;
+  do
+    {
+      ret = file_write(&snoop->filep, snoop->buf, snoop->next);
+      if (ret < 0)
+        {
+          break;
+        }
+
+      snoop->next -= ret;
+      memmove(snoop->buf, snoop->buf + ret, snoop->next);
+    }
+  while (snoop->next > 0);
+
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+  if (snoop->autosync)
+    {
+      ret = file_fsync(&snoop->filep);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: snoop_flush_lock
+ *
+ * Description:
+ *   Snoop flush atomic
+ *
+ ****************************************************************************/
+
+static int snoop_flush_lock(FAR struct snoop_s *snoop)
+{
+  irqstate_t flags;
+  int ret;
+
+  flags = enter_critical_section();
+  nxmutex_lock(&snoop->mutex);
+  ret = snoop_flush(snoop);
+  nxmutex_unlock(&snoop->mutex);
+  leave_critical_section(flags);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: snoop_flush_work
+ *
+ * Description:
+ *   Do snoop flush work.
+ *

Review Comment:
   done



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] acassis commented on a diff in pull request #8045: wireless/bluetooth: add interrupt_context hander for netsnoop

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #8045:
URL: https://github.com/apache/nuttx/pull/8045#discussion_r1063539615


##########
net/utils/net_snoop.c:
##########
@@ -161,76 +161,128 @@ begin_packed_struct struct snoop_packet_header_s
  ****************************************************************************/
 
 /****************************************************************************
- * Name: snoop_dump_packet_header
+ * Name: snoop_fill_packet_header
  *
  * Description:
- *   This function fill snoop headr info.
+ *   This function fill snoop packet header info.
  *
  ****************************************************************************/
 
-static int snoop_dump_packet_header(FAR struct snoop_s *snoop,
-                                    uint32_t bytes, uint32_t drops,
-                                    uint32_t flags)
+static void snoop_fill_packet_header(FAR struct snoop_s *snoop,
+                                     uint32_t bytes, uint32_t drops,
+                                     uint32_t flags, FAR struct
+                                     snoop_packet_header_s *header)
 {
-  struct snoop_packet_header_s header;
-  int ret;
-
-  if (!snoop)
-    {
-      return -EINVAL;
-    }
+  struct timeval tv;
 
   switch (snoop->datalink)
     {
-    case SNOOP_DATALINK_HCI_UNENCAP:
-    case SNOOP_DATALINK_HCI_UART:
-    case SNOOP_DATALINK_HCI_BSCP:
-    case SNOOP_DATALINK_HCI_SERIAL:
-      {
-        struct timeval tv;
-
+      case SNOOP_DATALINK_HCI_UNENCAP:
+      case SNOOP_DATALINK_HCI_UART:
+      case SNOOP_DATALINK_HCI_BSCP:
+      case SNOOP_DATALINK_HCI_SERIAL:
         gettimeofday(&tv, NULL);
-        header.ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
-        header.flags = htobe32(flags);
+        header->ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
+        header->flags = htobe32(flags);
         break;
-      }
-
-    case SNOOP_DATALINK_TYPE_TOKENBUS:
-    case SNOOP_DATALINK_TYPE_TOKERING:
-    case SNOOP_DATALINK_TYPE_METRONET:
-    case SNOOP_DATALINK_TYPE_ETHERNET:
-    case SNOOP_DATALINK_TYPE_HDLC:
-    case SNOOP_DATALINK_TYPE_CHARSYNC:
-    case SNOOP_DATALINK_TYPE_IBMC2C:
-    case SNOOP_DATALINK_TYPE_FDDI:
-    case SNOOP_DATALINK_TYPE_OTHER:
-      {
-        struct timeval tv;
 
+      case SNOOP_DATALINK_TYPE_TOKENBUS:
+      case SNOOP_DATALINK_TYPE_TOKERING:
+      case SNOOP_DATALINK_TYPE_METRONET:
+      case SNOOP_DATALINK_TYPE_ETHERNET:
+      case SNOOP_DATALINK_TYPE_HDLC:
+      case SNOOP_DATALINK_TYPE_CHARSYNC:
+      case SNOOP_DATALINK_TYPE_IBMC2C:
+      case SNOOP_DATALINK_TYPE_FDDI:
+      case SNOOP_DATALINK_TYPE_OTHER:
         gettimeofday(&tv, NULL);
-        header.ts.ts_sec = htobe32(tv.tv_sec);
-        header.ts.ts_usec = htobe32(tv.tv_usec);
-        header.rec_len = htobe32(flags);
+        header->ts.ts_sec = htobe32(tv.tv_sec);
+        header->ts.ts_usec = htobe32(tv.tv_usec);
+        header->rec_len = htobe32(flags);
         break;
-      }
 
-    default:
-      {
-        return -EINVAL;
-      }
+      default:
+        DEBUGASSERT(false);
     }
 
-  header.orig_len = htobe32(bytes);
-  header.incl_len = htobe32(bytes);
-  header.cum_drops = htobe32(drops);
+  header->orig_len = htobe32(bytes);
+  header->incl_len = htobe32(bytes);
+  header->cum_drops = htobe32(drops);
+}
 
-  ret = file_write(&snoop->filep, &header, sizeof(header));
-  if (ret != sizeof(header))
+/****************************************************************************
+ * Name: snoop_flush
+ *
+ * Description:
+ *   This function could flush snoop buf into file.
+ *

Review Comment:
   Please include Parameter and Return info



##########
net/utils/net_snoop.c:
##########
@@ -161,76 +161,128 @@ begin_packed_struct struct snoop_packet_header_s
  ****************************************************************************/
 
 /****************************************************************************
- * Name: snoop_dump_packet_header
+ * Name: snoop_fill_packet_header
  *
  * Description:
- *   This function fill snoop headr info.
+ *   This function fill snoop packet header info.
  *
  ****************************************************************************/
 
-static int snoop_dump_packet_header(FAR struct snoop_s *snoop,
-                                    uint32_t bytes, uint32_t drops,
-                                    uint32_t flags)
+static void snoop_fill_packet_header(FAR struct snoop_s *snoop,
+                                     uint32_t bytes, uint32_t drops,
+                                     uint32_t flags, FAR struct
+                                     snoop_packet_header_s *header)
 {
-  struct snoop_packet_header_s header;
-  int ret;
-
-  if (!snoop)
-    {
-      return -EINVAL;
-    }
+  struct timeval tv;
 
   switch (snoop->datalink)
     {
-    case SNOOP_DATALINK_HCI_UNENCAP:
-    case SNOOP_DATALINK_HCI_UART:
-    case SNOOP_DATALINK_HCI_BSCP:
-    case SNOOP_DATALINK_HCI_SERIAL:
-      {
-        struct timeval tv;
-
+      case SNOOP_DATALINK_HCI_UNENCAP:
+      case SNOOP_DATALINK_HCI_UART:
+      case SNOOP_DATALINK_HCI_BSCP:
+      case SNOOP_DATALINK_HCI_SERIAL:
         gettimeofday(&tv, NULL);
-        header.ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
-        header.flags = htobe32(flags);
+        header->ts_usec = htobe64(SNOOP_EPOCH_USEC(tv));
+        header->flags = htobe32(flags);
         break;
-      }
-
-    case SNOOP_DATALINK_TYPE_TOKENBUS:
-    case SNOOP_DATALINK_TYPE_TOKERING:
-    case SNOOP_DATALINK_TYPE_METRONET:
-    case SNOOP_DATALINK_TYPE_ETHERNET:
-    case SNOOP_DATALINK_TYPE_HDLC:
-    case SNOOP_DATALINK_TYPE_CHARSYNC:
-    case SNOOP_DATALINK_TYPE_IBMC2C:
-    case SNOOP_DATALINK_TYPE_FDDI:
-    case SNOOP_DATALINK_TYPE_OTHER:
-      {
-        struct timeval tv;
 
+      case SNOOP_DATALINK_TYPE_TOKENBUS:
+      case SNOOP_DATALINK_TYPE_TOKERING:
+      case SNOOP_DATALINK_TYPE_METRONET:
+      case SNOOP_DATALINK_TYPE_ETHERNET:
+      case SNOOP_DATALINK_TYPE_HDLC:
+      case SNOOP_DATALINK_TYPE_CHARSYNC:
+      case SNOOP_DATALINK_TYPE_IBMC2C:
+      case SNOOP_DATALINK_TYPE_FDDI:
+      case SNOOP_DATALINK_TYPE_OTHER:
         gettimeofday(&tv, NULL);
-        header.ts.ts_sec = htobe32(tv.tv_sec);
-        header.ts.ts_usec = htobe32(tv.tv_usec);
-        header.rec_len = htobe32(flags);
+        header->ts.ts_sec = htobe32(tv.tv_sec);
+        header->ts.ts_usec = htobe32(tv.tv_usec);
+        header->rec_len = htobe32(flags);
         break;
-      }
 
-    default:
-      {
-        return -EINVAL;
-      }
+      default:
+        DEBUGASSERT(false);
     }
 
-  header.orig_len = htobe32(bytes);
-  header.incl_len = htobe32(bytes);
-  header.cum_drops = htobe32(drops);
+  header->orig_len = htobe32(bytes);
+  header->incl_len = htobe32(bytes);
+  header->cum_drops = htobe32(drops);
+}
 
-  ret = file_write(&snoop->filep, &header, sizeof(header));
-  if (ret != sizeof(header))
+/****************************************************************************
+ * Name: snoop_flush
+ *
+ * Description:
+ *   This function could flush snoop buf into file.
+ *
+ ****************************************************************************/
+
+static int snoop_flush(FAR struct snoop_s *snoop)
+{
+  ssize_t ret;
+
+  if (snoop->next == 0)
     {
-      return ret < 0 ? ret : -EINVAL;
+      return 0;
     }
 
-  return OK;
+  do
+    {
+      ret = file_write(&snoop->filep, snoop->buf, snoop->next);
+      if (ret < 0)
+        {
+          break;
+        }
+
+      snoop->next -= ret;
+      memmove(snoop->buf, snoop->buf + ret, snoop->next);
+    }
+  while (snoop->next > 0);
+
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+  if (snoop->autosync)
+    {
+      ret = file_fsync(&snoop->filep);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: snoop_flush_lock
+ *
+ * Description:
+ *   Snoop flush atomic
+ *
+ ****************************************************************************/
+
+static int snoop_flush_lock(FAR struct snoop_s *snoop)
+{
+  irqstate_t flags;
+  int ret;
+
+  flags = enter_critical_section();
+  nxmutex_lock(&snoop->mutex);
+  ret = snoop_flush(snoop);
+  nxmutex_unlock(&snoop->mutex);
+  leave_critical_section(flags);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: snoop_flush_work
+ *
+ * Description:
+ *   Do snoop flush work.
+ *

Review Comment:
   Ditto



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 merged pull request #8045: wireless/bluetooth: add interrupt_context hander for netsnoop

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #8045:
URL: https://github.com/apache/nuttx/pull/8045


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org