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

transport.c File Reference

Transport layer implementation. More...

#include <avr/eeprom.h>
#include <inttypes.h>
#include <stddef.h>
#include <string.h>
#include "net/network.h"
#include "net/transport.h"
#include "utils.h"
#include "net.h"

Go to the source code of this file.

Data Structures

struct  cache_entry_t
struct  reply_entry_t
struct  tsp_int_buf

Defines

#define TPDU_MASK   0x30
#define SEQU_MASK   0x0f
#define TPDU_ACKED_MSG   0x00
#define TPDU_UACKED_MSG   0x01
#define TPDU_ACK   0x02
#define TPDU_REMINDER   0x03

Functions

net_buf_t * tsp_ind (uint8_t *buf, uint8_t len, uint8_t session)
 Called from transport layer if a packet arrived.

void tsp_con (uint8_t *buf, uint8_t len)
 Called from transport layer if a reply to a request arrived.

void tsp_con_fin (uint8_t status)
 Called from transport layer if a request was finished.

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.

void tsp_process (void)
 Process waiting packets and schedule them for transmission.

void tsp_check_timeout (void)
 Check transport layer timeouts.

int8_t tsp_requ (net_buf_t *buf, net_addr_t *dest, enum tsp_service_e service)
 Send a packet using a transport layer sevice.

uint8_t tsp_clear_to_send (void)
 Returns a nonzero value if a new packet could be passed to the transport layer.

void tsp_set_segment_size (uint8_t size)
 Set size of segment.

uint8_t tsp_get_segment_size (void)
 Get segment size.

void tsp_set_group_size (uint8_t group, uint8_t size)
 Set size of a group.

uint8_t tsp_get_group_size (uint8_t group)
 Get size of a group.


Variables

uint8_t ee_group_size[TSP_MAX_GROUPS] EEPROM


Detailed Description

Transport layer implementation.

The transport layer is responsible for reliable packet delivery and to provide a request/response (session) service. For correct function of this layer you have to call some special functions.

Firstly tsp_process(), preferably directly from the main loop. Secondly tsp_check_timeout() at a fixed rate but NOT from a timer interrupt routine. This is because the implementation is not thread-save. Instead call it from the main loop. See the following code to get a idea how to do it:

 uint8_t timer_flag;

 SIGNAL(SIG_OVERFLOW1)
 {
        timer_flag++;
 }

 void main(void)
 {
        ...
        for (;;) {
                while (timer_flag > 0) {
                        timer_flag--;
                        tsp_check_timeout();
                }
                tsp_process();
        }
        ...
 }

Standalone usage

If you use the protocol stack only for communication and not for a home automation system then this is the layer to be called from your application. The usage is straigt forward.

To receive packets provide a non-static function defined as follows:

 net_buf_t *tsp_ind(uint8_t *buf, uint8_t len, uint8_t session)
 {
 }
It will be called every time a packet is received for this node. Any passed data must be processed within the function or copied to another buffer. Do not save the buf-pointer since the buffer he points to will be overwritten with the next received packet.

You also have to define the following two function:

 void tsp_con(uint8_t *buf, uint8_t len)
 {
 }
 
 void tsp_con_fin(uint8_t status)
 {
 }
They will be called if a request generated reply data and when a transaction has been finished.
Note:
Currently tsp_con_fin() is also called if tsp_ind() indicated a session, a reply was provided and the reply has been transmitted. This behaviour is used to signal upper layers that the provided buffer can now be used for other things. Expect this to be changed in fututre because firstly it is not a clean solution and secondly it is unclear what a call to tsp_con_fin() means if multiple sessions are running.
Author:
Jan Klötzke
History:

Definition in file transport.c.


Function Documentation

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().

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().

void tsp_check_timeout void   ) 
 

Check transport layer timeouts.

This function must be called at a fixed rate from the main loop.

Attention:
It cannot be called from a timer interrupt because it is not thread save!

Definition at line 451 of file transport.c.

References NAF_GROUP, and tsp_con_fin().

void tsp_con uint8_t *  buf,
uint8_t  len
 

Called from transport layer if a reply to a request arrived.

Parameters:
buf Pointer to data of the reply.
len Length of the reply.

Definition at line 396 of file application.c.

Referenced by net_ind().

void tsp_con_fin uint8_t  status  ) 
 

Called from transport layer if a request was finished.

Parameters:
status Zero if the request failed, otherwise non-zero.

Definition at line 417 of file application.c.

Referenced by net_con(), net_ind(), and tsp_check_timeout().

uint8_t tsp_get_group_size uint8_t  group  ) 
 

Get size of a group.

Parameters:
group Group number. [0..TSP_MAX_GROUPS-1]
Returns:
Size of group.

Definition at line 597 of file transport.c.

uint8_t tsp_get_segment_size void   ) 
 

Get segment size.

Returns:
Current segment size.

Definition at line 575 of file transport.c.

net_buf_t* tsp_ind uint8_t *  buf,
uint8_t  len,
uint8_t  session
 

Called from transport layer if a packet arrived.

Parameters:
buf Pointer to the data of the packet.
len Length of the packet.
session Flag indicating duplicate requests.
  • 0: Packet is not related to a session.
  • 1: First request in a session.
  • 2: Additional request in a session.

Definition at line 359 of file application.c.

Referenced by net_ind().

void tsp_process void   ) 
 

Process waiting packets and schedule them for transmission.

This function should be called from your main loop.

Attention:
Must not be called from a interrupt routine. The implementation is not thread-save.
Todo:
Remove dirty hack ensuring that buffer of sesion reply gets released.

Definition at line 398 of file transport.c.

References net_clear_to_send(), net_requ(), and NPDU_SINGLE.

int8_t tsp_requ net_buf_t *  buf,
net_addr_t dest,
enum tsp_service_e  service
 

Send a packet using a transport layer sevice.

This function does return without waiting for the packet to be transmitted. Check the return value if the packet was scheduled for transmission.

Parameters:
buf Network buffer containing the packet data.
dest Destination network address.
service Transport layer service used for transmission.
Returns:
Returns -1 for a invalid request, 0 if the request could not be processed currently or 1 if successfull.

Definition at line 492 of file transport.c.

References AT_LOGIC, NPDU_SESSION, NPDU_SINGLE, NPDU_TRANSACTION, S_ACKED, S_DGRAM, S_REPEATED, and S_REQUEST.

Referenced by app_process().

void tsp_set_group_size uint8_t  group,
uint8_t  size
 

Set size of a group.

Parameters:
group Group number of group which size is about to be set. [0..TSP_MAX_GROUPS-1]
size The new group size.

Definition at line 586 of file transport.c.

void tsp_set_segment_size uint8_t  size  ) 
 

Set size of segment.

Parameters:
size New segment size.

Definition at line 565 of file transport.c.


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