@@ -246,6 +246,50 @@ lowpan_uncompress_addr(struct sk_buff *skb, struct in6_addr *ipaddr,
246246 return 0 ;
247247}
248248
249+ static void
250+ lowpan_compress_udp_header (u8 * * hc06_ptr , struct sk_buff * skb )
251+ {
252+ struct udphdr * uh = udp_hdr (skb );
253+
254+ pr_debug ("(%s): UDP header compression\n" , __func__ );
255+
256+ if (((uh -> source & LOWPAN_NHC_UDP_4BIT_MASK ) ==
257+ LOWPAN_NHC_UDP_4BIT_PORT ) &&
258+ ((uh -> dest & LOWPAN_NHC_UDP_4BIT_MASK ) ==
259+ LOWPAN_NHC_UDP_4BIT_PORT )) {
260+ pr_debug ("(%s): both ports compression to 4 bits\n" , __func__ );
261+ * * hc06_ptr = LOWPAN_NHC_UDP_CS_P_11 ;
262+ * * (hc06_ptr + 1 ) = /* subtraction is faster */
263+ (u8 )((uh -> dest - LOWPAN_NHC_UDP_4BIT_PORT ) +
264+ ((uh -> source & LOWPAN_NHC_UDP_4BIT_PORT ) << 4 ));
265+ * hc06_ptr += 2 ;
266+ } else if ((uh -> dest & LOWPAN_NHC_UDP_8BIT_MASK ) ==
267+ LOWPAN_NHC_UDP_8BIT_PORT ) {
268+ pr_debug ("(%s): remove 8 bits of dest\n" , __func__ );
269+ * * hc06_ptr = LOWPAN_NHC_UDP_CS_P_01 ;
270+ memcpy (* hc06_ptr + 1 , & uh -> source , 2 );
271+ * * (hc06_ptr + 3 ) = (u8 )(uh -> dest - LOWPAN_NHC_UDP_8BIT_PORT );
272+ * hc06_ptr += 4 ;
273+ } else if ((uh -> source & LOWPAN_NHC_UDP_8BIT_MASK ) ==
274+ LOWPAN_NHC_UDP_8BIT_PORT ) {
275+ pr_debug ("(%s): remove 8 bits of source\n" , __func__ );
276+ * * hc06_ptr = LOWPAN_NHC_UDP_CS_P_10 ;
277+ memcpy (* hc06_ptr + 1 , & uh -> dest , 2 );
278+ * * (hc06_ptr + 3 ) = (u8 )(uh -> source - LOWPAN_NHC_UDP_8BIT_PORT );
279+ * hc06_ptr += 4 ;
280+ } else {
281+ pr_debug ("(%s): can't compress header\n" , __func__ );
282+ * * hc06_ptr = LOWPAN_NHC_UDP_CS_P_00 ;
283+ memcpy (* hc06_ptr + 1 , & uh -> source , 2 );
284+ memcpy (* hc06_ptr + 3 , & uh -> dest , 2 );
285+ * hc06_ptr += 5 ;
286+ }
287+
288+ /* checksum is always inline */
289+ memcpy (* hc06_ptr , & uh -> check , 2 );
290+ * hc06_ptr += 2 ;
291+ }
292+
249293static u8 lowpan_fetch_skb_u8 (struct sk_buff * skb )
250294{
251295 u8 ret ;
@@ -365,8 +409,6 @@ static int lowpan_header_create(struct sk_buff *skb,
365409 if (hdr -> nexthdr == UIP_PROTO_UDP )
366410 iphc0 |= LOWPAN_IPHC_NH_C ;
367411
368- /* TODO: next header compression */
369-
370412 if ((iphc0 & LOWPAN_IPHC_NH_C ) == 0 ) {
371413 * hc06_ptr = hdr -> nexthdr ;
372414 hc06_ptr += 1 ;
@@ -454,8 +496,9 @@ static int lowpan_header_create(struct sk_buff *skb,
454496 }
455497 }
456498
457- /* TODO: UDP header compression */
458- /* TODO: Next Header compression */
499+ /* UDP header compression */
500+ if (hdr -> nexthdr == UIP_PROTO_UDP )
501+ lowpan_compress_udp_header (& hc06_ptr , skb );
459502
460503 head [0 ] = iphc0 ;
461504 head [1 ] = iphc1 ;
0 commit comments