Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

network.c File Reference

Network layer implementation. More...

#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include <inttypes.h>
#include "net/link.h"
#include "net/network.h"
#include "net.h"
#include "utils.h"

Go to the source code of this file.

Defines

#define DAF_MASK   0x03
#define SAF_MASK   0x0c
#define PDU_MASK   0x30

Functions

uint16_t ee_addr_logic __attribute__ ((section(".eeprom")))
void net_ind (uint8_t *buf, uint8_t len, const net_ind_t *ind)
 Called from network layer if a packet arrived for us...

void net_con (void)
 Called from network layer if a queued packet was sent.

uint8_t lnk_ind (uint8_t *buf, uint8_t len)
 Called from link layer if a packet has been received.

void lnk_con (void)
 Called from link layer if a packet was delivered.

uint8_t net_requ (net_buf_t *buf, const net_requ_t *requ)
 Send a packet.

uint8_t net_compare_src_addr (const net_addr_t *addr1, const net_addr_t *addr2)
 Compares two source network addresses.

uint8_t net_get_local_member_id (uint8_t group)
 Returns local member number for a group.

uint8_t net_clear_to_send (void)
 Check if another packet can be scheduled for transmission.

void net_set_logic_addr (uint16_t addr)
 Set logic address.

uint16_t net_get_logic_addr (void)
 Get logic address.

void net_set_group_addr (uint8_t group, uint16_t addr)
 Set address of a group.

uint16_t net_get_group_addr (uint8_t group)
 Get group address.


Detailed Description

Network layer implementation.

Implements the OpenHome network layer. The code is quite straight forward and rather self explainary.

Attention:
Define a unique physical address (NET_LOGIC_ADDR) in your net.h for each device.
Author:
Jan Klötzke
History:

Definition in file network.c.


Function Documentation

void lnk_con void   ) 
 

Called from link layer if a packet was delivered.

Simply passes event to upper layers.

Definition at line 139 of file network.c.

References net_con().

Referenced by lnk_process().

uint8_t lnk_ind uint8_t *  buf,
uint8_t  len
 

Called from link layer if a packet has been received.

This function is also called for locally generated packets to determine if the packet should be transmitted on the bus. If the destination address of the packet matches a local one then net_ind() is called to pass it to upper layers.

Parameters:
buf Pointer to the data of the packet.
len Length of the packet.
Returns:
One if the packet is only for this peer and should not be sent across network, otherwise it returns zero.
Note:
This function uses the local variable "ind" and passes a reference to the transport layer through net_ind(). Though this is not a good practice it saves stack and text space and should not lead to problems since the link layer processes only one packet at the same time.

Definition at line 86 of file network.c.

References net_addr_t::addr, AT_LOGIC, AT_PHYSIC, net_addr_t::format, NAF_BROADCAST, NAF_GROUP, NAF_LOGIC, NAF_PHYSIC, net_ind(), net_ind_t::pdu, net_ind_t::rat, and net_ind_t::src.

Referenced by lnk_process(), and net_requ().

uint8_t net_clear_to_send void   ) 
 

Check if another packet can be scheduled for transmission.

Returns:
Returns a nonzero value if a new packet could be passed to the network layer.

Definition at line 238 of file network.c.

References lnk_clear_to_send().

Referenced by tsp_process().

uint8_t net_compare_src_addr const net_addr_t addr1,
const net_addr_t addr2
 

Compares two source network addresses.

Since source and destination addresses differ in the group address format this function only compares two SOURCE network addresses.

Parameters:
addr1 First source address.
addr2 Second source address.
Returns:
One if the addresses match, otherwise zero.

Definition at line 210 of file network.c.

References net_addr_t::addr, and net_addr_t::format.

void net_con void   ) 
 

Called from network layer if a queued packet was sent.

Checks if tsp_con_fin() should be called.

Definition at line 380 of file transport.c.

References tsp_con_fin().

Referenced by lnk_con(), and net_requ().

uint16_t net_get_group_addr uint8_t  group  ) 
 

Get group address.

Parameters:
group Number of group.
Returns:
Group node address.

Definition at line 280 of file network.c.

uint8_t net_get_local_member_id uint8_t  group  ) 
 

Returns local member number for a group.

Parameters:
group Group from which the node's member number should be returned. Use AT_GROUP* constants.
Returns:
Group member number.

Definition at line 227 of file network.c.

Referenced by net_ind().

uint16_t net_get_logic_addr void   ) 
 

Get logic address.

Returns:
Current logic address.

Definition at line 258 of file network.c.

void net_ind uint8_t *  buf,
uint8_t  len,
const net_ind_t ind
 

Called from network layer if a packet arrived for us...

Parameters:
buf Pointer to the data of the packet.
len Length of the packet.
ind Structure containing network layer specific information of the packet.

Definition at line 296 of file transport.c.

References net_addr_t::addr, net_addr_t::format, NAF_GROUP, net_get_local_member_id(), NPDU_SESSION, NPDU_SINGLE, net_ind_t::pdu, net_ind_t::rat, net_ind_t::src, tsp_con(), tsp_con_fin(), and tsp_ind().

Referenced by lnk_ind().

uint8_t net_requ net_buf_t *  buf,
const net_requ_t requ
 

Send a packet.

This functions adds the network layer specific header and passes the packet to the link layer. Also checks if it should be delivered locally.

Parameters:
buf A network buffer containing the data to be sent. Must not be released until lnk_con() is called.
requ Structure containing network layer details such as the destination address.
Returns:
A nonzero value if the packet could be scheduled for delivery, otherwise zero.

Definition at line 162 of file network.c.

References net_addr_t::addr, AT_LOGIC, AT_PHYSIC, net_requ_t::backlog, net_requ_t::dest, net_addr_t::format, lnk_clear_to_send(), lnk_ind(), lnk_requ(), NAF_GROUP, NAF_LOGIC, NAF_PHYSIC, net_con(), net_requ_t::pdu, and net_requ_t::src.

Referenced by tsp_process().

void net_set_group_addr uint8_t  group,
uint16_t  addr
 

Set address of a group.

Parameters:
group Number of group which to set. [0..7]
addr Full qualified group node address.

Definition at line 269 of file network.c.

void net_set_logic_addr uint16_t  addr  ) 
 

Set logic address.

Parameters:
addr New logic address.

Definition at line 248 of file network.c.


Generated on Fri Oct 17 16:45:54 2003 for OpenHome by doxygen 1.3.3