Advertisement
Guest User

Untitled

a guest
Jun 21st, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. struct shortTvlv {
  3.         uint8_t type;
  4.         uint8_t version;
  5.         uint8_t length;
  6. };
  7.  
  8. struct longTvlv {
  9.         uint8_t type;
  10.         uint8_t version;
  11.         uint16_t length;
  12. };
  13.  
  14.  
  15.  
  16.  
  17. struct batadv_shortTvlv_node {
  18.         struct hlist_node tlist;
  19.         struct rcu_head rcu;
  20.         struct shortTvlv *sTvlv;
  21. };
  22.  
  23. struct batadv_longTvlv_node {
  24.         struct hlist_node tlist;
  25.         struct longTvlv *tvlv;
  26.         struct rcu_head rcu;
  27. };
  28.  
  29. void registerTvlv(       uint8_t type,
  30.                           uint8_t version,
  31.                           uint8_t length,/*i'm not sure we need the length it should be calculable from the value*/
  32.                           uint8_t *value,
  33.                           struct batadv_priv *bat_priv,
  34.                           struct batadv_ogm_packet *ogm);
  35.  
  36.  
  37. void addTvlvNode(struct batadv_priv *bat_priv,struct shortTvlv *tvlv){
  38.         struct batadv_shortTvlv_node *tvlv_node=0;
  39.         if(!bat_priv || !tvlv)
  40.         goto end;
  41.        
  42.         tvlv_node=kmalloc(sizeof(struct batadv_shortTvlv_node), GFP_KERNEL);
  43.         printk("New node allocated\n");
  44.        
  45.         if (!tvlv_node)
  46.                 return;
  47.                
  48.         INIT_HLIST_NODE(&tvlv_node->tlist);
  49.        printk("New node inited\n");
  50.      
  51.         spin_lock_bh(&bat_priv->tvlv_list_lock);
  52.          tvlv_node->sTvlv=tvlv;
  53.           printk("New node assigned\n");
  54.          
  55.          
  56.         hlist_add_head_rcu(&tvlv_node->tlist, &bat_priv->tvlv_list);
  57.          printk("New node put in list\n");
  58.          
  59.         spin_unlock_bh(&bat_priv->tvlv_list_lock);
  60.        
  61.         end:return;
  62.     }
  63.  
  64.  
  65.  
  66. void registerTvlv(uint8_t type,uint8_t version,uint8_t length,uint8_t *value,struct batadv_priv *bat_priv,struct batadv_ogm_packet *ogm){
  67.    
  68.     if(!type || !version || !length || !value || !bat_priv ||!ogm)
  69.     goto end;
  70.    
  71.        
  72.     printk("Type %d version %d length %d \n",type,version,length);
  73.    
  74.    
  75.     struct batadv_shortTvlv_node *shortTvlv_node=0;
  76.     struct hlist_node *listnode=0;;
  77.     int new=0;
  78.     uint8_t *val=0;
  79.  
  80.  
  81.     rcu_read_lock();
  82.        
  83.         hlist_for_each_entry_rcu(shortTvlv_node,listnode,&bat_priv->tvlv_list,tlist){
  84.    
  85.          
  86.          if(shortTvlv_node->sTvlv->type!=type )
  87.          continue;
  88.        
  89.          goto update;
  90.        
  91.          }
  92.  
  93. new:
  94. printk("Constructing new tlv\n");
  95. struct shortTvlv *tvlv=0;
  96. tvlv=kmalloc(sizeof(struct shortTvlv)+sizeof(uint8_t),GFP_KERNEL);
  97.         printk("passed malloc checking for new memory validity\n");
  98.         if(!tvlv)goto end;
  99.         printk("mem valid puting tvl \n");
  100.      tvlv->length=length;
  101.      tvlv->version=version;
  102.      tvlv->type=type;
  103.             printk("tvl filled\n");
  104.      ogm->nofAppendedTvlvs++;
  105.             printk("tvl registered in the ogm\n");
  106.      memcpy(tvlv+sizeof(struct shortTvlv),value,length*sizeof(uint8_t));
  107.             printk("value put in place\n");
  108.      addTvlvNode(bat_priv,tvlv);
  109.            
  110.      printk("New Tvlv added: %d\n",ogm->nofAppendedTvlvs);
  111.      goto end;
  112. update:
  113.     printk("updating existing one\n");
  114.     val=value;
  115.     struct shortTvlv *tmp;
  116.     tmp=shortTvlv_node->sTvlv;
  117.     memcpy(tmp+sizeof(struct shortTvlv),val,length*sizeof(uint8_t));
  118.    
  119. end:
  120.     rcu_read_unlock();
  121.    
  122.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement