Wiselib
wiselib.testing/algorithms/cluster/securedfscluster/securedfsclusteringmessage.h
Go to the documentation of this file.
00001 
00002 #ifndef __ALGORITHMS_SECURE_DFS_CLUSTERING_MESSAGE__
00003 #define __ALGORITHMS_SECURE_DFS_CLUSTERING_MESSAGE__
00004 
00005 #include "algorithms/crypto/ecc.h"
00006 #include "util/serialization/simple_types.h"
00007 
00008 namespace wiselib {
00009     template<typename OsModel_P,
00010             typename Radio_P>
00011     class SecureDFSMessage {
00012     public:
00013         typedef OsModel_P OsModel;
00014         typedef Radio_P Radio;
00015         typedef typename Radio::block_data_t block_data_t;
00016         typedef typename Radio::size_t size_t;
00017 
00018    enum msg_id_t {
00019       NEIGHBOR_DISCOVERY   = 0,
00020       NEIGHBOR_REPLY       = 1,
00021       JOIN_REQUEST         = 2,
00022       JOIN_DENY            = 3,
00023       RESUME               = 4,
00024       RESUME2              = 5,
00025       RESUME3              = 6,
00026       CK_SEND              = 7,
00027       CKSEND2              = 8,
00028       CKSEND3              = 9
00029    };
00030 
00031         inline SecureDFSMessage() {}
00032 
00033    inline void set_msg_id(uint8_t id) {
00034             write<OsModel, block_data_t, uint8_t>(buffer+MSGID_POS, id);
00035    }
00036    inline uint8_t msg_id() {
00037             return read<OsModel, block_data_t, uint8_t>(buffer+MSGID_POS);
00038    }
00039 
00040    inline void set_sid(uint16_t sid) {
00041             write<OsModel, block_data_t, uint16_t>(buffer+SID_POS, sid);
00042    }
00043    inline uint16_t sid() {
00044             return read<OsModel, block_data_t, uint16_t>(buffer+SID_POS);
00045    }
00046 
00047         inline uint8_t key_size() {
00048             return sizeof(PubKey)/2;
00049         }
00050         inline PubKey* key() {
00051       PubKey *ret=new PubKey();
00052       for(int i=0; i<21; i++) {
00053          ret->W.x.val[i]=ret->W.y.val[i]=0;
00054       }
00055       memcpy(ret->W.x.val+21, buffer+KEY_POS, 21);
00056       memcpy(ret->W.y.val+21, buffer+KEY_POS+21, 21);
00057       return ret;
00058         }
00059         inline void set_key(PubKey *key) {
00060       memcpy(buffer+KEY_POS, key->W.x.val+21, 21);
00061       memcpy(buffer+KEY_POS+21, key->W.y.val+21, 21);
00062         }
00063         inline size_t buffer_size() {
00064             return KEY_POS+key_size();
00065         }
00066         
00067     private:
00068         enum data_positions {
00069       MSGID_POS = 0,
00070       SID_POS   = 1,
00071       KEY_POS   = 3
00072         };
00073         uint8_t buffer[Radio::MAX_MESSAGE_LENGTH];
00074     };
00075 }
00076 
00077 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines