📄 simulationm.nc
字号:
/* tab:4
*
*
* Copyright (C) 2004 by North Carolina State University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE NORTH CAROLINA STATE UNIVERSITY BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE NORTH
* CAROLINA STATE UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE NORTH CAROLINA STATE UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE NORTH CAROLINA STATE UNIVERSITY HAS NO OBLIGATION
* TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Authors: Rongfang Li
* Date: 4/25/04
*/
includes AM;
includes PolyOne;
module SimulationM {
provides {
interface StdControl;
}
uses {
interface SetupServer;
interface Sensor;
interface Leds;
}
}
implementation {
PolyShare secret[ss];
uint16_t key[4];
uint16_t compromised[ss*(T+1)]={2,4};
command result_t StdControl.init(){
call Leds.init();
// the setup server generate a set of bivariate polynomials. the parameter 3 is the number of shared polynomials of each node.
call SetupServer.init();
call Leds.greenOn();
// assign secret(shared polynomials) to a sensor node whose ID is TOS_LOCAL_ADDRESS
call SetupServer.SecretAssign(TOS_LOCAL_ADDRESS,(uint8_t *)secret);
call Leds.yellowOn();
return SUCCESS;
}
command result_t StdControl.start() {
call Sensor.init(TOS_LOCAL_ADDRESS,(uint8_t *)secret, compromised);
call Leds.greenOff();
call Leds.yellowOff();
// node 5 need to establish common key with node 0
if (TOS_LOCAL_ADDRESS==22){
call Sensor.establish_key(9);
}
// random discovery, node 7 need establish common key with node 6
// if (TOS_LOCAL_ADDRESS==7){
// call Sensor.establish_key(6);
// }
// random discovery, node 1 need establish common key with node 0
// if (TOS_LOCAL_ADDRESS==0){
// call Sensor.establish_key(1);
// }
// node 11 need to establish common key with node 3
// if (TOS_LOCAL_ADDRESS==3){
// call Sensor.establish_key(11);
// }
// random discovery, node 0 need establish common key with node 8
// if (TOS_LOCAL_ADDRESS==0){
// call Sensor.establish_key(8);
// }
// random discovery, node 2 need establish common key with node 4
// if (TOS_LOCAL_ADDRESS==2){
// call Sensor.establish_key(4);
// }
return SUCCESS;
}
command result_t StdControl.stop() {
return SUCCESS;
}
event result_t Sensor.keyEstablished(uint16_t dID, uint8_t *KEY) {
uint16_t *k;
k=(uint16_t *)KEY;
dbg(DBG_USR1,"------RESULT:node_s%d and node_d%d have established key\n",TOS_LOCAL_ADDRESS,dID);
dbg(DBG_USR1,"------RESULT:key=%X %X %X %X\n",k[0],k[1],k[2],k[3]);
call Leds.greenOn();
return SUCCESS;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -