Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ARM).Porting TCP-IP programmer's guide.Ver 1.4.pdf
Скачиваний:
31
Добавлен:
23.08.2013
Размер:
2.79 Mб
Скачать

TCP/IP API Functions

4.3.2n_close()

This function performs the tasks required to shutdown the device and its associated driver software prior to exiting the application. Any resources allocated to accommodate multiple packet types, for example, 0x0800 for IP and 0x0806 for ARP, should be released here. On embedded systems that start their devices at power up and do not shut them down, this function is not required.

Syntax

int n_close(int if_number)

where:

if_number is an index into the nets[ ] array of the interface to be closed.

Return value

Returns one of the following:

0

if successful.

ENP_Code if not successful (see ENP_ error codes on page A-2).

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

4-19

TCP/IP API Functions

4.3.3n_init()

This function prepares the device to send and receive packets. It is called during system startup after prep_ifaces() has been called, and before any of the other network interface functions are invoked.

Syntax

int n_init(int if_number)

where:

if_number is an index into the nets[ ] array of the interface to be initialized.

Return value

Returns one of the following:

0

if successful.

ENP_Code if not successful (see ENP_ error codes on page A-2).

Usage

When this function returns, the device should be set up as follows:

the network hardware should be ready to send and receive packets

all required fields of the nets[ ] structure should be filled in

the MIB-II structure of the interface should be filled in, as shown in Example 4-2 on page 4-21

IP addressing information should be set before this function returns unless DHCP or BOOTP is to be used (see Specifying IP addresses on page 2-14).

This function typically includes hardware operations, such as initializing the device and enabling interrupts. It does not include setting protocol types. This is handled by n_reg_type().

On returning from this function, it is safe for your hardware interrupt or receive functions to start queuing received packets in the rvcdq queue. Packets that are not IP or ARP are discarded by the stack.

4-20

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B

TCP/IP API Functions

The nets[ ] structure should be completely filled in when this function returns. The structure is defined in \inet\net.h. The work of filling this structure is shared between prep_ifaces() and n_init(). If all your nets[ ] structure setup was done in prep_ifaces() (see prep_ifaces() on page 4-12), there may be no additional work.

Example 4-2 shows example code for setting up the MIB structure for a 10MB Ethernet interface. The n_mib field points to a structure that has already been statically allocated by the calling code. See RFC 1213 for detailed descriptions of the MIB fields.

Most of the MIB fields are used only for debugging and statistical information and are not critical unless your device is managed by SNMP. The ifPhysAddress field is an exception. It is used by ARP to obtain the MAC address of the hardware and must be set up correctly for the IP stack to work over Ethernet.

Although ifPhysAddress is a pointer, it does not point to valid memory when the MIB structure is created. You must make sure it points to a static buffer containing the MAC address before n_init() returns. The size of this address is determined by the media (6 bytes for Ethernet) and should be set in the nets[ ] structure member n_hal (hardware address length).

Example 4-2

nets[if_number]->nmib->ifDescr = "Ethernet Packet Driver"; nets[if_number]->nmib->ifType = ETHERNET;

/*SNMP Ethernet type */ nets[if_number]->nmib->ifMtu = ET_MAXLEN; nets[if_number]->nmib->ifSpeed = 10000000;

/* 10 megabits per second */ nets[if_number]->nmib->ifAdminStatus = 1; nets[if_number]->nmib->ifOperStatus = 1; nets[if_number]->nmib->ifPhysAddress = &macaddress[0];

/* example */

See the example Olicom driver interface in \pid7tdm\olicom.c.

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

4-21

TCP/IP API Functions

4.3.4n_reg_type()

This function registers with lower level drivers to receive a MAC type, such as 0x0800 for IP and 0x0806 for ARP.

Syntax

int n_reg_type(unsigned short type, NET net) where:

type

is the MAC type to be registered.

net

is a pointer to the NET structure corresponding to this interface.

Return value

Returns one of the following:

0

if successful.

ENP_Code if not successful (see ENP_ error codes on page A-2).

Usage

On most embedded systems with Ethernet, the ARM stack does not share the hardware with other network stacks, so no action is required. The stack gets all the packets and n_reg_type() can return an OK status without doing anything. However, you should make sure that all received packets are passed to the stack. On some driver subsystems, a type must be registered with the driver. On other drivers, an intermediate layer must be notified that the application is interested in the packets.

On SLIP links, all packets are IP, so you need not modify n_reg_type().

On PPP links, PPP processes the packets, so you need not modify n_reg_type().

4-22

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B