📄 activemessagec.nc
字号:
// $Id: ActiveMessageC.nc,v 1.6 2008/04/24 06:52:12 klueska Exp $/* * Copyright (c) 2005-2006 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, * 94704. Attention: Intel License Inquiry. *//** * Dummy implementation to support the null platform. */module ActiveMessageC { provides { interface SplitControl; interface AMSend[uint8_t id]; interface Receive[uint8_t id]; interface Receive as Snoop[uint8_t id]; interface Packet; interface AMPacket; interface PacketAcknowledgements as Acks; }}implementation { uint8_i state; uint8_i pendingSendToBS;/* debugging purpose */ message_t* buffer; uint16_t lastCount; uint16_t counter; uint8_t blockSize = 8; uint8_t keySize = 10; uint8_t preCombBlocks = 5; uint8_t tagLength = 4; CipherModeContext cc; uint8_t key[]; uint8_t decryptedMsg[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; uint8_t iv[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; uint8_t plainMsg[]= {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08, 0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10, 0x11,0x12,0x13,0x14,0x15,0x16 }; uint8_t cipherMsg[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; uint8_t tag[]={0x00,0x00,0x00,0x00}; uint8_t message_decrypted[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; uint8_t cipher_rec[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; uint8_t tag_rec[]= {0x00, 0x00, 0x00, 0x00}; uint8_t tag_length = 4; uint8_t max_times_inc_IV; uint8_t nbre_times_inc_IV = 0; message_t dataToSendToBS; uint8_t nbreLB; /* * number of consecutive failure of decrypting a message even * after the IV was incremented max_times_inc_IV */ uint8_t num_f; /* * number of times, the receiver fails to decrypt messages, before * it runs the resync protocol */ uint8_t num_fb_resync; message_t* buffer_nonce; message_t* data_nonce; uint8_t waiting_for_resync; /* testing purpose */ uint8_t cipherTest[]= {0,0xb7,0xf,0xc4,0x13,0x71,0xfd,0x95,0x36,0x3f,0x40,0xea,0xeb,0x9a,0x60,0x88,0x24,0xcc,0x2b,0xd9,0x3c,0xfe}; uint8_t tagTest[]={0x73, 0xd9, 0x54, 0x7f}; // void dumpInt ( uint8_t int_name, uint8_t value) ; void dumpBuffer (char * bufName, uint8_t * buf, uint8_t size); // void dumpHexa ( uint8_t hexaName, uint8_t value); // Initialization of this component /* helping functions */ int IncIV(uint8_t *IV, uint8_t inc); int incIV(uint8_t *IV); void DecIV(uint8_t *IV, uint8_t dec); void decIV(uint8_t *IV); void cpyBuffer(uint8_t *des, uint8_t *src, uint8_t size); command error_t SplitControl.start() { return SUCCESS; } command error_t SplitControl.stop() { return SUCCESS; }void dbgPacket(message_t* data) { uint8_t i; for(i = 0; i < sizeof(message_t); i++) { dbg_clear("DBG_AM", "%02hhx ", ((uint8_t *)data)[i]); } dbg_clear("DBG_AM", "\n"); } command error_t AMSend.send[uint8_t id](am_addr_t addr, message_t* msg, uint8_t len) { //IntMsg *message; //uint8_t valid=0; if (state!=SUCCESS) { dumpBuffer("=>gm IV_sending", iv+7,1); dumpBuffer("data->data plain *radio*", data->data, length); //encrypt(context, plaintext, ciphertest, tag, numButes, IV //now cipherMsg has ciphertext, tag has tag call cipherMode.encrypt(&cc, data->data, cipherMsg, tag, length, iv); dumpBuffer("data->data cipher *radio*", data->data, length); dumpBuffer("tag *radio* ", tag, tag_length); //copies ciphertext and tag into data->data cpyBuffer(data->data, cipherMsg, length); cpyBuffer((data->data)+length, tag, tag_length); /* * TODO: small pbm * every thing is done in bytes, so even if only 3 LB bits are sent * the max length of the msg is reduced by 1 byte * I am sending one more byte over the air, but actually taking advantage * of only two bits (this is just a hack, actually I need to find a way * to send only more few bits) */ data->data[length+tag_length] = iv[7] & (0xff >> (8-nbreLB)); dumpBuffer("doit marcher send", data->data, sizeof(data->data)); /* as the tag is also sent, the max length of the msgs is reduced by tag_length */ state = TRUE; if ((length+tag_length+1) > DATA_LENGTH) { /* the 1 is for LB */ dbg(DBG_AM, "AM: Send length too long: %i. Fail.\n", (int)length); state = FALSE; return FAIL; } if(incIV(iv)!= SUCCESS) return FAIL; } dbg(DBG_BOOT, "=>gm AM:msg sent\n"); return SUCCESS; } command error_t AMSend.cancel[uint8_t id](message_t* msg) { return SUCCESS; } command uint8_t AMSend.maxPayloadLength[uint8_t id]() { return 0; } command void* AMSend.getPayload[uint8_t id](message_t* msg, uint8_t len) { return NULL; } command void Packet.clear(message_t* msg) { } command uint8_t Packet.payloadLength(message_t* msg) { return 0; } command uint8_t Packet.maxPayloadLength() { return 0; } command void* Packet.getPayload(message_t* msg, uint8_t len) { return msg; } command void Packet.setPayloadLength(message_t* msg, uint8_t len) { } command am_addr_t AMPacket.address() { return 0; } command am_addr_t AMPacket.destination(message_t* amsg) { return 0; } command bool AMPacket.isForMe(message_t* amsg) { return FALSE; } command am_id_t AMPacket.type(message_t* amsg) { return 0; } command void AMPacket.setDestination(message_t* amsg, am_addr_t addr) { } command void AMPacket.setType(message_t* amsg, am_id_t t) { } command am_addr_t AMPacket.source(message_t* amsg) { return 0; } command void AMPacket.setSource(message_t* amsg, am_addr_t addr) { } command am_group_t AMPacket.group(message_t* amsg) { return 0; } command void AMPacket.setGroup(message_t* amsg, am_group_t grp) { } command am_group_t AMPacket.localGroup() { return 0; } async command error_t Acks.requestAck( message_t* msg ) { return SUCCESS; } async command error_t Acks.noAck( message_t* msg ) { return SUCCESS; } async command bool Acks.wasAcked(message_t* msg) { return FALSE; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -