diff options
| author | [email protected] <[email protected]> | 2012-11-13 01:44:34 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-11-13 01:44:34 +0000 |
| commit | 0f111d6e470b7fdcec71967f456eaa7b1e0e142b (patch) | |
| tree | 70e2d7b9cd3965f71827286660130258e80744f1 | |
| parent | b04c308524b70147eeb255b2e53d6af505f75b21 (diff) | |
merge prife's patch for exclusive access pcap driver.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2404 bbd45198-f89e-11dd-88c7-29a3b14d5316
| -rw-r--r-- | bsp/simulator/pcap/pcap_netif.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/bsp/simulator/pcap/pcap_netif.c b/bsp/simulator/pcap/pcap_netif.c index 7ddfe4a1b5..7c9aeac86e 100644 --- a/bsp/simulator/pcap/pcap_netif.c +++ b/bsp/simulator/pcap/pcap_netif.c @@ -1,3 +1,19 @@ +/*
+ * File : pcap_netif.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2012, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2012-11-05 Bernard the first version
+ * 2012-11-13 Bernard merge prife's patch for exclusive
+ * access pcap driver.
+ */
+
#ifdef _TIME_T_DEFINED
#undef _TIME_T_DEFINED
#endif
@@ -56,13 +72,16 @@ static void pcap_thread_entry(void* parameter) NETIF_PCAP(&pcap_netif_device) = tap;
- // pcap_loop(tap, 0, packet_handler, NULL);
/* Read the packets */
- while((res = pcap_next_ex(tap, &header, &pkt_data)) >= 0)
+ while (1)
{
struct eth_device* eth;
struct pbuf *p;
+ rt_enter_critical();
+ res = pcap_next_ex(tap, &header, &pkt_data);
+ rt_exit_critical();
+
if (res == 0) continue;
eth = (struct eth_device*) &pcap_netif_device;
@@ -113,6 +132,7 @@ static rt_err_t pcap_netif_init(rt_device_t dev) for(d = alldevs, i = 0; i < inum-1 ;d = d->next, i++);
{
+ rt_kprintf("Select (%s) as network interface\n", d->description);
packet_mb = rt_mb_create("pcap", 64, RT_IPC_FLAG_FIFO);
tid = rt_thread_create("pcap", pcap_thread_entry, d,
2048, RT_THREAD_PRIORITY_MAX - 1, 10);
@@ -180,6 +200,7 @@ rt_err_t pcap_netif_tx( rt_device_t dev, struct pbuf* p) rt_uint8_t buf[2048];
rt_err_t result = RT_EOK;
pcap_t *tap;
+ int res;
tap = NETIF_PCAP(dev);
@@ -196,7 +217,11 @@ rt_err_t pcap_netif_tx( rt_device_t dev, struct pbuf* p) q = q->next;
}
- if (pcap_sendpacket(tap, buf, p->tot_len) != 0)
+ rt_enter_critical();
+ res = pcap_sendpacket(tap, buf, p->tot_len);
+ rt_exit_critical();
+
+ if (res != 0)
{
rt_kprintf("Error sending the packet: \n", pcap_geterr(tap));
result = -RT_ERROR;
|
