YOSHIHISA TABUCHI / Mbed OS Host_Software_MAX32664GWEB_HR_EXTENDEDtest

Dependencies:   BMI160 max32630hsp3 MemoryLCD USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bootldrAPI.cpp Source File

bootldrAPI.cpp

00001 /*
00002  * bootldrInterface.cpp
00003  *
00004  *  Created on: Feb 7, 2019
00005  *      Author: Yagmur.Gok
00006  */
00007 
00008 #include <mbed.h>  /*for type definitions*/
00009 #include "bootldrAPI.h"
00010 #include "SHComm.h"
00011 #include "demoDefinitions.h"
00012 
00013 //extern Serial daplink;
00014 
00015 //#define SERIALOUT printf
00016 //#define SERIALIN  printf
00017 
00018 #define COMM_SUCCESS        0
00019 #define COMM_GENERAL_ERROR  -1
00020 #define COMM_INVALID_PARAM  -254
00021 #define COMM_NOT_RECOGNIZED -255
00022 
00023 #define BL_FLASH_ERR_GENERAL    -1
00024 #define BL_FLASH_ERR_CHECKSUM   -2
00025 #define BL_FLASH_ERR_AUTH       -3
00026 #define BL_SET_NUM_PAGES_FAIL   -4
00027 #define BL_FLASS_ERASE_FAIL     -5
00028 #define BL_SET_IV_FAIL          -6
00029 #define BL_FLASHING_FAIL        -7
00030 #define BL_RAM_ALLOC_FAIL       -8
00031 
00032 #define AES_NONCE_SIZE 11
00033 #define AES_AUTH_SIZE  16
00034 #define BOOTLOADER_MAX_PAGE_SIZE (8192)
00035 #define CHECKBYTES_SIZE (16)
00036 #define FLASHCMDBYTES (2)
00037 
00038 #define SS_BOOTLOADER_ERASE_DELAY   700
00039 #define AES_NONCE_SIZE              11
00040 #define AES_AUTH_SIZE               16
00041 #define MAX_PAGE_SIZE               8192
00042 #define CHECKBYTES_SIZE             16
00043 
00044 #define PAGE_WRITE_DELAY_MS         170
00045 #define MAX_PAGE_NUMBER             31
00046 #define PAGE_ERASE_CMD_SLEEP_MS     50
00047 #define BL_CFG_SAVE_CMD_SLEEP_MS    50
00048 
00049 static int parse_iv(const char* cmd, uint8_t* iv_bytes);
00050 static int parse_auth(const char* cmd, uint8_t *auth_bytes);
00051 static int is_hub_ready_for_flash(void);
00052 static void clear_state_info(void);
00053 
00054 
00055 typedef struct {
00056     int num_allocated_pages; /* Allocated page size */
00057     int num_pages;
00058     int num_received_pages;
00059     int page_size;
00060     uint8_t auth[AES_AUTH_SIZE];
00061     uint8_t nonce[AES_NONCE_SIZE];
00062     uint8_t pages[MAX_PAGE_NUMBER * (MAX_PAGE_SIZE + CHECKBYTES_SIZE)]; //TODO: Use dynamic allocation
00063 } app_image_t;
00064 
00065 
00066 static app_image_t *app_image = NULL;
00067 
00068 static struct {
00069 
00070     uint32_t num_pages;
00071     uint32_t page_size;
00072     uint32_t hub_mode_bootloader;
00073     uint32_t is_iv_set;
00074     uint32_t is_auth_done;
00075     uint32_t is_flash_erased;
00076     uint32_t flag_image_on_ram;
00077     uint32_t bootcmds_delay_factor;
00078     uint32_t ebl_mode;
00079 
00080 }bootldrState = { 0 , 0 , 0 ,0 , 0 , 0 , 0 , 1 ,1};
00081 
00082 
00083 
00084 int BOOTLDR_get_host_bootloader_state(const char *null_arg){
00085 
00086     SERIALOUT(" \r\n BOOT STATE INFO: \r\n num_pages= %d \r\n page_size= %d \r\n is_iv_set= %d \r\n is_auth_done= %d \r\n is_flash_erased= %d \r\n flag_image_on_ram= %d \r\n bootcmds_delay_factor= %d \r\n ebl_mode= %d \r\n",
00087                                          bootldrState.num_pages,
00088                                          bootldrState.page_size,
00089                                          bootldrState.is_iv_set,
00090                                          bootldrState.is_auth_done,
00091                                          bootldrState.is_flash_erased,
00092                                          bootldrState.flag_image_on_ram,
00093                                          bootldrState.bootcmds_delay_factor,
00094                                          bootldrState.ebl_mode );
00095 
00096 
00097 }
00098 
00099 int SH_BOOTLDR_enter_blmode(const char *null_arg){
00100 
00101     int status = 0x00;
00102 
00103     //status = sh_put_in_bootloader();
00104     //status = sh_set_ebl_mode((uint8_t)1); /* 1: GPIO rest 0: CMD reset*/
00105 
00106     if( status == 0x00) {
00107 
00108         //////////status = sh_reset_to_bootloader(); - CHECKIF PROBLEM STILL PRESENT!!
00109         status = sh_debug_reset_to_bootloader();
00110         //status = sh_set_sensorhub_operating_mode((uint8_t)0x08);
00111         if (status == 0x00) {
00112            SERIALOUT("\r\n%s err=%d\r\n", "bootldr", COMM_SUCCESS);
00113            bootldrState.hub_mode_bootloader  = 1;
00114         }
00115         else
00116            SERIALOUT("\r\n%s err=%d\r\n", "bootldr", COMM_GENERAL_ERROR);
00117     }
00118 
00119     return status;
00120 
00121 }
00122 
00123 
00124 int SH_BOOTLDR_exit_blmode(const char *null_arg){
00125 
00126     int status;
00127     status = sh_reset_to_main_app() ; //sh_exit_from_bootloader();
00128     if (status == 0x00)
00129         printf("\r\n exited from bootloader mode \r\n");
00130 
00131     if (status == 0x00) {
00132        SERIALOUT("\r\n%s err=%d\r\n", "exit", COMM_SUCCESS);
00133        bootldrState.hub_mode_bootloader  = 0;
00134     }
00135     else
00136        SERIALOUT("\r\n%s err=%d\r\n", "exit", COMM_GENERAL_ERROR);
00137 
00138     return status;
00139 
00140 }
00141 
00142 int SH_BOOTLOADER_image_on_ram( const char *arg ){
00143 
00144       int status = COMM_SUCCESS;
00145       int tmp;
00146       sscanf(arg, "%*s %d", &tmp );
00147       bootldrState.flag_image_on_ram = (tmp > 0)? 1:0 ;
00148 
00149       if(tmp == 1){
00150 
00151           app_image = (app_image_t*) malloc(sizeof(*app_image));
00152           if(app_image != NULL){
00153 
00154               app_image->num_allocated_pages = MAX_PAGE_NUMBER;
00155               app_image->num_pages = 0;
00156               app_image->num_received_pages = 0;
00157               app_image->page_size = MAX_PAGE_SIZE;
00158               //app_image->nonce = {0};
00159               //app_image->auth  = {0};
00160               //app_image->pages = {0};
00161 
00162           }else {
00163               SERIALOUT("Memory allocation fail for ram image \r\n");
00164               status = BL_RAM_ALLOC_FAIL;
00165           }
00166 
00167       }
00168 
00169       SERIALOUT("\r\n%s err=%d\r\n", "image_on_ram", COMM_SUCCESS);
00170 
00171 }
00172 
00173 int SH_BOOTLDR_get_pagesz(const char *null_arg){
00174 
00175     int status;
00176     int pageSize;
00177 
00178     if (bootldrState.flag_image_on_ram) {
00179         SERIALOUT("\r\n%s value=%d err=%d\r\n", "page_size", MAX_PAGE_SIZE, COMM_SUCCESS);
00180         app_image->page_size   = MAX_PAGE_SIZE;
00181         bootldrState.page_size = MAX_PAGE_SIZE;
00182         SERIALOUT("\r\n%s err=%d\r\n", "image_on_ram", 1);
00183 
00184     }else {
00185 
00186         status = sh_get_bootloader_pagesz(&pageSize);
00187         if (status == 0x00 ){
00188               if( pageSize == -2){
00189                   SERIALOUT("\r\n Page size over maximum allowable \r\n");
00190                   status = -1;
00191               }else {
00192                   SERIALOUT("\r\n%s value=%d err=%d\r\n", "page_size", pageSize, status);
00193                   bootldrState.page_size = pageSize;
00194               }
00195         }else
00196             SERIALOUT("\r\n%s err=%d\r\n", "page_size", status);
00197 
00198     }
00199     return status;
00200 
00201 }
00202 
00203 int SH_BOOTLDR_set_pagecount(const char *arg){
00204 
00205     int status = -1;
00206     int pageCount;
00207 
00208     if(sscanf(arg, "%*s %d", &pageCount)){
00209 
00210         if(bootldrState.flag_image_on_ram){
00211             app_image->num_pages =  (pageCount <= MAX_PAGE_NUMBER)?  pageCount:0;
00212             app_image->num_allocated_pages = MAX_PAGE_NUMBER;
00213             bootldrState.num_pages = app_image->num_pages;
00214 
00215         }else {
00216 
00217             status = sh_set_bootloader_numberofpages(pageCount);
00218             if (status == 0x00){
00219                 bootldrState.num_pages = pageCount;
00220             }else
00221                 bootldrState.num_pages = 0;
00222         }
00223     }
00224     SERIALOUT("\r\n%s err=%d\r\n", "num_pages", status);
00225     return status;
00226 
00227 }
00228 
00229 int SH_BOOTLDR_set_iv(const char *arg) {
00230 
00231     uint8_t iv_bytes[AES_NONCE_SIZE];
00232     int status =  parse_iv(arg, &iv_bytes[0]);
00233     if( status == 0x00){
00234 
00235         if(bootldrState.flag_image_on_ram){
00236             int i=0;
00237             for(i = 0 ; i != AES_NONCE_SIZE ; i++)
00238                 app_image->nonce[i] = iv_bytes[i];
00239             bootldrState.is_iv_set = 1;
00240 
00241         }else {
00242 
00243             status = sh_set_bootloader_iv(iv_bytes);
00244             if( status == 0x00 ) {
00245                 bootldrState.is_iv_set = 1;
00246             }
00247             else {
00248                 bootldrState.is_iv_set = 0;
00249                 status = COMM_GENERAL_ERROR;
00250             }
00251         }
00252     }
00253     SERIALOUT("\r\n%s err=%d\r\n", "set_iv", status);
00254 
00255     return status;
00256 
00257 }
00258 
00259 
00260 int SH_BOOTLDR_set_authentication(const char *arg){
00261 
00262     uint8_t auth_bytes[AES_AUTH_SIZE];
00263     int status = parse_auth(arg, &auth_bytes[0]);
00264     if( status == 0x00){
00265 
00266         if(bootldrState.flag_image_on_ram){
00267             int i=0;
00268             for(i = 0 ; i != AES_AUTH_SIZE ; i++)
00269                 app_image->auth[i] = auth_bytes[i];
00270             bootldrState.is_auth_done = 1;
00271 
00272         }else {
00273 
00274             status = sh_set_bootloader_auth(auth_bytes);
00275             if( status == 0x00 ){
00276                 bootldrState.is_auth_done = 1;
00277             }
00278             else
00279                 status = COMM_GENERAL_ERROR;
00280         }
00281 
00282     }
00283     SERIALOUT("\r\n%s err=%d\r\n", "set_auth", status);
00284 
00285     return status;
00286 
00287 }
00288 
00289 int SH_BOOTLDR_eraseflash(const char *null_arg){
00290 
00291     int status;
00292     if(bootldrState.flag_image_on_ram){
00293         SERIALOUT("\r\n%s err=%d\r\n", "erase", COMM_SUCCESS);
00294         status == 0x00 /*SS_SUCCESS*/;
00295 
00296     }else {
00297 
00298         status = sh_set_bootloader_erase();
00299         if(status == 0x00 /*SS_SUCCESS*/) {
00300             bootldrState.is_flash_erased = 1;
00301         }else{
00302             status = COMM_GENERAL_ERROR;
00303         }
00304         SERIALOUT("\r\n%s err=%d\r\n", "erase", status);
00305 
00306     }
00307     return status;
00308 
00309 }
00310 
00311 
00312 int SH_BOOTLDR_receive_image_to_ram(void){
00313 
00314 
00315     int status;
00316     int totalBytes = 0;
00317     int currentPage = 1;
00318 
00319     if( app_image != NULL && app_image->num_allocated_pages > 0) {
00320 
00321         uint8_t *page = &app_image->pages[0];
00322         uint32_t offset = 0;
00323         while (currentPage <= app_image->num_pages) {
00324 
00325             while (totalBytes < (MAX_PAGE_SIZE + CHECKBYTES_SIZE)) {
00326                 page[totalBytes++] = SERIALIN(); // daplink.getc();  ; /////////////////////////////////////////////////////m_USB->_getc();
00327             }
00328 
00329             currentPage++;
00330             SERIALOUT("\r\npageFlashDone err=%d\r\n", COMM_SUCCESS);
00331 
00332             offset += MAX_PAGE_SIZE + CHECKBYTES_SIZE;
00333             page = &app_image->pages[offset];
00334             totalBytes = 0;
00335         }
00336 
00337         app_image->num_received_pages = currentPage;
00338 
00339         status =  COMM_SUCCESS;
00340 
00341     }else
00342         status =  COMM_GENERAL_ERROR;
00343 
00344     return status;
00345 
00346 }
00347 
00348 int SH_BOOTLDR_flash_pages(void){
00349 
00350 
00351     int totalBytes = 0;
00352     int currentPage = 1;
00353     char charbuf_flash[256];
00354     int data_len_flash = 0;
00355     int status;
00356 
00357     static uint8_t tx_buf[ BOOTLOADER_MAX_PAGE_SIZE + CHECKBYTES_SIZE + FLASHCMDBYTES] = { SS_FAM_W_BOOTLOADER, SS_CMDIDX_SENDPAGE };
00358     uint8_t *data_buffer = &tx_buf[2];
00359 
00360     if(!is_hub_ready_for_flash()){
00361         printf("missing condition for flashing:  no page size , no page number, iv notset , no outhentication , flash noterased or mode is not bootloader!\r\n");
00362         clear_state_info();
00363         return -1;
00364     }
00365     printf(" \r\n NOW WE ARE FLASHING THE PAGES..........\r\n");
00366     printf(" \r\n page_size:  %d \r\n", bootldrState.page_size);
00367     printf(" \r\n num_pages:  %d \r\n", bootldrState.num_pages);
00368 
00369     while (currentPage <= bootldrState.num_pages) {
00370 
00371         while (totalBytes < (bootldrState.page_size + CHECKBYTES_SIZE)) {
00372             data_buffer[totalBytes++] = SERIALIN(); //daplink.getc(); //m_USB->_getc();  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MYG
00373             //Here we should be able to take the data over BLE
00374         }
00375         printf(" \r\n NOW WE GOT A  PAGE..........\r\n");
00376         //status = sh_bootloader_flashpage(&tx_buf[0] , bootldrState.page_size);
00377 
00378         status = sh_write_cmd(tx_buf, bootldrState.page_size + CHECKBYTES_SIZE + 2, 2000);
00379 
00380         if (status == 0x00)
00381                 printf(" \r\n NOW WE PUSHED A  PAGE..........\r\n");
00382 /*
00383         if (status == 0x00){
00384             currentPage++;
00385             SERIALOUT("\r\npageFlashDone err=%d\r\n", COMM_SUCCESS);
00386         }else{
00387 
00388             if (status == SS_ERR_BTLDR_CHECKSUM)
00389                 SERIALOUT("\r\npageFlashDone err=%d\r\n", BL_FLASH_ERR_CHECKSUM);
00390             else
00391                 SERIALOUT("\r\npageFlashDone err=%d\r\n", BL_FLASH_ERR_GENERAL);
00392 
00393         }
00394  */
00395 
00396         if (status == SS_ERR_BTLDR_CHECKSUM) {
00397 
00398             data_len_flash = snprintf(charbuf_flash, sizeof(charbuf_flash), "\r\npageFlashDone err=%d\r\n", FLASH_ERR_CHECKSUM);
00399             SERIALOUT(charbuf_flash);
00400         } else if (status != SS_SUCCESS) {
00401 
00402             data_len_flash = snprintf(charbuf_flash, sizeof(charbuf_flash), "\r\npageFlashDone err=%d\r\n", FLASH_ERR_GENERAL);
00403             SERIALOUT(charbuf_flash);
00404         } else {
00405             currentPage++;
00406 
00407             data_len_flash = snprintf(charbuf_flash, sizeof(charbuf_flash), "\r\npageFlashDone err=%d\r\n", COMM_SUCCESS);
00408             SERIALOUT(charbuf_flash);
00409         }
00410         totalBytes = 0;
00411 
00412     }
00413     //SERIALOUT(" all pages are flashed \r\n");
00414     clear_state_info();
00415 
00416     return status;
00417 
00418 }
00419 
00420 
00421 int SH_BOOTLDR_flash(const char *null_arg){
00422 
00423     int status;
00424     if(bootldrState.flag_image_on_ram)
00425         status = SH_BOOTLDR_receive_image_to_ram();
00426     else
00427         status = SH_BOOTLDR_flash_pages();
00428 
00429     SERIALOUT("\r\n%s err=%d\r\n", "flash", status);
00430 
00431     return status;
00432 }
00433 
00434 
00435 int SH_BOOTLDR_flash_appimage_from_ram(const char *null_arg){
00436 
00437 
00438     int currentPage = 1;
00439     uint32_t offset = 0;
00440     int ret;
00441 
00442     if(app_image == NULL)
00443         return -1;
00444 
00445     /* Put device to bootloader mode */
00446     int status = SH_BOOTLDR_enter_blmode(NULL);
00447     if( status != 0x00)
00448          return -1;
00449 
00450     wait_ms(10);
00451 
00452     status = sh_set_bootloader_numberofpages(app_image->num_pages);
00453     SERIALOUT("*** set_num_page... ret: %d\n", ret);
00454     if (status != 0x00) {
00455         return BL_SET_NUM_PAGES_FAIL;
00456     }
00457 
00458     status = sh_set_bootloader_iv(app_image->nonce);
00459     SERIALOUT("*** set_iv... ret: %d\n", ret);
00460     if (status != 0) {
00461         return BL_SET_IV_FAIL;
00462     }
00463 
00464     status = sh_set_bootloader_auth(app_image->auth);
00465     SERIALOUT("*** set_auth... ret: %d\n", ret);
00466     if (status != 0) {
00467         return BL_FLASH_ERR_AUTH;
00468     }
00469 
00470     status = sh_set_bootloader_erase() ;
00471     SERIALOUT("*** erase app memory... ret: %d\n", ret);
00472     if (status != 0) {
00473         return BL_FLASS_ERASE_FAIL;
00474     }
00475 
00476     static uint8_t tx_buf[MAX_PAGE_SIZE + CHECKBYTES_SIZE + 2];
00477 
00478     tx_buf[0] = SS_FAM_W_BOOTLOADER;
00479     tx_buf[1] = SS_CMDIDX_SENDPAGE;
00480 
00481     while (currentPage <= app_image->num_pages) {
00482 
00483         memcpy(&tx_buf[2], &app_image->pages[offset], MAX_PAGE_SIZE + CHECKBYTES_SIZE);
00484 
00485         status = sh_write_cmd(tx_buf, MAX_PAGE_SIZE + CHECKBYTES_SIZE + 2, bootldrState.bootcmds_delay_factor * PAGE_WRITE_DELAY_MS);
00486 
00487         if (status == SS_ERR_BTLDR_CHECKSUM) {
00488 
00489             SERIALOUT("\r\npageFlashDone err=%d\r\n", BL_FLASH_ERR_CHECKSUM);
00490             break;
00491         } else if (status != SS_SUCCESS) {
00492 
00493             SERIALOUT("\r\npageFlashDone err=%d\r\n", BL_FLASH_ERR_GENERAL);
00494             break;
00495         } else {
00496 
00497             SERIALOUT("\r\npageFlashDone err=%d\r\n", COMM_SUCCESS);
00498         }
00499 
00500         offset += MAX_PAGE_SIZE + CHECKBYTES_SIZE;
00501         currentPage++;
00502     }
00503 
00504     return COMM_SUCCESS;
00505 
00506 }
00507 
00508 int SH_BOOTLDR_set_host_ebl_mode(const char *arg) {
00509 
00510     int status;
00511     int tmp;
00512     sscanf(arg, "%*s %*s %*s %d", &tmp);
00513     status = sh_set_ebl_mode(tmp);
00514     if( status == 0x00) {
00515         bootldrState.ebl_mode = tmp;
00516     }else
00517         status = COMM_INVALID_PARAM;
00518 
00519     SERIALOUT("\r\n%s err=%d\r\n", "set_cfg host ebl",status);
00520 
00521     return status;
00522 
00523 }
00524 
00525 int SH_BOOTLDR_get_host_ebl_mode(const char *null_arg){
00526 
00527       int value;
00528       value = sh_get_ebl_mode();
00529       SERIALOUT("\r\n%s value=%s\r\n", "get_cfg host ebl", (value==1)? "GPIO_RST_MODE":"CMD_RST_MODE");
00530       return 0x00;
00531 }
00532 
00533 int SH_BOOTLDR_set_host_bootcmds_delay_factor( const char *arg) {
00534 
00535      int status;
00536      int tmp;
00537      sscanf(arg, "%*s %*s %*s %d", &tmp);
00538      status =  sh_set_bootloader_delayfactor( tmp);
00539      if( status == 0x00) {
00540          bootldrState.bootcmds_delay_factor = tmp;
00541      }else
00542          status = COMM_INVALID_PARAM;
00543 
00544      SERIALOUT("\r\n%s err=%d\r\n", "set_cfg host cdf",status);
00545 
00546      return status;
00547 
00548 }
00549 
00550 int SH_BOOTLDR_get_host_bootcmds_delay_factor( const char *null_arg){
00551 
00552     int value;
00553     value =  sh_get_bootloader_delayfactor();
00554     SERIALOUT("\r\n%s value=%d \r\n", "get_cfg host cdf", value);
00555     return 0x00;
00556 
00557 }
00558 
00559 static int is_hub_ready_for_flash(void){
00560 
00561     int status = 0;
00562     if( bootldrState.hub_mode_bootloader == 1 &&
00563          bootldrState.is_auth_done == 1 &&
00564           bootldrState.is_iv_set == 1 &&
00565            bootldrState.is_flash_erased == 1 &&
00566             bootldrState.num_pages > 0 &&
00567              bootldrState.page_size > 0 )
00568                 status =  1;
00569 
00570     return status;
00571 }
00572 
00573 static void clear_state_info(void) {
00574 
00575     bootldrState.is_auth_done    = 0;
00576     bootldrState.is_iv_set       = 0;
00577     bootldrState.is_flash_erased = 0;
00578     bootldrState.num_pages       = 0;
00579     bootldrState.page_size       = 0;
00580     bootldrState.hub_mode_bootloader;
00581 
00582     return;
00583 }
00584 
00585 static int parse_iv(const char* cmd, uint8_t* iv_bytes) {
00586 
00587     int status = 0x00;
00588     char cmdStr[] = "set_iv ";
00589     int length = strlen(cmd);
00590     int expected_length = strlen(cmdStr) + 2*AES_NONCE_SIZE;
00591 
00592     if (length != expected_length) {
00593         SERIALOUT("Couldn't parse IV, incorrect number of characters (len:%d, expected:%d)\n",
00594                length, expected_length);
00595         status = COMM_INVALID_PARAM;
00596     }else{
00597 
00598         const char* ivPtr = cmd + strlen(cmdStr);
00599         int num_found;
00600         int byteVal;
00601         for (int ividx = 0; ividx < AES_NONCE_SIZE; ividx++) {
00602             num_found = sscanf(ivPtr, "%2X", &byteVal);
00603 
00604             if (num_found != 1 || byteVal > 0xFF) {
00605                 status = COMM_INVALID_PARAM;
00606                 //break; //
00607                 return status;
00608             }
00609             iv_bytes[ividx] = (uint8_t)byteVal;
00610            ivPtr += 2;
00611         }
00612     }
00613     return status;
00614 
00615 }
00616 
00617 
00618 static int parse_auth(const char* cmd, uint8_t *auth_bytes){
00619 
00620     int status = 0x00;
00621     char cmdStr[] = "set_auth ";
00622     int length = strlen(cmd);
00623     int expected_length = strlen(cmdStr) + 2*AES_AUTH_SIZE;
00624 
00625     if (length != expected_length) {
00626         status = -1;
00627     }else{
00628 
00629         const char* macPtr = cmd + strlen(cmdStr);
00630 
00631         int num_found;
00632         int byteVal;
00633         for (int aidx = 0; aidx < AES_AUTH_SIZE; aidx++) {
00634             num_found = sscanf(macPtr, "%2X", &byteVal);
00635 
00636             if (num_found != 1 || byteVal > 0xFF) {
00637                 status = COMM_INVALID_PARAM;;
00638                 //break; //
00639                 return status;
00640             }
00641 
00642             auth_bytes[aidx] = (uint8_t)byteVal;
00643             macPtr += 2;
00644         }
00645 
00646     }
00647     return status;
00648 
00649 }
00650 
00651