driver hacking and packet annotations

John Bicket jbicket at mit.edu
Fri Jun 27 22:58:25 EDT 2003


Hi Everyone,
I've been doing a lot of hacking on some of the wireless drivers so
that we can do some cool things in click that used to require cumbersome
hacks.

For instance, when the prism2 driver receives a packet, it can mark
a packet annotation with the signal and noise that the packet was
recieved with, and then you process that information in click since
the annotations are stored in sk_buff->cb.  

Here is the packet_anno.h file that I put in the linux-2.4.20/include/linux
dir and I have been using.  It's basically stuff taken out of 
click/include/click/packet.hh. 

I don't know that this is something that you want to include in the patches,
but I wondered if you had any thoughts or feedback.

--john


#ifndef PACKET_ANNO_H
#define PACKET_ANNO_H
/*
 * Click packet annotations.
 */

#include <linux/skbuff.h>

enum { ADDR_ANNO_SIZE = 16 };

enum { USER_ANNO_SIZE = 24,
       USER_ANNO_US_SIZE = 12,
       USER_ANNO_S_SIZE = 12,
       USER_ANNO_U_SIZE = 6,
       USER_ANNO_I_SIZE = 6 };

// Anno must fit in sk_buff's char cb[48].
struct Anno {
  union {
    uint8_t c[ADDR_ANNO_SIZE];
    uint32_t ip4;
  } addr;
  
  union {
    uint8_t c[USER_ANNO_SIZE];
    uint16_t us[USER_ANNO_US_SIZE];
    int16_t s[USER_ANNO_S_SIZE];
    uint32_t u[USER_ANNO_U_SIZE];
    int32_t i[USER_ANNO_I_SIZE];
  } user;
  uint64_t perfctr;
};
  

struct Anno *anno(struct sk_buff *skb) {return (struct Anno *) skb->cb; }

  
uint8_t user_anno_c(struct sk_buff *skb, int i) { return anno(skb)->user.c[i]; }
void set_user_anno_c(struct sk_buff *skb, int i, uint8_t v) { anno(skb)->user.c[i] = v; }
uint16_t user_anno_us(struct sk_buff *skb, int i) { return anno(skb)->user.us[i]; }
void set_user_anno_us(struct sk_buff *skb, int i, uint16_t v) { anno(skb)->user.us[i] = v; }
int16_t user_anno_s(struct sk_buff *skb, int i) { return anno(skb)->user.us[i]; }
void set_user_anno_s(struct sk_buff *skb, int i, int16_t v) { anno(skb)->user.s[i] = v; }
uint32_t user_anno_u(struct sk_buff *skb, int i) { return anno(skb)->user.u[i]; }
void set_user_anno_u(struct sk_buff *skb, int i, uint32_t v) { anno(skb)->user.u[i] = v; }
int32_t user_anno_i(struct sk_buff *skb, int i) { return anno(skb)->user.i[i]; }
void set_user_anno_i(struct sk_buff *skb, int i, int32_t v) { anno(skb)->user.i[i] = v; }

#define WIFI_TX_SUCCESS_ANNO(p)           (user_anno_c(p, 10))
#define SET_WIFI_TX_SUCCESS_ANNO(p, v)    (set_user_anno_c(p, 10, (v)))

#define WIFI_TX_POWER_ANNO(p)           (user_anno_c(p, 11))
#define SET_WIFI_TX_POWER_ANNO(p, v)    (set_user_anno_c(p, 11, (v)))

#define WIFI_RATE_ANNO(p)           (user_anno_c(p, 12))
#define SET_WIFI_RATE_ANNO(p, v)    (set_user_anno_c(p, 12, (v)))

#define WIFI_RETRIES_ANNO(p)           (user_anno_c(p, 13))
#define SET_WIFI_RETRIES_ANNO(p, v)    (set_user_anno_c(p, 13, (v)))

#define WIFI_SIGNAL_ANNO(p)           (user_anno_c(p, 14))
#define SET_WIFI_SIGNAL_ANNO(p, v)    (set_user_anno_c(p, 14, (v)))

#define WIFI_NOISE_ANNO(p)           (user_anno_c(p, 15))
#define SET_WIFI_NOISE_ANNO(p, v)    (set_user_anno_c(p, 15, (v)))


#endif /* PACKET_ANNO_H */




More information about the click mailing list