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

TCP/IP API Functions

3.2.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 must be set up as follows:

the network hardware must be ready to send and receive packets

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

the MIB-II structure of the interface must be filled in, as shown in Example 3-2 on page 3-19

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

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.

3-18

Copyright © 1998-2001 ARM Limited. All rights reserved.

ARM DUI 0144B

TCP/IP API Functions

The nets[ ] structure must 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 3-11), there might be no additional work.

Example 3-2 shows sample 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.

You must make sure that nets[]->n_haddr 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). You must also ensure that nets[]->n_type is set to the media type, for example, Ethernet.

Example 3-2

np->n_lnh

= ETHHDR_SIZE;

/* 16 on ARM for alignment*/

np->n_mtu

= 1500 + ETHHDR_SIZE; /* 1516 on ARM */

np->n_hal

= 6;

 

np->n_init

= i8255x_init;

 

np->pkt_send

= i8255x_pkt_send;

 

np->n_close

= raw_send

 

;

 

 

np->n_stats

= NULL;

 

np->n_local

= ( void * )dev;

 

#ifdef NET_STATS

 

 

np->n_mib->ifOperStatus

= 2;

/* interface is down */

np->n_mib->ifAdminStatus

= 2;

/* interface is down */

np->n_mib->ifLastChange

= cticks;

 

np->n_mib->ifDescr

= (u_char *)i8255x_chip[revision];

np->n_mib->ifIndex

= i8255x_next_net;

 

np->n_mib->ifMtu

= ET_MAXLEN;

 

np->n_mib->ifSpeed

= 10000000;

 

#endif

 

 

np->n_haddr

= dev->mac_address;

 

np->n_type

= ETHERNET;

 

 

 

 

See the sample Ethernet driver interface in \integrator\i8255x.c.

ARM DUI 0144B

Copyright © 1998-2001 ARM Limited. All rights reserved.

3-19

TCP/IP API Functions

3.2.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 must 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 PPP links, PPP processes the packets, so you do not have to modify n_reg_type().

3-20

Copyright © 1998-2001 ARM Limited. All rights reserved.

ARM DUI 0144B

TCP/IP API Functions

3.2.5n_stats()

This is an optional function that you can use to display per-net statistics. You can also use it to log such statistics or return a pointer to a status block, depending on your requirements.

Syntax

void *n_stats(void *pio, int if_number) where:

pio

Is a pointer to a GenericIO structure into which debug information is to

 

be written.

if_number Is an index into the nets[ ] array of the interface for which statistics are to be dumped.

Return value

Optional.

Usage

This function is only used for debugging purposes.

ARM DUI 0144B

Copyright © 1998-2001 ARM Limited. All rights reserved.

3-21