src/stack/nimu/nimu.c File Reference

Implements the network interface management code. This is required when the NDK Core stack has been built to be able to handle multiple drivers. The file has the code which resides in the data path. More...


Functions

void NIMUSendPacket (HANDLE hIF, PBM_Pkt *pPkt)
int NIMUAddHeader (NETIF_DEVICE *ptr_device, HANDLE hPkt, UINT8 *dst_mac, UINT8 *src_mac, UINT16 protocol)
void NIMUPacketService (void)
void NIMUPacketServiceCheck (int fEvents)
int NIMUReceivePacket (PBM_Handle hPkt)
PBM_Pkt * NIMUCreatePacket (uint packet_size)
int NIMUAddEthernetHeader (NETIF_DEVICE *ptr_net_device, PBM_Handle hPkt, UINT8 *dst_mac, UINT8 *src_mac, UINT16 ether_type)
NETIF_DEVICE * NIMUFindByIndex (uint index)
NETIF_DEVICE * NIMUFindByName (char *name)
int NIMURegister (NETIF_DEVICE *ptr_netif_device)
int NIMUUnregister (NETIF_DEVICE *ptr_netif_device)
int NIMUIoctl (uint cmd, NIMU_IF_REQ *ptr_nimu_ifreq, void *pBuf, uint size)
void NIMUGetRsvdSizeInfo (int *header_size, int *trailer_size)
void NIMUSetRsvdSizeInfo (int header_size, int trailer_size)
int NIMUInit (STKEVENT_Handle hEvent)
void NIMUShutdown (void)


Detailed Description

Implements the network interface management code. This is required when the NDK Core stack has been built to be able to handle multiple drivers. The file has the code which resides in the data path.

NOTE: (C) Copyright 2008, Texas Instruments, Inc.

Function Documentation

int NIMUAddEthernetHeader ( NETIF_DEVICE *  ptr_net_device,
PBM_Handle  hPkt,
UINT8 *  dst_mac,
UINT8 *  src_mac,
UINT16  ether_type 
)

Description
The function is a UTILITY function which is provided for use to driver authors if the driver is a simple Ethernet driver. Driver Authors should initialize the 'add_header' field of the NIMU Network Interface object to this function.

This will ensure that all packets passed to the driver are pre-pended with the correct layer2 ethernet header before they are transmitted. Failure to do will cause no Layer2 headers to be added.

Parameters:
[in] ptr_net_device The NIMU Network interface object on which the packet will be transmitted and which is used to tag the correct L2 header.
[in] hPkt Handle to the packet which will be sent out and on which the L2 header is added.
[in] dst_mac The Dst MAC Address to be added on the packet
[in] src_mac The Src MAC Address to be added on the packet
[in] ether_type The 'Protocol' tag which needs to be appended.
Return values:
0 - Success
<0 - Error

int NIMUAddHeader ( NETIF_DEVICE *  ptr_device,
HANDLE  hPkt,
UINT8 *  dst_mac,
UINT8 *  src_mac,
UINT16  protocol 
)

Description
The function is used to add an appropriate layer2 header as specified by the NIMU object. This function is called when the packet is passed down from layer3 to layer2 and is used to prep the packet by adding the correct layer2 header.

This is for *internal* NDK Stack Usage.

Parameters:
[in] ptr_device The NIMU Network interface object on which the packet will be transmitted and which is used to tag the correct L2 header.
[in] hPkt Handle to the packet which will be sent out and on which the L2 header is added.
[in] dst_mac The Dst MAC Address to be added on the packet
[in] src_mac The Src MAC Address to be added on the packet
[in] protocol The 'Protocol' tag which needs to be appended.
Return values:
0 - Success
<0 - Error

PBM_Pkt* NIMUCreatePacket ( uint  packet_size  ) 

Description
The function is a generic utility function which creates a packet that is used for transmission on any network interface object which has been registered with the NIMU. The packet allocated has 'header' and 'trailer' padding added.

This is for *internal* NDK Stack Usage.

Parameters:
[in] packet_size Size of the packet which needs to be allocated.
Return values:
Handle to the packet - Success
NULL - Error

NETIF_DEVICE* NIMUFindByIndex ( uint  index  ) 

Description
The function searches the NIMU database and finds an entry matching the device 'index'

This is for *internal* NDK Stack Usage.

Parameters:
[in] index The device index we are trying to locate.
Return values:
NIMU Network Interface Object - Matching entry found.
NULL - No Match

NETIF_DEVICE* NIMUFindByName ( char *  name  ) 

Description
The function searches the NIMU database and finds an entry matching the device 'name'

This is for *internal* NDK Stack Usage.

Parameters:
[in] name The device name we are trying to locate.
Return values:
NIMU Network Interface Object - Matching entry found.
NULL - No Match

void NIMUGetRsvdSizeInfo ( int *  header_size,
int *  trailer_size 
)

Description
The function is to used to retrieve the header and trailer reserved size information. The Network Interface Management Unit keeps track of all devices present in the system and is also responsible for ensuring that there is suffient headroom and tailroom for various driver layers to be able to add headers or trailers as the need be. This ensures that there are no copies being done because of insufficient headroom.

The function is available for usage; but it should only be called from kernel mode (llEnter()/llExit())

Parameters:
[out] header_size The current header size which is reserved.
[out] trailer_size The current trailer size which is reserved.
Return values:
Not Applicable.

int NIMUInit ( STKEVENT_Handle  hEvent  ) 

Description
The function initializes the NDK core stack Network Interface Management Unit

This is for *internal* NDK Stack Usage.

Parameters:
[in] hEvent The stack event handle which is used by the NDK Network Scheduler to indicate data is present on the drivers. This handle is required by the drivers for its operation.
Return values:
0 - Success
<0 - Error

int NIMUIoctl ( uint  cmd,
NIMU_IF_REQ *  ptr_nimu_ifreq,
void *  pBuf,
uint  size 
)

Description
The function is the standard IOCTL interface to the NIMU module and is used to get/set parameters to the NIMU. The API is available to use for applications outside the core NDK stack since it does the necessary llEnter/llExit.

Parameters:
[in] cmd One of the special commands mentioned above.
[in] ptr_nimu_ifreq The NIMU Interface request structure which identifies the NIMU object to which the 'cmd' is directed upon.
[in] pBuf The pointer to the buffer where the result of the command execution will be stored.
[in] size The size of the result buffer i.e. pBuf.
Return values:
0 - Success
<0 - Error

void NIMUPacketService ( void   ) 

Description
The function is called by the NDK Net Scheduler to service all NIMU Network Interface objects registered in the system. This is called when the NDK scheduler detects that a packet has been received by the lower HAL drivers and needs to be serviced.

This is for *internal* NDK Stack Usage.

Return values:
Not Applicable.

void NIMUPacketServiceCheck ( int  fEvents  ) 

Description
The function is called by the NDK Net Scheduler to allow HAL drivers to be able to perform 'periodic' activities; such as Ethernet Link management. There also exists a mode in which the HAL drivers can execute in 'polled' mode. In this case this the HAL drivers do not use 'interrupts' and are polled by the NDK Net Scheduler to check for transmit/receive activity.

This is for *internal* NDK Stack Usage.

Parameters:
[in] fEvents This is set to 1 if the function is invoked by the NDK Net Scheduler because of a timer tick. Set to 0 otherwise. This flag is available to the HAL drivers to determine the source of the function invocation.
Return values:
Not Applicable.

int NIMUReceivePacket ( PBM_Handle  hPkt  ) 

Description
This routine is the API interface routine which needs to be invoked by the drivers to pass the packet up the NDK core stack The function takes the raw packet received from the MAC device, and validates the link level related data. Packets are passed up the stack on the basis of the 'protocol' field.

Parameters:
[in] hPkt Handle to the packet which is to be passed up the NDK stack.
Return values:
-1 - Error
0 - Success

int NIMURegister ( NETIF_DEVICE *  ptr_netif_device  ) 

Description
This API is used by driver authors to register a network device with the NDK Network Interface Management Unit. The function verifies the arguments, checks for duplicates and adds the device to NIMU (Network Interface Management Unit)

Parameters:
[in] ptr_netif_device The NIMU Network Interface Object to be registered.
Return values:
0 - Success
<0 - Error

void NIMUSendPacket ( HANDLE  hIF,
PBM_Pkt *  pPkt 
)

Description
The function is the interface routine which is called to send a packet via the registered the NIMU Network Interface Object.

This is for *internal* NDK Stack Usage.

Parameters:
[in] hIF Handle of the NIMU Network interface object on which the packet will be transmitted.
[in] pPkt Handle to the packet which needs to be sent
Return values:
Not Applicable.

void NIMUSetRsvdSizeInfo ( int  header_size,
int  trailer_size 
)

Description
The function is to used to set the header and trailer reserved size information. This is typically used by driver authors if the driver needs a L2 header or trailer and the current size are not sufficient.

There is no validation done on the arguments.

The function is available for usage; but it should only be called from kernel mode (llEnter()/llExit())

Parameters:
[in] header_size The new header size which is to be reserved
[in] trailer_size The new trailer size which is to be reserved
Return values:
Not Applicable.

void NIMUShutdown ( void   ) 

Description
The function closes the NDK core stack Network Interface Management Unit

This is for *internal* NDK Stack Usage.

Return values:
Not applicable.

int NIMUUnregister ( NETIF_DEVICE *  ptr_netif_device  ) 

Description
This API is used by driver authors to unregister and stop the network device from the NIMU. The device should have been registered with the NIMU.

Parameters:
[in] ptr_netif_device The NIMU Network Interface Object to be unregistered.
Return values:
0 - Success
<0 - Error


Copyright 2009, Texas Instruments Incorporated