Go to the documentation of this file.
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
115 pcap_if_t *deviceList;
116 struct bpf_program filerCode;
118 char_t errorBuffer[PCAP_ERRBUF_SIZE];
120 #if (NET_RTOS_SUPPORT == ENABLED)
125 TRACE_INFO(
"Initializing PCAP driver...\r\n");
134 printf(
"Failed to allocate context!\r\n");
146 ret = pcap_findalldevs(&deviceList, errorBuffer);
152 printf(
"Failed to list devices!\r\n");
162 if(deviceList == NULL)
165 printf(
"No network adapter found!\r\n");
178 printf(
"Network adapters:\r\n");
185 while(device != NULL)
188 printf(
" %-2u", i + 1);
192 if(device->name != NULL)
194 printf(
" %-8s", device->name);
198 if(device->description != NULL)
200 printf(
" %s\r\n", device->description);
208 device = device->next;
213 if(interface->phyAddr >= 1 && interface->phyAddr <= i)
215 j = interface->phyAddr;
221 printf(
"Select network adapter for %s interface (1-%u):", interface->name, i);
237 for(i = 1; i < j; i++)
239 device = device->next;
243 context->
handle = pcap_open_live(device->name, 65535,
247 if(context->
handle == NULL)
250 printf(
"Failed to open device!\r\n");
253 pcap_freealldevs(deviceList);
261 pcap_freealldevs(deviceList);
264 osSprintf(filterExpr,
"!(ether src %02x:%02x:%02x:%02x:%02x:%02x) && "
265 "((ether dst %02x:%02x:%02x:%02x:%02x:%02x) || (ether broadcast) || (ether multicast))",
266 interface->macAddr.b[0], interface->macAddr.b[1], interface->macAddr.b[2],
267 interface->macAddr.b[3], interface->macAddr.b[4], interface->macAddr.b[5],
268 interface->macAddr.b[0], interface->macAddr.b[1], interface->macAddr.b[2],
269 interface->macAddr.b[3], interface->macAddr.b[4], interface->macAddr.b[5]);
272 ret = pcap_compile(context->
handle, &filerCode, filterExpr, 1, 0);
278 printf(
"Failed to compile filter!\r\n");
281 pcap_close(context->
handle);
289 ret = pcap_setfilter(context->
handle, &filerCode);
295 printf(
"Failed to set filter!\r\n");
298 pcap_close(context->
handle);
305 #if (NET_RTOS_SUPPORT == ENABLED)
313 printf(
"Failed to create task!\r\n");
316 pcap_close(context->
handle);
482 struct pcap_pkthdr *header;
492 ret = pcap_next_ex(context->
handle, &header, &
data);
504 if(interface->linkState)
521 interface->nicEvent =
TRUE;
530 #if (NET_RTOS_SUPPORT == DISABLED)
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
void pcapDriverTick(NetInterface *interface)
PCAP timer handler.
#define PCAP_DRIVER_MAX_PACKET_SIZE
size_t netBufferRead(void *dest, const NetBuffer *src, size_t srcOffset, size_t length)
Read data from a multi-part buffer.
Structure describing a buffer that spans multiple chunks.
#define OS_INVALID_TASK_ID
void pcapDriverEventHandler(NetInterface *interface)
PCAP event handler.
const NicDriver pcapDriver
PCAP driver.
void nicProcessPacket(NetInterface *interface, uint8_t *packet, size_t length, NetRxAncillary *ancillary)
Handle a packet received by the network controller.
__weak_func void * osAllocMem(size_t size)
Allocate a memory block.
error_t pcapDriverInit(NetInterface *interface)
PCAP driver initialization.
#define osMemcpy(dest, src, length)
#define osSprintf(dest,...)
void(* OsTaskCode)(void *arg)
Task routine.
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
@ ERROR_FAILURE
Generic error code.
#define PCAP_DRIVER_TIMEOUT
PcapDriverPacket queue[PCAP_DRIVER_QUEUE_SIZE]
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
void pcapDriverEnableIrq(NetInterface *interface)
Enable interrupts.
uint8_t data[PCAP_DRIVER_MAX_PACKET_SIZE]
error_t pcapDriverUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
#define PCAP_DRIVER_QUEUE_SIZE
thread_t * OsTaskId
Task identifier.
#define osMemset(p, value, length)
void pcapDriverDisableIrq(NetInterface *interface)
Disable interrupts.
error_t pcapDriverSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
void pcapDriverTask(NetInterface *interface)
PCAP receive task.
@ NIC_TYPE_ETHERNET
Ethernet interface.