我想用default加密,就是同一个PAN的device都只用一个key.source code如下:
void App_InitSecurity(void) { mlmeMessage_t Msg; uint8_t ret; uint8_t boolFlag; uint8_t securityMaterial[26] = { /* The key that must be common to both sides */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,1,0,0,0,0,0,0,0,0,1}; /* Security material counters - must be initialized like this They are used for checking repeated packets and assigning packet counters */ //uint8_t securityMaterialLength = sizeof(securityMaterial); uint8_t securityMaterialLength = 16;
/* The security level */ uint8_t securityLevel = 5;
/* The security mode */ uint8_t securityMode = 2; /* We will only apply security to one device and fill out the security information for this device. The first device will always have ACL entry #0. The next will have #1 etc. up to #7 */
Msg.msgType = gMlmeSetReq_c; Msg.msgData.setReq.pibAttribute = gMPibDefaultSecurity_c; boolFlag = TRUE; Msg.msgData.setReq.pibAttributeValue = &boolFlag; ret = MSG_Send(NWK_MLME, &Msg); /* Tell how much security material that we have got */ Msg.msgType = gMlmeSetReq_c; Msg.msgData.setReq.pibAttribute = gMPibDefaultSecurityMaterialLength_c; Msg.msgData.setReq.pibAttributeValue = &securityMaterialLength; ret = MSG_Send(NWK_MLME, &Msg); /* Set security material */ Msg.msgType = gMlmeSetReq_c; Msg.msgData.setReq.pibAttribute = gMPibDefaultSecurityMaterial_c; Msg.msgData.setReq.pibAttributeValue = (uint8_t *)&securityMaterial; ret = MSG_Send(NWK_MLME, &Msg); /* Set the security suite/level */ Msg.msgType = gMlmeSetReq_c; Msg.msgData.setReq.pibAttribute = gMPibDefaultSecuritySuite_c; Msg.msgData.setReq.pibAttributeValue = (uint8_t *)&securityLevel; ret = MSG_Send(NWK_MLME, &Msg); /* Set the security mode */ Msg.msgType = gMlmeSetReq_c; Msg.msgData.setReq.pibAttribute = gMPibSecurityMode_c; Msg.msgData.setReq.pibAttributeValue = (uint8_t *)&securityMode; ret = MSG_Send(NWK_MLME, &Msg); //Uart_Print("Security was successfully applied.\n"); return; }
coordinator和enddevice都一样,出现的问题是只有coordinator能够发送数据到device,而coordinator却接收不到device的数据.datesheet上说要把MaterialLength设定为小于26来屏蔽optional counter才能使用default的key加密,但不论我把securityMaterialLength设为多少也解决不了问题.有高手能够指点一二吗?? |