added hooks for adding an external header compressor
This commit is contained in:
parent
ea090a60e6
commit
e8916fe01f
|
@ -32,7 +32,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: sicslowpan.c,v 1.29 2010/03/16 10:21:04 joxe Exp $
|
||||
* $Id: sicslowpan.c,v 1.30 2010/03/17 12:08:59 joxe Exp $
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
|
@ -168,6 +168,11 @@ void uip_log(char *msg);
|
|||
/** A pointer to the mac driver */
|
||||
const struct mac_driver *sicslowpan_mac;
|
||||
|
||||
#ifdef SICSLOWPAN_NH_COMPRESSOR
|
||||
/** A pointer to the additional compressor */
|
||||
extern struct sicslowpan_nh_compressor SICSLOWPAN_NH_COMPRESSOR;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A pointer to the rime buffer.
|
||||
* We initialize it to the beginning of the rime buffer, then
|
||||
|
@ -467,7 +472,7 @@ compress_hdr_hc06(rimeaddr_t *rime_destaddr)
|
|||
RIME_IPHC_BUF[0] |= SICSLOWPAN_IPHC_TC_C;
|
||||
*hc06_ptr = (tmp & 0xc0) |
|
||||
(UIP_IP_BUF->tcflow & 0x0F);
|
||||
memcpy(hc06_ptr + 1, &UIP_IP_BUF->flow, 2);
|
||||
memcpy(hc06_ptr + 1, &UIP_IP_BUF->flow, 2);
|
||||
hc06_ptr += 3;
|
||||
} else {
|
||||
/* compress nothing */
|
||||
|
@ -484,13 +489,17 @@ compress_hdr_hc06(rimeaddr_t *rime_destaddr)
|
|||
#if UIP_CONF_UDP
|
||||
if(UIP_IP_BUF->proto == UIP_PROTO_UDP) {
|
||||
RIME_IPHC_BUF[0] |= SICSLOWPAN_IPHC_NH_C;
|
||||
} else {
|
||||
}
|
||||
#endif /*UIP_CONF_UDP*/
|
||||
#ifdef SICSLOWPAN_NH_COMPRESSOR
|
||||
if(SICSLOWPAN_NH_COMPRESSOR.is_compressable(UIP_IP_BUF->proto)) {
|
||||
RIME_IPHC_BUF[0] |= SICSLOWPAN_IPHC_NH_C;
|
||||
}
|
||||
#endif
|
||||
if ((RIME_IPHC_BUF[0] & SICSLOWPAN_IPHC_NH_C) == 0) {
|
||||
*hc06_ptr = UIP_IP_BUF->proto;
|
||||
hc06_ptr += 1;
|
||||
#if UIP_CONF_UDP
|
||||
}
|
||||
#endif /*UIP_CONF_UDP*/
|
||||
}
|
||||
|
||||
/*
|
||||
* Hop limit
|
||||
|
@ -620,6 +629,10 @@ compress_hdr_hc06(rimeaddr_t *rime_destaddr)
|
|||
uncomp_hdr_len += UIP_UDPH_LEN;
|
||||
}
|
||||
#endif /*UIP_CONF_UDP*/
|
||||
#ifdef SICSLOWPAN_NH_COMPRESSOR
|
||||
/* if nothing to compress just return zero */
|
||||
hc06_ptr += SICSLOWPAN_NH_COMPRESSOR.compress(hc06_ptr, &uncomp_hdr_len);
|
||||
#endif
|
||||
rime_hdr_len = hc06_ptr - rime_ptr;
|
||||
return;
|
||||
}
|
||||
|
@ -856,7 +869,7 @@ uncompress_hdr_hc06(u16_t ip_len) {
|
|||
/* Next header processing - continued */
|
||||
if((RIME_IPHC_BUF[0] & SICSLOWPAN_IPHC_NH_C)) {
|
||||
/* The next header is compressed, NHC is following */
|
||||
if((*hc06_ptr & SICSLOWPAN_NDC_UDP_MASK) == SICSLOWPAN_NHC_UDP_ID) {
|
||||
if((*hc06_ptr & SICSLOWPAN_NHC_UDP_MASK) == SICSLOWPAN_NHC_UDP_ID) {
|
||||
SICSLOWPAN_IP_BUF->proto = UIP_PROTO_UDP;
|
||||
switch(*hc06_ptr) {
|
||||
case SICSLOWPAN_NHC_UDP_C:
|
||||
|
@ -886,6 +899,11 @@ uncompress_hdr_hc06(u16_t ip_len) {
|
|||
}
|
||||
uncomp_hdr_len += UIP_UDPH_LEN;
|
||||
}
|
||||
#ifdef SICSLOWPAN_NH_COMPRESSOR
|
||||
else {
|
||||
hc06_ptr += SICSLOWPAN_NH_COMPRESSOR.uncompress(hc06_ptr, sicslowpan_buf, &uncomp_hdr_len);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
rime_hdr_len = hc06_ptr - rime_ptr;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: sicslowpan.h,v 1.10 2010/03/16 10:21:04 joxe Exp $
|
||||
* $Id: sicslowpan.h,v 1.11 2010/03/17 12:08:59 joxe Exp $
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
|
@ -137,13 +137,15 @@
|
|||
#define SICSLOWPAN_IPHC_MCAST_RANGE 0xA0
|
||||
/** @} */
|
||||
|
||||
|
||||
#define SICSLOWPAN_NDC_UDP_MASK 0xF8
|
||||
/* NHC_EXT_HDR */
|
||||
#define SICSLOWPAN_NHC_MASK 0xF0
|
||||
#define SICSLOWPAN_NHC_EXT_HDR 0xE0
|
||||
|
||||
/**
|
||||
* \name LOWPAN_UDP encoding (works together with IPHC)
|
||||
* @{
|
||||
*/
|
||||
#define SICSLOWPAN_NHC_UDP_MASK 0xF8
|
||||
#define SICSLOWPAN_NHC_UDP_ID 0xF0
|
||||
#define SICSLOWPAN_NHC_UDP_C 0xF3
|
||||
#define SICSLOWPAN_NHC_UDP_I 0xF0
|
||||
|
@ -284,6 +286,25 @@ struct sicslowpan_addr_context {
|
|||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* The structure of a next header compressor.
|
||||
*
|
||||
* TODO: needs more parameters when compressing extension headers, etc.
|
||||
*/
|
||||
struct sicslowpan_nh_compressor {
|
||||
int (* is_compressable)(uint8_t next_header);
|
||||
|
||||
/** compress next header (TCP/UDP, etc) - ptr points to next header to
|
||||
compress */
|
||||
int (* compress)(uint8_t *compressed, uint8_t *uncompressed_len);
|
||||
|
||||
/** uncompress next header (TCP/UDP, etc) - ptr points to next header to
|
||||
uncompress */
|
||||
int (* uncompress)(uint8_t *compressed, uint8_t *lowpanbuf, uint8_t *uncompressed_len);
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern const struct network_driver sicslowpan_driver;
|
||||
|
||||
extern const struct mac_driver *sicslowpan_mac;
|
||||
|
|
Loading…
Reference in a new issue