Skip to content
Snippets Groups Projects
dsl_cpe_cli_access2.c 111 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
    
      For licensing information, see the file 'LICENSE' in the root folder of
      this software module.
    
    ******************************************************************************/
    
    /** \file
       DSL CLI, access function implementation
    */
    
    #include "dsl_cpe_control.h"
    #if defined(INCLUDE_DSL_CPE_CLI_SUPPORT) && defined(INCLUDE_DSL_CPE_CLI_AUTOGEN_SUPPORT)
    
    #include "dsl_cpe_cli.h"
    #include "dsl_cpe_cli_console.h"
    #include "dsl_cpe_debug.h"
    #include "drv_dsl_cpe_api.h"
    #include "drv_dsl_cpe_api_ioctl.h"
    
    #if defined(INCLUDE_DSL_CPE_DTI_SUPPORT)
    #include "dsl_cpe_dti.h"
    #endif /* #if defined(INCLUDE_DSL_CPE_DTI_SUPPORT)*/
    
    #undef DSL_CCA_DBG_BLOCK
    #define DSL_CCA_DBG_BLOCK DSL_CCA_DBG_CLI
    
    
    /* for debugging: */
    #ifdef DSL_CLI_LOCAL
    #undef DSL_CLI_LOCAL
    #endif
    #if 1
    #define DSL_CLI_LOCAL
    #else
    #define DSL_CLI_LOCAL static
    #endif
    
    DSL_void_t DSL_CPE_CLI_AutogenCommandsRegister (DSL_void_t);
    
    DSL_void_t DSL_CPE_CLI_DeviceCommandsRegister ( DSL_void_t );
    #ifdef INCLUDE_DSL_ADSL_MIB
    DSL_void_t DSL_CPE_CLI_MibCommandsRegister ( DSL_void_t );
    #endif /* INCLUDE_DSL_ADSL_MIB*/
    
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
    const char *sFailureReturn = "nReturn=%d%s";
    #else
    const char *sFailureReturn = "nReturn=%d";
    #endif
    
    #ifndef DSL_CPE_DEBUG_DISABLE
    static const DSL_char_t g_sCcaDbgmlg[] =
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Input Parameter" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_CCA_debugModules_t nCcaDbgModule (dec)" DSL_CPE_CRLF
       "   DSL_CCA_DBG_APP = 1" DSL_CPE_CRLF
       "   DSL_CCA_DBG_OS = 2" DSL_CPE_CRLF
       "   DSL_CCA_DBG_CLI = 3" DSL_CPE_CRLF
       "   DSL_CCA_DBG_PIPE = 4" DSL_CPE_CRLF
       "   DSL_CCA_DBG_CONSOLE = 6" DSL_CPE_CRLF
       "   DSL_CCA_DBG_TDPMSG = 7" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_debugLevels_t nDbgLevel (hex)" DSL_CPE_CRLF
       "   DSL_CCA_DBG_NONE = 0" DSL_CPE_CRLF
       "   DSL_CCA_DBG_PRN = 1" DSL_CPE_CRLF
       "   DSL_CCA_DBG_ERR = 2" DSL_CPE_CRLF
       "   DSL_CCA_DBG_WRN = 40" DSL_CPE_CRLF
       "   DSL_CCA_DBG_MSG = 80" DSL_CPE_CRLF
       "   DSL_CCA_DBG_LOCAL = FF" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_CCA_DBG_ModuleLevelGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_CCA_debugLevels_t nDbgLvl = DSL_CCA_DBG_NONE;
       DSL_CCA_debugModules_t nDbgModule = DSL_CCA_DBG_NO_BLOCK;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 1, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       sscanf (pCommands, "%d", &nDbgModule);
    
       if ((nDbgModule > DSL_CCA_DBG_NO_BLOCK) && (nDbgModule < DSL_CCA_DBG_LAST_BLOCK))
       {
          nDbgLvl = DSL_CCA_g_dbgLvl[nDbgModule].nDbgLvl;
       }
       else
       {
          ret = -1;
       }
    
       DSL_CPE_FPrintf (out, DSL_CPE_RET"nDbgLevel=%x" DSL_CPE_CRLF, DSL_CPE_RET_VAL(ret), nDbgLvl);
    
       return 0;
    }
    #endif
    
    #ifndef DSL_CPE_DEBUG_DISABLE
    static const DSL_char_t g_sCcaDbgmls[] =
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Input Parameter" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_CCA_debugModules_t nCcaDbgModule (dec)" DSL_CPE_CRLF
       "   DSL_CCA_DBG_APP = 1" DSL_CPE_CRLF
       "   DSL_CCA_DBG_OS = 2" DSL_CPE_CRLF
       "   DSL_CCA_DBG_CLI = 3" DSL_CPE_CRLF
       "   DSL_CCA_DBG_PIPE = 4" DSL_CPE_CRLF
       "   DSL_CCA_DBG_CONSOLE = 6" DSL_CPE_CRLF
       "   DSL_CCA_DBG_TCPMSG = 7" DSL_CPE_CRLF
       "- DSL_CCA_debugLevels_t nDbgLevel (hex)" DSL_CPE_CRLF
       "   DSL_CCA_DBG_NONE = 0" DSL_CPE_CRLF
       "   DSL_CCA_DBG_PRN = 1" DSL_CPE_CRLF
       "   DSL_CCA_DBG_ERR = 2" DSL_CPE_CRLF
       "   DSL_CCA_DBG_WRN = 40" DSL_CPE_CRLF
       "   DSL_CCA_DBG_MSG = 80" DSL_CPE_CRLF
       "   DSL_CCA_DBG_LOCAL = FF" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       DSL_CPE_CRLF "";
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_CCA_DBG_ModuleLevelSet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_CCA_debugLevels_t nDbgLvl = DSL_CCA_DBG_NONE;
       DSL_CCA_debugModules_t nDbgModule = DSL_CCA_DBG_NO_BLOCK;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 2, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       sscanf (pCommands, "%d %x", &nDbgModule, &nDbgLvl);
    
       if ((nDbgModule > DSL_CCA_DBG_NO_BLOCK) && (nDbgModule < DSL_CCA_DBG_LAST_BLOCK))
       {
          if ((nDbgLvl == DSL_CCA_DBG_PRN) || (nDbgLvl == DSL_CCA_DBG_ERR) ||
             (nDbgLvl == DSL_CCA_DBG_WRN) || (nDbgLvl == DSL_CCA_DBG_MSG) ||
             (nDbgLvl == DSL_CCA_DBG_LOCAL))
          {
             DSL_CCA_g_dbgLvl[nDbgModule].nDbgLvl = nDbgLvl;
          }
          else
          {
             ret = -1;
          }
       }
       else
       {
          ret = -1;
       }
    
       DSL_CPE_FPrintf (out, DSL_CPE_RET"nDbgLevel=%x" DSL_CPE_CRLF, DSL_CPE_RET_VAL(ret), nDbgLvl);
    
       return 0;
    }
    #endif
    
    #ifdef INCLUDE_SCRIPT_NOTIFICATION
    static const DSL_char_t g_sNsecs[] =
    #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
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_char_t notify_script[1-256] (Attention: Use absolute firmware path only!)"
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_NotificationScriptExecuteConfigSet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_char_t sNotifyScript[256] = { 0 };
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 1, DSL_CLI_MIN) == DSL_FALSE)
       {
          return -1;
       }
    
       sscanf (pCommands, "%s", &sNotifyScript);
    
       /* Get ADSL script file */
       if ( strlen(sNotifyScript) > 0 )
       {
          if (DSL_CPE_IsFileExists(sNotifyScript))
          {
             if (g_sRcScript)
             {
                DSL_CPE_Free(g_sRcScript);
                g_sRcScript = DSL_NULL;
             }
    
             g_sRcScript = DSL_CPE_Malloc (strlen (sNotifyScript) + 1);
    
             if (g_sRcScript)
             {
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
                memset(g_sRcScript, 0, strlen (sNotifyScript) + 1);
                cpe_control_strncpy_s(g_sRcScript, strlen (sNotifyScript) + 1, sNotifyScript, strlen (sNotifyScript));
    
    Kenneth Johansson's avatar
    Kenneth Johansson committed
             }
          }
          else
          {
             ret = -1;
          }
       }
    
       DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(ret));
       if (ret < 0)
       {
          DSL_CPE_FPrintf(out, " (Have you used absolute script path?)" DSL_CPE_CRLF);
       }
    
       return 0;
    }
    #endif /* INCLUDE_SCRIPT_NOTIFICATION*/
    
    #ifdef INCLUDE_SCRIPT_NOTIFICATION
    static const DSL_char_t g_sNsecg[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "Input Parameter" DSL_CPE_CRLF
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
       DSL_CPE_CRLF
    #endif
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_char_t notify_script[256]" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_NotificationScriptExecuteConfigGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 0, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       DSL_CPE_FPrintf (out, DSL_CPE_RET, DSL_CPE_RET_VAL(ret));
    
       if(g_sRcScript != DSL_NULL)
       {
          DSL_CPE_FPrintf (out, " notify_script=%s", g_sRcScript);
       }
       else
       {
          DSL_CPE_FPrintf (out, " notify_script=n/a");
       }
    
       DSL_CPE_FPrintf (out, DSL_CPE_CRLF);
    
       return 0;
    }
    #endif /* INCLUDE_SCRIPT_NOTIFICATION*/
    
    #ifdef INCLUDE_DSL_CPE_FILESYSTEM_SUPPORT
    #ifdef INCLUDE_DSL_CPE_CMV_SCRIPTS_SUPPORT
    static const DSL_char_t g_sAsecg[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "Input Parameter" DSL_CPE_CRLF
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
       DSL_CPE_CRLF
    #endif
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_char_t adsl_script[256]" DSL_CPE_CRLF
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       "- DSL_char_t vdsl_script[256]" DSL_CPE_CRLF
    #endif
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_AutobootScriptExecuteConfigGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 0, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       DSL_CPE_FPrintf (out, DSL_CPE_RET, DSL_CPE_RET_VAL(ret));
    
       if(g_sAdslScript != DSL_NULL)
       {
          DSL_CPE_FPrintf (out, " adsl_script=%s", g_sAdslScript);
       }
       else
       {
          DSL_CPE_FPrintf (out, " adsl_script=n/a");
       }
    
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       if(g_sVdslScript != DSL_NULL)
       {
          DSL_CPE_FPrintf (out, " vdsl_script=%s", g_sVdslScript);
       }
       else
       {
          DSL_CPE_FPrintf (out, " vdsl_script=n/a");
       }
    #endif
    
       DSL_CPE_FPrintf (out, DSL_CPE_CRLF);
    
       return 0;
    }
    #endif
    #endif
    
    #ifdef INCLUDE_DSL_CPE_FILESYSTEM_SUPPORT
    #ifdef INCLUDE_DSL_CPE_CMV_SCRIPTS_SUPPORT
    static const DSL_char_t g_sAsecs[] =
    #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
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_char_t adsl_script[1-256]"
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 0)
       " (let empty to clear currently set value,"
       " adsl_script must include the full path to the script)" DSL_CPE_CRLF
    #else
       " (enter '.' to let adsl script unchanged)" DSL_CPE_CRLF
       "- DSL_char_t vdsl_script[1-256]"
       " (enter '.' to let vdsl script unchanged, or let empty to clear currently set value,"
       " let both parameters empty to clear currently set values"
       " vdsl_script must include the full path to the script)" DSL_CPE_CRLF
    #endif
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_AutobootScriptExecuteConfigSet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_char_t sAdslScript[256] = { 0 };
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       DSL_char_t sVdslScript[256] = { 0 };
    #endif
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 0, DSL_CLI_MIN) == DSL_FALSE)
       {
          return -1;
       }
    
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 2, DSL_CLI_MAX) == DSL_FALSE)
    #else
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 1, DSL_CLI_MAX) == DSL_FALSE)
    #endif
       {
          return -1;
       }
    
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       sscanf (pCommands, "%s %s", &sAdslScript, &sVdslScript);
    #else
       sscanf (pCommands, "%s", &sAdslScript);
    #endif
    
       /* Get ADSL script file */
       if ( strlen(sAdslScript) > 0 )
       {
          if ( strcmp(sAdslScript, ".") != 0 )
          {
             if (DSL_CPE_IsFileExists(sAdslScript))
             {
                if (g_sAdslScript)
                {
                   DSL_CPE_Free(g_sAdslScript);
                   g_sAdslScript = DSL_NULL;
                }
                g_sAdslScript = DSL_CPE_Malloc (strlen (sAdslScript) + 1);
                if (g_sAdslScript)
                {
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
                   memset(g_sAdslScript, 0, strlen (sAdslScript) + 1);
                   cpe_control_strncpy_s(g_sAdslScript, strlen (sAdslScript) + 1, sAdslScript, strlen (sAdslScript));
    
    Kenneth Johansson's avatar
    Kenneth Johansson committed
                }
             }
             else
             {
                ret = -1;
             }
          }
       }
       else
       {
          DSL_CPE_Free(g_sAdslScript);
          g_sAdslScript = DSL_NULL;
       }
    
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       /* Get VDSL script file */
       if (strlen(sVdslScript) > 0)
       {
          if ( strcmp(sVdslScript, ".") != 0 )
          {
             if (DSL_CPE_IsFileExists(sVdslScript))
             {
                if (g_sVdslScript)
                {
                   DSL_CPE_Free(g_sVdslScript);
                   g_sVdslScript = DSL_NULL;
                }
                g_sVdslScript = DSL_CPE_Malloc (strlen (sVdslScript) + 1);
                if (g_sVdslScript)
                {
    
    Oussama Ghorbel's avatar
    Oussama Ghorbel committed
                   memset(g_sVdslScript, 0, strlen (sVdslScript) + 1);
                   cpe_control_strncpy_s(g_sVdslScript, strlen (sVdslScript) + 1, sVdslScript, strlen (sVdslScript));
    
    Kenneth Johansson's avatar
    Kenneth Johansson committed
    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 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
                }
             }
             else
             {
                ret = -1;
             }
          }
       }
       else
       {
          DSL_CPE_Free(g_sVdslScript);
          g_sVdslScript = DSL_NULL;
       }
    #endif
    
       DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(ret));
       if (ret < 0)
       {
          DSL_CPE_FPrintf(out, " (Have you used absolute script path?)" DSL_CPE_CRLF);
       }
    
       return 0;
    }
    #endif
    #endif
    
    #ifdef INCLUDE_DSL_CPE_CMV_SCRIPTS_SUPPORT
    static const DSL_char_t g_sAcfgs[] =
    #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
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_boolean_t bWaitBeforeConfigWrite" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bWaitBeforeLinkActivation" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bWaitBeforeRestart" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bAutoContinueWaitBeforeConfigWrite (dsl_cpe_control)" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bAutoContinueWaitBeforeLinkActivation (dsl_cpe_control)" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bAutoContinueWaitBeforeRestart (dsl_cpe_control)" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       DSL_CPE_CRLF
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_AutobootConfigOptionSet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_boolean_t bAdsl = DSL_FALSE, bVdsl = DSL_FALSE;
       DSL_boolean_t bAutoContinueWaitBeforeLinkActivation = DSL_TRUE,
       bAutoContinueWaitBeforeConfigWrite = DSL_TRUE,
       bAutoContinueWaitBeforeRestart = DSL_TRUE,
       bWaitBeforeLinkActivation = DSL_FALSE,
       bWaitBeforeConfigWrite = DSL_FALSE, bWaitBeforeRestart = DSL_FALSE;
       DSL_AutobootConfig_t pData;
       DSL_CPE_Control_Context_t *pCtx = DSL_NULL;
       DSL_uint32_t nDevice = 0;
       DSL_int_t nDeviceNum = -1;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 6, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       sscanf (pCommands, "%u %u %u %u %u %u",
          &bWaitBeforeConfigWrite, &bWaitBeforeLinkActivation, &bWaitBeforeRestart,
          &bAutoContinueWaitBeforeConfigWrite, &bAutoContinueWaitBeforeLinkActivation,
          &bAutoContinueWaitBeforeRestart);
    
       if ((g_sAdslScript != DSL_NULL) && (strlen(g_sAdslScript) > 0))
       {
          bAdsl = DSL_TRUE;
       }
    
       if ((g_sVdslScript != DSL_NULL) && (strlen(g_sVdslScript) > 0))
       {
          bVdsl = DSL_TRUE;
       }
    
       if ( (bAdsl == DSL_TRUE) || (bVdsl == DSL_TRUE) )
       {
          if (!bWaitBeforeLinkActivation && !bWaitBeforeConfigWrite && !bWaitBeforeRestart)
          {
             DSL_CPE_FPrintf (out, "Warning: bWaitBeforeConfigWrite, bWaitBeforeLinkActivation and "
                "bWaitBeforeRestart were set to false "
                "but an autostart script was selected (autostart script "
                "handling only works when one these settings is set to true)" DSL_CPE_CRLF);
             DSL_CPE_FPrintf (out, "Set bWaitBeforeConfigWrite = DSL_TRUE, "
                "bWaitBeforeLinkActivation = DSL_TRUE, bWaitBeforeRestart = DSL_TRUE!" DSL_CPE_CRLF);
             bWaitBeforeConfigWrite = DSL_TRUE;
             bWaitBeforeLinkActivation = DSL_TRUE;
             bWaitBeforeRestart = DSL_TRUE;
          }
       }
    
       if ((pCtx = DSL_CPE_GetGlobalContext()) != DSL_NULL)
       {
          if (pCtx->bBackwardCompMode)
          {
             nDeviceNum = pCtx->nDevNum;
          }
          else if (DSL_CPE_DSL_ENTITIES > 1)
          {
             for (nDevice = 0; nDevice < DSL_CPE_DSL_ENTITIES; nDevice++)
             {
                if(pCtx->fd[nDevice] == fd)
                {
                   nDeviceNum = nDevice;
                   break;
                }
             }
          }
       }
       else
       {
          DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(-1));
          return 0;
       }
    
       if (nDeviceNum == -1)
       {
          DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(-1));
          return 0;
       }
    
       g_bWaitBeforeConfigWrite[nDeviceNum]    = bWaitBeforeConfigWrite;
       g_bWaitBeforeLinkActivation[nDeviceNum] = bWaitBeforeLinkActivation;
       g_bWaitBeforeRestart[nDeviceNum]        = bWaitBeforeRestart;
    
       g_bAutoContinueWaitBeforeConfigWrite[nDeviceNum]    = bAutoContinueWaitBeforeConfigWrite;
       g_bAutoContinueWaitBeforeLinkActivation[nDeviceNum] = bAutoContinueWaitBeforeLinkActivation;
       g_bAutoContinueWaitBeforeRestart[nDeviceNum]        = bAutoContinueWaitBeforeRestart;
    
       pData.data.nStateMachineOptions.bWaitBeforeConfigWrite =
          bWaitBeforeConfigWrite;
    
       pData.data.nStateMachineOptions.bWaitBeforeLinkActivation =
          bWaitBeforeLinkActivation;
    
       pData.data.nStateMachineOptions.bWaitBeforeRestart =
          bWaitBeforeRestart;
    
       ret = DSL_CPE_Ioctl (fd, DSL_FIO_AUTOBOOT_CONFIG_SET, (int) &pData);
    
       if ((ret < 0) && (pData.accessCtl.nReturn < DSL_SUCCESS))
       {
          DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(pData.accessCtl.nReturn));
       }
       else
       {
          DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(ret));
       }
    
       return 0;
    }
    #endif
    
    #ifdef INCLUDE_DSL_CONFIG_GET
    #ifdef INCLUDE_DSL_CPE_CMV_SCRIPTS_SUPPORT
    static const DSL_char_t g_sAcfgg[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "Input Parameter" DSL_CPE_CRLF
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
       DSL_CPE_CRLF
    #endif
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_boolean_t bWaitBeforeConfigWrite" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bWaitBeforeLinkActivation" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bWaitBeforeRestart" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bAutoContinueWaitBeforeConfigWrite (dsl_cpe_control)" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bAutoContinueWaitBeforeLinkActivation (dsl_cpe_control)" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       "- DSL_boolean_t bAutoContinueWaitBeforeRestart (dsl_cpe_control)" DSL_CPE_CRLF
       "   false = 0" DSL_CPE_CRLF
       "   true = 1" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_AutobootConfigOptionGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_AutobootConfig_t pData;
       DSL_CPE_Control_Context_t *pCtx = DSL_NULL;
       DSL_uint32_t nDevice = 0;
       DSL_int_t nDeviceNum = -1;
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 0, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    
       ret = DSL_CPE_Ioctl (fd, DSL_FIO_AUTOBOOT_CONFIG_GET, (int) &pData);
    
       if ((ret < 0) && (pData.accessCtl.nReturn < DSL_SUCCESS))
       {
          DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(pData.accessCtl.nReturn));
       }
       else
       {
          if ((pCtx = DSL_CPE_GetGlobalContext()) != DSL_NULL)
          {
             if (pCtx->bBackwardCompMode)
             {
                nDeviceNum = pCtx->nDevNum;
             }
             else if (DSL_CPE_DSL_ENTITIES > 1)
             {
                for (nDevice = 0; nDevice < DSL_CPE_DSL_ENTITIES; nDevice++)
                {
                   if(pCtx->fd[nDevice] == fd)
                   {
                      nDeviceNum = nDevice;
                      break;
                   }
                }
             }
          }
          else
          {
             DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(-1));
             return 0;
          }
    
          if (nDeviceNum == -1)
          {
             DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(-1));
             return 0;
          }
    
    
          g_bWaitBeforeConfigWrite[nDeviceNum] =
             pData.data.nStateMachineOptions.bWaitBeforeConfigWrite;
          g_bWaitBeforeLinkActivation[nDeviceNum] =
             pData.data.nStateMachineOptions.bWaitBeforeLinkActivation;
          g_bWaitBeforeRestart[nDeviceNum] =
             pData.data.nStateMachineOptions.bWaitBeforeRestart;
    
          DSL_CPE_FPrintf (out, DSL_CPE_RET"bWaitBeforeConfigWrite=%d "
             "bWaitBeforeLinkActivation=%d bWaitBeforeRestart=%d bAutoContinueWaitBeforeConfigWrite=%d "
             "bAutoContinueWaitBeforeLinkActivation=%d bAutoContinueWaitBeforeRestart=%d"
             DSL_CPE_CRLF, DSL_CPE_RET_VAL(pData.accessCtl.nReturn), g_bWaitBeforeConfigWrite[nDeviceNum],
             g_bWaitBeforeLinkActivation[nDeviceNum], g_bWaitBeforeRestart[nDeviceNum],
             g_bAutoContinueWaitBeforeConfigWrite[nDeviceNum], g_bAutoContinueWaitBeforeLinkActivation[nDeviceNum],
             g_bAutoContinueWaitBeforeRestart[nDeviceNum]);
       }
    
       return 0;
    }
    #endif
    #endif
    
    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
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
    #if defined(INCLUDE_DSL_CPE_API_DANUBE)
       "- DSL_char_t adsl_firmware[1-256] (Attention: Use absolute firmware path only,"
    #else
       "- DSL_char_t firmware1[1-256] (Attention: Use absolute firmware path only,"
    #endif
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       " enter '.' to let empty, to specify adsl_firmware only)" DSL_CPE_CRLF
       "- DSL_char_t adsl_firmware[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
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       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;
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       DSL_char_t *pcFw2 = DSL_NULL;
    #endif /* (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1) || !defined(INCLUDE_FW_REQUEST_SUPPORT)*/
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       DSL_char_t sFirmwareName2[256] = { 0 };
    #endif
    #ifdef INCLUDE_FW_REQUEST_SUPPORT
    #endif /* INCLUDE_FW_REQUEST_SUPPORT*/
    
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 1, DSL_CLI_MIN) == DSL_FALSE)
       {
          return -1;
       }
    
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 2, DSL_CLI_MAX) == DSL_FALSE)
       {
          return -1;
       }
    #else
       if (DSL_CPE_CLI_CheckParamNumber(pCommands, 1, DSL_CLI_EQUALS) == DSL_FALSE)
       {
          return -1;
       }
    #endif
    
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       sscanf (pCommands, "%s %s", sFirmwareName1, sFirmwareName2);
    #else
       sscanf (pCommands, "%s", sFirmwareName1);
    #endif
    
       /* Get Firmware binary 1 */
       if ((strlen(sFirmwareName1) > 0) && (strcmp(sFirmwareName1, ".") != 0))
       {
          pcFw = &sFirmwareName1[0];
       }
    
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       /* Get Firmware binary 2 */
       if (strlen(sFirmwareName2) > 0)
       {
          pcFw2 = &sFirmwareName2[0];
       }
    #endif
    
       /* Update links to the FW binaries */
       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);
       }
    
    #if (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)
       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);
       }
    #endif /* (INCLUDE_DSL_CPE_API_VDSL_SUPPORT == 1)*/
    
    #ifdef INCLUDE_FW_REQUEST_SUPPORT
    
    #if defined(INCLUDE_DSL_CPE_API_DANUBE)
       ret = DSL_CPE_DownloadFirmware(fd, DSL_FW_REQUEST_NA, pcFw, DSL_NULL);
    
       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
    
       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 (AutobootStatus.data.nStatus == DSL_AUTOBOOT_STATUS_FW_WAIT)
       {
          ret = DSL_CPE_DownloadFirmware(fd, AutobootStatus.data.nFirmwareRequestType, 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;
    
          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, autobootCtrl.accessCtl.nReturn);
          }
          else
          {
             DSL_CPE_FPrintf (out, DSL_CPE_RET DSL_CPE_CRLF, DSL_CPE_RET_VAL(ret));
          }
       }
    #endif /* defined(INCLUDE_DSL_CPE_API_DANUBE) && !defined(DSL_FIRMWARE_MEMORY_FREE_ENABLED)*/
    
    #else
       ret = DSL_CPE_DownloadFirmware(fd, 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;
    }
    
    #ifdef INCLUDE_DSL_RESOURCE_STATISTICS
    static const DSL_char_t g_sRusg[] =
    #ifndef DSL_CPE_DEBUG_DISABLE
       "Long Form: %s" DSL_CPE_CRLF
       "Short Form: %s" DSL_CPE_CRLF
       DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "Input Parameter" DSL_CPE_CRLF
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
       DSL_CPE_CRLF
    #endif
       "Output Parameter" DSL_CPE_CRLF
       "- DSL_Error_t nReturn" DSL_CPE_CRLF
    #if (DSL_CPE_MAX_DSL_ENTITIES > 1)
       "- DSL_uint32_t nDevice (optional, not used in the 'backward compatible' mode)" DSL_CPE_CRLF
    #endif
       "- DSL_uint32_t drvStaticMemUsage" DSL_CPE_CRLF
       "- DSL_uint32_t drvDynamicMemUsage" DSL_CPE_CRLF
       "- DSL_uint32_t appStaticMemUsage" DSL_CPE_CRLF
       "- DSL_uint32_t appDynamicMemUsage" DSL_CPE_CRLF
       DSL_CPE_CRLF "";
    #else
       "";
    #endif
    
    DSL_CLI_LOCAL DSL_int_t DSL_CPE_CLI_ResourceUsageStatisticsGet(
       DSL_int_t fd,
       DSL_char_t *pCommands,
       DSL_CPE_File_t *out)
    {
       DSL_int_t ret = 0;
       DSL_ResourceUsageStatistics_t pData;