Skip to content
Snippets Groups Projects
dsl_cpe_cli_vrx.c 83.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • Kenneth Johansson's avatar
    Kenneth Johansson committed
    /******************************************************************************
    
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
             Copyright 2016 - 2019 Intel Corporation
             Copyright 2015 - 2016 Lantiq Beteiligungs-GmbH & Co. KG
             Copyright 2009 - 2014 Lantiq Deutschland GmbH
             Copyright 2007 - 2008 Infineon Technologies AG
    
    Kenneth Johansson's avatar
    Kenneth Johansson committed
    7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
    
      For licensing information, see the file 'LICENSE' in the root folder of
      this software module.
    
    ******************************************************************************/
    
    /** \file
       VRX specific DSL CLI, access function implementation
    */
    
    #include "dsl_cpe_control.h"
    
    #if defined(INCLUDE_DSL_CPE_API_VRX)
    
    #include "dsl_cpe_cli.h"
    #include "drv_dsl_cpe_api.h"
    #include "drv_dsl_cpe_api_ioctl.h"
    
    /* MEI CPE driver specific headers*/
    #include "drv_mei_cpe_interface.h"
    
    #ifdef INCLUDE_DSL_CPE_CLI_SUPPORT
    
    #include "dsl_cpe_bnd_vrx.h"
    
    #undef DSL_CCA_DBG_BLOCK
    #define DSL_CCA_DBG_BLOCK DSL_CCA_DBG_CLI
    
    extern const char *sFailureReturn;
    
    /* for debugging: */
    #ifdef DSL_CLI_LOCAL
    #undef DSL_CLI_LOCAL
    #endif
    #if 0
    #define DSL_CLI_LOCAL
    #else
    #define DSL_CLI_LOCAL static
    #endif
    
    
    static const DSL_char_t g_sDms[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Input Parameter" DSL_CPE_CRLF
       "%s"
       "- DSL_uint16_t nMsgID (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nIndex (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nLength (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nPayload[0-256] (hex, for 32-bit messages payload contains maximum 128 32-bit values, leading 0's can be skipped)" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
       "%s"
       "- DSL_uint16_t nMsgID (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nIndex (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nLength (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nPayload[256] (hex, for 32-bit messages payload contains maximum 128 32-bit values)" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_DBG_DeviceMessageSend(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       /* maximum message size includinf ID, Index and Length field */
       #define VRX_MSG_LEN  262
       /**
          This bit of the Message ID identifies 32 bit aligned TC messages */
       #define VDSL2_MBX_MSG_ID_IFX_MASK 0x0010
    
       DSL_int_t ret = 0;
       DSL_DeviceMessage_t DevMsg;
       DSL_uint8_t msg[VRX_MSG_LEN];
       DSL_uint16_t *pMsg16 = (DSL_uint16_t*)&msg[0];
       DSL_uint16_t const *pMsgId = (DSL_uint16_t*)&msg[0];
       DSL_uint32_t *pMsg32 = (DSL_uint32_t*)&msg[6];
       DSL_char_t *pChar;
       DSL_uint32_t nParam = 0;
       DSL_uint32_t i = 0;
       DSL_boolean_t  bXtcMsg = DSL_FALSE;
    
    
       if (pCommands == DSL_NULL)
       {
          DSL_CPE_FPrintf(out, DSL_CPE_RET DSL_CPE_CRLF ,
             DSL_CPE_RET_VAL(DSL_ERROR));
          return -1;
       }
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 3, DSL_CLI_MIN) == DSL_FALSE)
       {
          return -1;
       }
    
       pChar = pCommands;
    
       /* get MsgId, Index and Length parameter */
       while (pChar != DSL_NULL)
       {
          /* Extract next parameter */
          if (sscanf(pChar, "%x", &nParam) > 0)
          {
             i += 2;
             *pMsg16 = (DSL_uint16_t)nParam;
             /* Find next parameter */
             pChar = strpbrk( pChar, " ");
             if (pChar != DSL_NULL)
             {
                pChar++;
                pMsg16++;
             }
             else
             {
                break;
             }
          }
          else
          {
             break;
          }
    
          if (i >= 6) break;
       }
    
       /* decide on the MsgId wether to treat 16 or 32bit params */
       if (*pMsgId & VDSL2_MBX_MSG_ID_IFX_MASK)
          bXtcMsg = DSL_TRUE;
    
    
       while (pChar != DSL_NULL)
       {
          /* Extract next parameter */
          if (sscanf(pChar, "%x", &nParam) > 0)
          {
             if (bXtcMsg == DSL_TRUE)
             {
                i += 4;
                *pMsg32 = (DSL_uint32_t)nParam;
             }
             else
             {
                i += 2;
                *pMsg16 = (DSL_uint16_t)nParam;
             }
             /* Find next parameter */
             pChar = strpbrk( pChar, " ");
             if (pChar != DSL_NULL)
             {
                pChar++;
                if (bXtcMsg == DSL_TRUE)
                   pMsg32++;
                else
                   pMsg16++;
             }
             else
             {
                break;
             }
          }
          else
          {
             break;
          }
    
          if (i >= VRX_MSG_LEN) break;
       }
       if ( (i > 0) && (i < VRX_MSG_LEN) )
       {
          /* Firmware message must consist of MsgID and two parameters minimum (6 bytes)*/
          if (i < 6)
          {
             DSL_CPE_FPrintf(out, DSL_CPE_RET"(firmware message has to be at least 3 "
                "hex parameters long - '0x' does not have to be written)" DSL_CPE_CRLF ,
                DSL_CPE_RET_VAL(DSL_ERROR));
             return -1;
          }
          else
          {
             memset(&DevMsg, 0x0, sizeof(DSL_DeviceMessage_t));
    
             DevMsg.data.pMsg    = (DSL_uint8_t*)&msg;
             DevMsg.data.nSizeTx = (DSL_uint16_t)i;
             DevMsg.data.nSizeRx = (DSL_uint16_t)VRX_MSG_LEN;
    
             ret = DSL_CPE_Ioctl (fd, DSL_FIO_DBG_DEVICE_MESSAGE_SEND, (int) &DevMsg);
    
             if ((ret < 0) && (DevMsg.accessCtl.nReturn < DSL_SUCCESS))
             {
                DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(ret));
                return ret;
             }
             else
             {
                DSL_CPE_FPrintf(out, DSL_CPE_RET"nData=\"", DSL_CPE_RET_VAL(ret));
                pMsg16 = (DSL_uint16_t*)&msg[0];
                pMsg32 = (DSL_uint32_t*)&msg[6];
                /* print Msg ID, Index and Length*/
                DSL_CPE_FPrintf(out, "%04X ", *pMsg16 );
                pMsg16++;
                DSL_CPE_FPrintf(out, "%04X ", *pMsg16 );
                pMsg16++;
                DSL_CPE_FPrintf(out, "%04X ", *pMsg16 );
                pMsg16++;
                i = 6;
                if (bXtcMsg == DSL_TRUE)
                {
                   while (i < DevMsg.data.nSizeRx)
                   {
                      DSL_CPE_FPrintf(out, "%08X ", *pMsg32 );
                      pMsg32++;
                      i += 4;
                   }
                }
                else
                {
                   while (i < DevMsg.data.nSizeRx)
                   {
                      DSL_CPE_FPrintf(out, "%04X ", *pMsg16 );
                      pMsg16++;
                      i += 2;
                   }
                }
    
                DSL_CPE_FPrintf(out, "\"" DSL_CPE_CRLF);
                return 0;
             }
          }
    
       }
       else
       {
          DSL_CPE_FPrintf(out, "DSL: error during processing of message data." DSL_CPE_CRLF );
          ret = -1;
       }
    
       return ret;
    }
    
    static const DSL_char_t g_sDmms[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Input Parameter" DSL_CPE_CRLF
       "%s"
       "- DSL_uint16_t nMsgID (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nIndex (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nLength (hex, N)" DSL_CPE_CRLF
       "- DSL_uint16_t nPayload[0-256] (hex, <data_1> <mask_1> ... <data_N> <mask_N>)" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
       "%s"
       "- DSL_uint16_t nMsgID (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nIndex (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nLength (hex)" DSL_CPE_CRLF
       "- DSL_uint16_t nPayload[256] (hex, for 32-bit messages payload contains maximum 128 32-bit values)" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_DBG_DeviceMessageModifySend(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       /* maximum mask size */
       #define VRX_MASK_LEN  (VRX_MSG_LEN - 6 /*message header size = 6*/)
    
       DSL_int_t ret = 0;
       DSL_DeviceMessageModify_t DevMsg;
       DSL_uint8_t msg[VRX_MSG_LEN];
       DSL_uint16_t *pMsg16 = (DSL_uint16_t*)&msg[0];
       DSL_uint16_t const *pMsgId = (DSL_uint16_t*)&msg[0];
       DSL_uint32_t *pMsg32 = (DSL_uint32_t*)&msg[6];
    
       DSL_uint8_t msk[VRX_MASK_LEN];
       DSL_uint16_t *pMask16 = (DSL_uint16_t*)&msk[0];
       DSL_uint32_t *pMask32 = (DSL_uint32_t*)&msk[0];
    
       DSL_char_t *pChar;
       DSL_uint32_t nParam = 0;
       DSL_uint32_t i = 0;
       DSL_boolean_t  bXtcMsg = DSL_FALSE;
       DSL_boolean_t  bProcMask = DSL_FALSE;
    
       if (pCommands == DSL_NULL)
       {
          DSL_CPE_FPrintf(out, DSL_CPE_RET DSL_CPE_CRLF ,
             DSL_CPE_RET_VAL(DSL_ERROR));
          return -1;
       }
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 3, DSL_CLI_MIN) == DSL_FALSE)
       {
          return -1;
       }
    
       pChar = pCommands;
    
       memset(msg,0,VRX_MSG_LEN);
       memset(msk,0,VRX_MASK_LEN);
    
       /* get MsgId, Index and Length parameter */
       while (pChar != DSL_NULL)
       {
          /* Extract next parameter */
          if (sscanf(pChar, "%x", &nParam) > 0)
          {
             i += 2;
             *pMsg16 = (DSL_uint16_t)nParam;
             /* Find next parameter */
             pChar = strpbrk( pChar, " ");
             if (pChar != DSL_NULL)
             {
                pChar++;
                pMsg16++;
             }
             else
             {
                break;
             }
          }
          else
          {
             break;
          }
    
          if (i >= 6) break;
       }
    
       /* decide on the MsgId wether to treat 16 or 32bit params */
       if (*pMsgId & VDSL2_MBX_MSG_ID_IFX_MASK)
          bXtcMsg = DSL_TRUE;
    
    
       while (pChar != DSL_NULL)
       {
          /* Extract next parameter */
          if (sscanf(pChar, "%x", &nParam) > 0)
          {
             if (bProcMask == DSL_TRUE)
             {
                if (bXtcMsg == DSL_TRUE)
                {
                   *pMask32 = (DSL_uint32_t)nParam;
                   pMask32++;
                }
                else
                {
                   *pMask16 = (DSL_uint16_t)nParam;
                   pMask16++;
                }
    
                bProcMask = DSL_FALSE;
             } else
             {
                if (bXtcMsg == DSL_TRUE)
                {
                   i += 4;
                   *pMsg32 = (DSL_uint32_t)nParam;
                   pMsg32++;
                }
                else
                {
                   i += 2;
                   *pMsg16 = (DSL_uint16_t)nParam;
                   pMsg16++;
                }
    
                bProcMask = DSL_TRUE;
             }
    
             /* Find next parameter */
             pChar = strpbrk( pChar, " ");
             if (pChar != DSL_NULL)
             {
                pChar++;
             }
             else
             {
                break;
             }
          } else
          {
             break;
          }
    
          if (i >= VRX_MSG_LEN) break;
       }
       if ( (i > 0) && (i < VRX_MSG_LEN) )
       {
          /* Firmware message must consist of MsgID and two parameters minimum (6 bytes)*/
          if (i < 6)
          {
             DSL_CPE_FPrintf(out, DSL_CPE_RET"(firmware message has to be at least 3 "
                "hex parameters long - '0x' does not have to be written)" DSL_CPE_CRLF ,
                DSL_CPE_RET_VAL(DSL_ERROR));
             return -1;
          }
          else
          {
             memset(&DevMsg, 0x0, sizeof(DSL_DeviceMessageModify_t));
    
             DevMsg.data.pMsg    = (DSL_uint8_t*)&msg;
             DevMsg.data.pMsgMask= (DSL_uint8_t*)&msk;
             DevMsg.data.nSizeTx = (DSL_uint16_t)i;
             DevMsg.data.nSizeRx = (DSL_uint16_t)VRX_MSG_LEN;
    
             ret = DSL_CPE_Ioctl (fd, DSL_FIO_DBG_DEVICE_MESSAGE_MODIFY_SEND, (int) &DevMsg);
    
             if ((ret < 0) && (DevMsg.accessCtl.nReturn < DSL_SUCCESS))
             {
                DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(ret));
                return ret;
             }
             else
             {
                /*Check that all data values passed with mask*/
                if (bProcMask == DSL_TRUE)
                {
                   DSL_CPE_FPrintf(out,"Last data value passed without mask."DSL_CPE_CRLF);
                   ret = DSL_WRN_CONFIG_PARAM_IGNORED;
                } else
                {
                   ret = 0;
                }
    
                DSL_CPE_FPrintf(out, DSL_CPE_RET"nData=\"", DSL_CPE_RET_VAL(ret));
                pMsg16 = (DSL_uint16_t*)&msg[0];
                pMsg32 = (DSL_uint32_t*)&msg[6];
                /* print Msg ID, Index and Length*/
                DSL_CPE_FPrintf(out, "%04X ", *pMsg16 );
                pMsg16++;
                DSL_CPE_FPrintf(out, "%04X ", *pMsg16 );
                pMsg16++;
                DSL_CPE_FPrintf(out, "%04X ", *pMsg16 );
                pMsg16++;
                i = 6;
                if (bXtcMsg == DSL_TRUE)
                {
                   while (i < DevMsg.data.nSizeRx)
                   {
                      DSL_CPE_FPrintf(out, "%08X ", *pMsg32 );
                      pMsg32++;
                      i += 4;
                   }
                }
                else
                {
                   while (i < DevMsg.data.nSizeRx)
                   {
                      DSL_CPE_FPrintf(out, "%04X ", *pMsg16 );
                      pMsg16++;
                      i += 2;
                   }
                }
    
                DSL_CPE_FPrintf(out, "\"" DSL_CPE_CRLF);
                return 0;
             }
          }
    
       }
       else
       {
          DSL_CPE_FPrintf(out, "DSL: error during processing of message data." DSL_CPE_CRLF );
          ret = -1;
       }
    
       return ret;
    }
    
    static const DSL_char_t g_sAufg[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "%s"
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
       "%s"
       "- DSL_char_t xdsl_firmware[1-256]" DSL_CPE_CRLF
       /*TODO: Handle OnChipBonding */
    #if defined(INCLUDE_DSL_BONDING) 
       "- DSL_char_t xdsl_firmware2[1-256]"DSL_CPE_CRLF
    #endif
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_AutobootUsedFirmwareGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_CPE_Control_Context_t *pCtrlCtx = DSL_NULL;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 0, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       pCtrlCtx = DSL_CPE_GetGlobalContext();
       if(pCtrlCtx == DSL_NULL)
       {
          DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(-1));
    
          return -1;
       }
    
       if (DSL_CPE_LINES_PER_DEVICE == 2)
       {
          DSL_CPE_FPrintf (out,
             DSL_CPE_RET"xdsl_firmware=%s xdsl_firmware2=%s" DSL_CPE_CRLF,
             DSL_CPE_RET_VAL(ret),
             g_sFirmwareName1 != DSL_NULL ? g_sFirmwareName1 : "n/a",
             g_sFirmwareName2 != DSL_NULL ? g_sFirmwareName2 : "n/a");
       }
       else
       {
          DSL_CPE_FPrintf (out,
             DSL_CPE_RET"xdsl_firmware=%s" DSL_CPE_CRLF,
             DSL_CPE_RET_VAL(ret),
             g_sFirmwareName1 != DSL_NULL ? g_sFirmwareName1 : "n/a");
       }
       return 0;
    }
    
    static const DSL_char_t g_sAlf[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Input Parameter" DSL_CPE_CRLF
       "%s"
       "- DSL_char_t xdsl_firmware[1-256] (Attention: Use absolute firmware path only"DSL_CPE_CRLF
       /*TODO: Handle On chip bonding */
    #if defined(INCLUDE_DSL_BONDING) 
       "- DSL_char_t xdsl_firmware2[1-256] (Attention: Use absolute firmware path only"DSL_CPE_CRLF
    #endif
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
       "%s"
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_AutobootLoadFirmware(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_char_t sFirmwareName1[256] = { 0 };
       DSL_char_t *pcFw = DSL_NULL;
       DSL_char_t *pcFw2 = DSL_NULL;
       DSL_char_t sFirmwareName2[256] = { 0 };
    #ifdef INCLUDE_FW_REQUEST_SUPPORT
       DSL_AutobootControl_t autobootCtrl;
       DSL_AutobootStatus_t  AutobootStatus;
    #endif /* INCLUDE_FW_REQUEST_SUPPORT*/
       DSL_uint32_t nDevice = 0;
       DSL_CPE_Control_Context_t *pCtrlCtx = DSL_NULL;
    
       memset(&autobootCtrl, 0x00, sizeof(DSL_AutobootControl_t));
       memset(&AutobootStatus, 0x00, sizeof(DSL_AutobootStatus_t));
    
       if (DSL_CPE_LINES_PER_DEVICE == 2)
       {
          if (DSL_CPE_CLI_CheckParamNumber(pCommands, 2, DSL_CLI_EQUALS) == DSL_FALSE)
          {
             return -1;
          }
       }
       else
       {
          if (DSL_CPE_CLI_CheckParamNumber(pCommands, 1, DSL_CLI_EQUALS) == DSL_FALSE)
          {
             return -1;
          }
       }
    
       if (DSL_CPE_LINES_PER_DEVICE == 2)
       {
          sscanf (pCommands, "%256s %256s", sFirmwareName1, sFirmwareName2);
       }
       else
       {
          sscanf (pCommands, "%256s", sFirmwareName1);
       }
    
       /* Get first (default) firmware binary. */
       if (strlen(sFirmwareName1) > 0)
       {
          if ( strcmp(sFirmwareName1, ".") != 0 )
          {
             pcFw = &sFirmwareName1[0];
    
             /* Update link to the first (default) FW binary. */
             if (pcFw)
             {
                if (g_sFirmwareName1 != DSL_NULL)
                {
                   DSL_CPE_Free(g_sFirmwareName1);
                }
    
                g_sFirmwareName1 = DSL_CPE_Malloc (strlen (pcFw) + 1);
                if (g_sFirmwareName1)
                {
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
                   memset(g_sFirmwareName1, 0, strlen (pcFw) + 1);
                   cpe_control_strncpy_s(g_sFirmwareName1, strlen (pcFw) + 1, pcFw, strlen (pcFw));
    
    Kenneth Johansson's avatar
    Kenneth Johansson committed
                }
                DSL_CPE_FwFeaturesGet(g_sFirmwareName1, &g_nFwFeatures1);
             }
          }
       }
    
       /* Get second (on-chip bonding) firmware binary. */
       if (DSL_CPE_LINES_PER_DEVICE == 2 && strlen(sFirmwareName2) > 0)
       {
          pcFw2 = &sFirmwareName2[0];
    
          /* Update link to the second (on-chip bonding) FW binary. */
          if (pcFw2)
          {
             if (g_sFirmwareName2 != DSL_NULL)
             {
                DSL_CPE_Free(g_sFirmwareName2);
             }
    
             g_sFirmwareName2 = DSL_CPE_Malloc (strlen (pcFw2) + 1);
             if (g_sFirmwareName2)
             {
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
                memset(g_sFirmwareName2, 0, strlen (pcFw2) + 1);
                cpe_control_strncpy_s(g_sFirmwareName2, strlen (pcFw2) + 1, pcFw2, strlen (pcFw2));
    
    Kenneth Johansson's avatar
    Kenneth Johansson committed
             }
             DSL_CPE_FwFeaturesGet(g_sFirmwareName2, &g_nFwFeatures2);
          }
       }
    
       pCtrlCtx = DSL_CPE_GetGlobalContext();
       if(pCtrlCtx == DSL_NULL)
       {
          DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(-1));
    
          return -1;
       }
    
       DSL_CPE_Fd2DevNum(fd, &nDevice);
       pCtrlCtx->bForceFirmwareDownload[nDevice] = DSL_TRUE;
    
    #ifdef INCLUDE_FW_REQUEST_SUPPORT
       if (DSL_CPE_LINES_PER_DEVICE < 2)
       {
          ret = DSL_CPE_Ioctl (fd, DSL_FIO_AUTOBOOT_STATUS_GET, (int) &AutobootStatus);
    
          if ((ret < 0) && (AutobootStatus.accessCtl.nReturn < DSL_SUCCESS))
          {
             DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(autobootCtrl.accessCtl.nReturn));
             return 0;
          }
       }
    
       if (DSL_CPE_LINES_PER_DEVICE < 2 && ((AutobootStatus.data.nStatus == DSL_AUTOBOOT_STATUS_FW_WAIT &&
             AutobootStatus.data.nFirmwareRequestType != DSL_FW_REQUEST_NA) ||
            (AutobootStatus.data.nStatus == DSL_AUTOBOOT_STATUS_STOPPED)))
       {
          ret = DSL_CPE_DownloadFirmware(fd, nDevice, AutobootStatus.data.nFirmwareRequestType,
                                                       DSL_PORT_MODE_NA, pcFw, pcFw2);
    
          DSL_CPE_FPrintf (out, DSL_CPE_RET, DSL_CPE_RET_VAL(ret));
          if (ret < DSL_SUCCESS)
          {
             DSL_CPE_FPrintf(out, " (Have you used absolute firmware path?)" DSL_CPE_CRLF);
          }
       }
       else
       {
          /* Trigger Autoboot restart sequence. FW binary will be requested
             from the DSL CPE API driver later*/
          autobootCtrl.data.nCommand = DSL_AUTOBOOT_CTRL_RESTART_FULL;
    
          ret = DSL_CPE_Ioctl (fd, DSL_FIO_AUTOBOOT_CONTROL_SET, (int) &autobootCtrl);
    
          if ((ret < 0) && (autobootCtrl.accessCtl.nReturn < DSL_SUCCESS))
          {
             DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(autobootCtrl.accessCtl.nReturn));
          }
          else
          {
             DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(ret));
          }
       }
    #else
       ret = DSL_CPE_DownloadFirmware(fd, nDevice, DSL_FW_REQUEST_NA, pcFw, pcFw2);
    
       DSL_CPE_FPrintf (out, DSL_CPE_RET, DSL_CPE_RET_VAL(ret));
       if (ret < DSL_SUCCESS)
       {
          DSL_CPE_FPrintf(out, " (Have you used absolute firmware path?)" DSL_CPE_CRLF);
       }
    #endif /* INCLUDE_FW_REQUEST_SUPPORT*/
    
       return 0;
    }
    
    static const DSL_char_t g_sAlig[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Input Parameter" DSL_CPE_CRLF
       "%s"
       "- DSL_XTUDir_t nDirection" DSL_CPE_CRLF
       "   near end = 0" DSL_CPE_CRLF
       "   far end = 1" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
       "%s"
       "- DSL_AuxLineInventory_t nData[" _MKSTR(DSL_G993_LI_MAXLEN_AUX)"]" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_AuxLineInventoryGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_uint32_t i = 0;
       DSL_AuxLineInventory_t pData;
       int nDirection = 0;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 1, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       sscanf (pCommands, "%d", &nDirection);
    
       pData.nDirection = nDirection;
    
       memset(&pData, 0x0, sizeof(DSL_AuxLineInventory_t));
    
       ret = DSL_CPE_Ioctl (fd, DSL_FIO_AUX_LINE_INVENTORY_GET, (int) &pData);
    
       if ((ret < 0) && (pData.accessCtl.nReturn < DSL_SUCCESS))
       {
          DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(pData.accessCtl.nReturn));
       }
       else
       {
          DSL_CPE_FPrintf (out, DSL_CPE_RET"nLength=%u nData=\"" DSL_CPE_CRLF,
             DSL_CPE_RET_VAL(pData.accessCtl.nReturn),
             (unsigned int)pData.data.nLength);
    
          for (i = 0; i < pData.data.nLength; i++)
          {
             if (i%10 == 0) DSL_CPE_FPrintf ( out, DSL_CPE_CRLF);
             DSL_CPE_FPrintf ( out, "%02x ", pData.data.pData[i]);
          }
          DSL_CPE_FPrintf ( out, "\""DSL_CPE_CRLF);
       }
    
       return 0;
    }
    
    #define DSL_CPE_CLI_MAX_PROFILES_PER_BANDS   2030
    
    static const DSL_char_t g_sBpsg[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "%s"
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
       "%s"
       "- DSL_uint32_t nBandPlan" DSL_CPE_CRLF
       "- DSL_uint32_t nProfile" DSL_CPE_CRLF
       "- DSL_boolean_t bSupported" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- ... nParamNr[3] nCount[" _MKSTR(DSL_CPE_CLI_MAX_PROFILES_PER_BANDS) "]" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_BandPlanSupportGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_BandPlanSupport_t *pData = DSL_NULL;
       DSL_int_t nBandPlan = 0, nProfile = 0;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 0, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       pData = (DSL_BandPlanSupport_t*)DSL_CPE_Malloc(sizeof(DSL_BandPlanSupport_t));
       if (pData == DSL_NULL)
       {
          DSL_CPE_FPrintf(out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(DSL_ERR_MEMORY));
          return 0;
       }
    
       ret = DSL_CPE_Ioctl (fd, DSL_FIO_BAND_PLAN_SUPPORT_GET, (int) pData);
    
       if ((ret < 0) && (pData->accessCtl.nReturn < DSL_SUCCESS))
       {
          DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(pData->accessCtl.nReturn));
       }
       else
       {
          DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(pData->accessCtl.nReturn));
          DSL_CPE_FPrintf (out, "nFormat=(nBandPlan(dec),nProfile(dec),bSupported(dec)) nData=\"" DSL_CPE_CRLF);
    
          for (nBandPlan = 0; nBandPlan < DSL_BANDPLAN_LAST; nBandPlan++)
          {
             for (nProfile = 0; nProfile < DSL_PROFILE_LAST; nProfile++)
             {
                DSL_CPE_FPrintf (out, "(%02d,%02d,%d) ", nBandPlan, nProfile,
                   pData->data.bSupported[nBandPlan][nProfile]);
             }
             DSL_CPE_FPrintf (out, DSL_CPE_CRLF );
          }
          DSL_CPE_FPrintf(out, "\"" DSL_CPE_CRLF );
       }
    
       DSL_CPE_Free(pData);
    
       return 0;
    }
    
    static const DSL_char_t g_sBpstg[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "%s"
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
       "%s"
       "- DSL_uint32_t nBandPlan (deprecated)" DSL_CPE_CRLF
       "   DSL_BANDPLAN_NA = -1" DSL_CPE_CRLF
       "- DSL_uint32_t nProfile" DSL_CPE_CRLF
       "   DSL_PROFILE_8A = 0" DSL_CPE_CRLF
       "   DSL_PROFILE_8B = 1" DSL_CPE_CRLF
       "   DSL_PROFILE_8C = 2" DSL_CPE_CRLF
       "   DSL_PROFILE_8D = 3" DSL_CPE_CRLF
       "   DSL_PROFILE_12A = 4" DSL_CPE_CRLF
       "   DSL_PROFILE_12B = 5" DSL_CPE_CRLF
       "   DSL_PROFILE_17A = 6" DSL_CPE_CRLF
       "   DSL_PROFILE_30A = 7" DSL_CPE_CRLF
       "   DSL_PROFILE_35B = 8" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_BandPlanStatusGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_BandPlanStatus_t pData;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 0, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       memset(&pData, 0x0, sizeof(DSL_BandPlanStatus_t));
    
       ret = DSL_CPE_Ioctl (fd, DSL_FIO_BAND_PLAN_STATUS_GET, (int) &pData);
    
       if ((ret < 0) && (pData.accessCtl.nReturn < DSL_SUCCESS))
       {
          DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(pData.accessCtl.nReturn));
       }
       else
       {
          DSL_CPE_FPrintf (out,
             DSL_CPE_RET"nBandPlan=%d nProfile=%d" DSL_CPE_CRLF,
             DSL_CPE_RET_VAL(pData.accessCtl.nReturn),
             pData.data.nBandPlan, pData.data.nProfile);
       }
    
       return 0;
    }
    
    static const DSL_char_t g_sVig[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "%s"
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
       "%s"
       "- DSL_char_t DSL_DriverVersionApi[" _MKSTR(MAX_INFO_STRING_LEN)"]"DSL_CPE_CRLF
       "- DSL_char_t DSL_ChipSetFWVersion[" _MKSTR(MAX_INFO_STRING_LEN)"]"DSL_CPE_CRLF
       "- DSL_char_t DSL_ChipSetHWVersion[" _MKSTR(MAX_INFO_STRING_LEN)"]"DSL_CPE_CRLF
       "- DSL_char_t DSL_ChipSetType[" _MKSTR(MAX_INFO_STRING_LEN)"]"DSL_CPE_CRLF
       "- DSL_char_t DSL_DriverVersionMeiBsp[" _MKSTR(MAX_INFO_STRING_LEN)"]"DSL_CPE_CRLF
       "- DSL_HybridType_t nHybridType"DSL_CPE_CRLF
       "   unknown = -1"DSL_CPE_CRLF
       "   na = 0"DSL_CPE_CRLF
       "   pots = 1"DSL_CPE_CRLF
       "   isdn_b = 2"DSL_CPE_CRLF
       "   isdn_bj = 3"DSL_CPE_CRLF
       "   universal_vrx500 = 4"DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_VersionInformationGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_VersionInformation_t pData;
       DSL_CPE_Control_Context_t *pCtrlCtx = DSL_NULL;
       DSL_char_t pAppPatch[8];
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 0, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       memset(&pData, 0x0, sizeof(DSL_VersionInformation_t));
    
       ret = DSL_CPE_Ioctl (fd, DSL_FIO_VERSION_INFORMATION_GET, (int) &pData);
    
       if ((ret < 0) && (pData.accessCtl.nReturn < DSL_SUCCESS))
       {
          DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(ret));
       }
       else
       {
          pCtrlCtx = DSL_CPE_GetGlobalContext();
          if(pCtrlCtx == DSL_NULL)
          {
             DSL_CPE_FPrintf (out, sFailureReturn, DSL_CPE_RET_VAL(-1));
             return -1;
          }
    
          if ((pCtrlCtx->driverVer.nMajor != pCtrlCtx->applicationVer.nMajor) ||
              (pCtrlCtx->driverVer.nMinor != pCtrlCtx->applicationVer.nMinor))
          {
             pData.accessCtl.nReturn = DSL_WRN_VERSION_INCOMPATIBLE;
          }
    
          pAppPatch[0] = 0;
    
    #ifndef DISABLE_DSL_PATCH_VERSION
          if (pCtrlCtx->applicationVer.nPatch != 0)
          {
             snprintf (pAppPatch, sizeof(pAppPatch), "%spa%d", (pCtrlCtx->driverVer.nPatch == 0) ? "-" : "",
                pCtrlCtx->applicationVer.nPatch);
          }
    #endif /*#ifndef DISABLE_DSL_PATCH_VERSION*/
    
          DSL_CPE_FPrintf (out,
             DSL_CPE_RET"DSL_DriverVersionApi=%s%s DSL_ChipSetFWVersion=%s "
             "DSL_ChipSetHWVersion=%s DSL_ChipSetType=%s DSL_DriverVersionMeiBsp=%s "
             "nHybrid=%d"
             DSL_CPE_CRLF, DSL_CPE_RET_VAL(pData.accessCtl.nReturn),
             pData.data.DSL_DriverVersionApi, pAppPatch,
             pData.data.DSL_ChipSetFWVersion, pData.data.DSL_ChipSetHWVersion,
             pData.data.DSL_ChipSetType, pData.data.DSL_DriverVersionMeiBsp,
             pData.data.nHybridType);