zdsecmgr.s51

来自「TI的基于ZIGBEE2006的协议栈」· S51 代码 · 共 1,559 行 · 第 1/5 页

S51
1,559
字号
//  341 
//  342 
//  343   // allocate MASTER key data
//  344   size = (short)( sizeof(ZDSecMgrMasterKeyData_t) * ZDSECMGR_MASTERKEY_MAX );
//  345 
//  346   ZDSecMgrMasterKeyData = osal_mem_alloc( size );
//  347 
//  348   // initialize MASTER key data
//  349   if ( ZDSecMgrMasterKeyData != NULL )
//  350   {
//  351     for ( index = 0; index < ZDSECMGR_MASTERKEY_MAX; index++ )
//  352     {
//  353       ZDSecMgrMasterKeyData[index].ami = INVALID_NODE_ADDR;
//  354     }
//  355 
//  356     // check if preconfigured keys are enabled
//  357     //-------------------------------------------------------------------------
//  358     #if ( ZDSECMGR_PRECONFIG_MAX != 0 )
//  359     //-------------------------------------------------------------------------
//  360     if ( zgPreConfigKeys == TRUE )
//  361     {
//  362       // sync configured data
//  363       entry.user = ADDRMGR_USER_SECURITY;
//  364 
//  365       for ( index = 0; index < ZDSECMGR_PRECONFIG_MAX; index++ )
//  366       {
//  367         // check for Address Manager entry
//  368         AddrMgrExtAddrSet( entry.extAddr,
//  369                            (uint8*)ZDSecMgrPreConfigData[index].extAddr );
//  370 
//  371         if ( AddrMgrEntryLookupExt( &entry ) != TRUE )
//  372         {
//  373           // update Address Manager
//  374           AddrMgrEntryUpdate( &entry );
//  375         }
//  376 
//  377         if ( entry.index != INVALID_NODE_ADDR )
//  378         {
//  379           // sync MASTER keys with Address Manager index
//  380           ZDSecMgrMasterKeyData[index].ami = entry.index;
//  381 
//  382           osal_cpyExtAddr( ZDSecMgrMasterKeyData[index].key,
//  383                            (void*)ZDSecMgrPreConfigData[index].key );
//  384         }
//  385       }
//  386     }
//  387     //-------------------------------------------------------------------------
//  388     #endif // ( ZDSECMGR_PRECONFIG_MAX != 0 )
//  389     //-------------------------------------------------------------------------
//  390   }
//  391 }
//  392 #endif // defined ( ZDSECMGR_COMMERCIAL )
//  393 
//  394 #if defined ( ZDSECMGR_COMMERCIAL )
//  395 /******************************************************************************
//  396  * @fn          ZDSecMgrExtAddrLookup
//  397  *
//  398  * @brief       Lookup index for specified EXT address.
//  399  *
//  400  * @param       extAddr - [in] EXT address
//  401  * @param       ami     - [out] Address Manager index
//  402  *
//  403  * @return      ZStatus_t
//  404  */
//  405 ZStatus_t ZDSecMgrExtAddrLookup( uint8* extAddr, uint16* ami )
//  406 {
//  407   ZStatus_t      status;
//  408   AddrMgrEntry_t entry;
//  409 
//  410 
//  411   // lookup entry
//  412   entry.user = ADDRMGR_USER_SECURITY;
//  413   AddrMgrExtAddrSet( entry.extAddr, extAddr );
//  414 
//  415   if ( AddrMgrEntryLookupExt( &entry ) == TRUE )
//  416   {
//  417     // return successful results
//  418     *ami   = entry.index;
//  419     status = ZSuccess;
//  420   }
//  421   else
//  422   {
//  423     // return failed results
//  424     *ami   = entry.index;
//  425     status = ZNwkUnknownDevice;
//  426   }
//  427 
//  428   return status;
//  429 }
//  430 #endif // defined ( ZDSECMGR_COMMERCIAL )
//  431 
//  432 #if defined ( ZDSECMGR_COMMERCIAL )
//  433 /******************************************************************************
//  434  * @fn          ZDSecMgrExtAddrStore
//  435  *
//  436  * @brief       Store EXT address.
//  437  *
//  438  * @param       extAddr - [in] EXT address
//  439  * @param       ami     - [out] Address Manager index
//  440  *
//  441  * @return      ZStatus_t
//  442  */
//  443 ZStatus_t ZDSecMgrExtAddrStore( uint8* extAddr, uint16* ami )
//  444 {
//  445   ZStatus_t      status;
//  446   AddrMgrEntry_t entry;
//  447 
//  448 
//  449   // add entry
//  450   entry.user    = ADDRMGR_USER_SECURITY;
//  451   entry.nwkAddr = INVALID_NODE_ADDR;
//  452   AddrMgrExtAddrSet( entry.extAddr, extAddr );
//  453 
//  454   if ( AddrMgrEntryUpdate( &entry ) == TRUE )
//  455   {
//  456     // return successful results
//  457     *ami   = entry.index;
//  458     status = ZSuccess;
//  459   }
//  460   else
//  461   {
//  462     // return failed results
//  463     *ami   = entry.index;
//  464     status = ZNwkUnknownDevice;
//  465   }
//  466 
//  467   return status;
//  468 }
//  469 #endif // defined ( ZDSECMGR_COMMERCIAL )
//  470 
//  471 #if defined ( ZDSECMGR_COMMERCIAL )
//  472 /******************************************************************************
//  473  * @fn          ZDSecMgrMasterKeyLookup
//  474  *
//  475  * @brief       Lookup MASTER key for specified address index.
//  476  *
//  477  * @param       ami - [in] Address Manager index
//  478  * @param       key - [out] valid MASTER key
//  479  *
//  480  * @return      ZStatus_t
//  481  */
//  482 ZStatus_t ZDSecMgrMasterKeyLookup( uint16 ami, uint8** key )
//  483 {
//  484   ZStatus_t status;
//  485   uint16    index;
//  486 
//  487 
//  488   // initialize results
//  489   *key   = NULL;
//  490   status = ZNwkUnknownDevice;
//  491 
//  492   // verify data is available
//  493   if ( ZDSecMgrMasterKeyData != NULL )
//  494   {
//  495     for ( index = 0; index < ZDSECMGR_MASTERKEY_MAX ; index++ )
//  496     {
//  497       if ( ZDSecMgrMasterKeyData[index].ami == ami )
//  498       {
//  499         // return successful results
//  500         *key   = ZDSecMgrMasterKeyData[index].key;
//  501         status = ZSuccess;
//  502 
//  503         // break from loop
//  504         index  = ZDSECMGR_MASTERKEY_MAX;
//  505       }
//  506     }
//  507   }
//  508 
//  509   return status;
//  510 }
//  511 #endif // defined ( ZDSECMGR_COMMERCIAL )
//  512 
//  513 #if defined ( ZDSECMGR_COMMERCIAL )
//  514 /******************************************************************************
//  515  * @fn          ZDSecMgrMasterKeyStore
//  516  *
//  517  * @brief       Store MASTER key for specified address index.
//  518  *
//  519  * @param       ami - [in] Address Manager index
//  520  * @param       key - [in] valid key to store
//  521  *
//  522  * @return      ZStatus_t
//  523  */
//  524 ZStatus_t ZDSecMgrMasterKeyStore( uint16 ami, uint8* key )
//  525 {
//  526   ZStatus_t status;
//  527   uint16    index;
//  528   uint8*    entry;
//  529 
//  530 
//  531   // initialize results
//  532   status = ZNwkUnknownDevice;
//  533 
//  534   // verify data is available
//  535   if ( ZDSecMgrMasterKeyData != NULL )
//  536   {
//  537     for ( index = 0; index < ZDSECMGR_MASTERKEY_MAX ; index++ )
//  538     {
//  539       if ( ZDSecMgrMasterKeyData[index].ami == INVALID_NODE_ADDR )
//  540       {
//  541         // store EXT address index
//  542         ZDSecMgrMasterKeyData[index].ami = ami;
//  543 
//  544         entry = ZDSecMgrMasterKeyData[index].key;
//  545 
//  546         if ( key != NULL )
//  547         {
//  548           osal_cpyExtAddr( entry, key );
//  549         }
//  550         else
//  551         {
//  552           osal_memset( entry, 0, SEC_KEY_LEN );
//  553         }
//  554 
//  555         // return successful results
//  556         status = ZSuccess;
//  557 
//  558         // break from loop
//  559         index  = ZDSECMGR_MASTERKEY_MAX;
//  560       }
//  561     }
//  562   }
//  563 
//  564   return status;
//  565 }
//  566 #endif // !defined ( ZDSECMGR_COMMERCIAL )
//  567 
//  568 #if defined ( ZDSECMGR_COMMERCIAL )
//  569 /******************************************************************************
//  570  * @fn          ZDSecMgrEntryInit
//  571  *
//  572  * @brief       Initialize entry sub module
//  573  *
//  574  * @param       none
//  575  *
//  576  * @return      none
//  577  */
//  578 void ZDSecMgrEntryInit( void )
//  579 {
//  580   uint16 size;
//  581   uint16 index;
//  582 
//  583 
//  584   // allocate entry data
//  585   size = (short)( sizeof(ZDSecMgrEntry_t) * ZDSECMGR_ENTRY_MAX );
//  586 
//  587   ZDSecMgrEntries = osal_mem_alloc( size );
//  588 
//  589   // initialize data
//  590   if ( ZDSecMgrEntries != NULL )
//  591   {
//  592     for( index = 0; index < ZDSECMGR_ENTRY_MAX; index++ )
//  593     {
//  594       ZDSecMgrEntries[index].ami = INVALID_NODE_ADDR;
//  595     }
//  596   }
//  597 }
//  598 #endif // defined ( ZDSECMGR_COMMERCIAL )
//  599 
//  600 #if defined ( ZDSECMGR_COMMERCIAL )
//  601 /******************************************************************************
//  602  * @fn          ZDSecMgrEntryLookup
//  603  *
//  604  * @brief       Lookup entry index using specified NWK address.
//  605  *
//  606  * @param       nwkAddr - [in] NWK address
//  607  * @param       entry   - [out] valid entry
//  608  *
//  609  * @return      ZStatus_t
//  610  */
//  611 ZStatus_t ZDSecMgrEntryLookup( uint16 nwkAddr, ZDSecMgrEntry_t** entry )
//  612 {
//  613   ZStatus_t      status;
//  614   uint16         index;
//  615   AddrMgrEntry_t addrMgrEntry;
//  616 
//  617 
//  618   // initialize results
//  619   *entry = NULL;
//  620   status = ZNwkUnknownDevice;
//  621 
//  622   // verify data is available
//  623   if ( ZDSecMgrEntries != NULL )
//  624   {
//  625     addrMgrEntry.user    = ADDRMGR_USER_SECURITY;
//  626     addrMgrEntry.nwkAddr = nwkAddr;
//  627 
//  628     if ( AddrMgrEntryLookupNwk( &addrMgrEntry ) == TRUE )
//  629     {
//  630       for ( index = 0; index < ZDSECMGR_ENTRY_MAX ; index++ )
//  631       {
//  632         if ( addrMgrEntry.index == ZDSecMgrEntries[index].ami )
//  633         {
//  634           // return successful results
//  635           *entry = &ZDSecMgrEntries[index];
//  636           status = ZSuccess;
//  637 
//  638           // break from loop
//  639           index = ZDSECMGR_ENTRY_MAX;
//  640         }
//  641       }
//  642     }
//  643   }
//  644 
//  645   return status;
//  646 }
//  647 #endif // defined ( ZDSECMGR_COMMERCIAL )
//  648 
//  649 #if defined ( ZDSECMGR_COMMERCIAL )
//  650 /******************************************************************************
//  651  * @fn          ZDSecMgrEntryLookupAMI
//  652  *

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?