Beispiel #1
0
/**
   Initialise the CLI DTI
*/
DSL_Error_t DSL_CPE_Dti_Stop(
                        DSL_CPE_Control_Context_t *pContext)
{
   DTI_AgentCtx_t             *pDtiAgent = DSL_NULL;

   if (DSL_CPE_GlobalDtiContext.bEnabled == DSL_TRUE)
   {
      pDtiAgent = DSL_CPE_GlobalDtiContext.pDtiAgent;
      DSL_CPE_GlobalDtiContext.pDtiAgent = DSL_NULL;

      if ( DTI_AgentStop(&pDtiAgent) != DTI_SUCCESS)
      {
         DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"ERROR - Stop DTI agent" DSL_CPE_CRLF);

         return DSL_ERROR;
      }

      if (DSL_CPE_CLI_Unregister(DSL_CPE_GlobalDtiContext.pCLIContext) == DSL_SUCCESS)
      {
         DSL_CPE_Free(DSL_CPE_GlobalDtiContext.pCLIContext);
         DSL_CPE_GlobalDtiContext.pCLIContext = DSL_NULL;
      }
   }
   else
   {
      DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"ERROR - Stop DTI agent, not running" DSL_CPE_CRLF);

      return DSL_ERROR;
   }

   return DSL_SUCCESS;
}
Beispiel #2
0
/**
   Exit the CLI DTI
*/
DTI_STATIC DSL_Error_t DSL_CPE_CLI_Dti_Exit(
                        DSL_void_t *pContext)
{
   DSL_Error_t             ret = DSL_SUCCESS;
   DSL_CPE_Dti_Context_t   *pDtiContext = (DSL_CPE_Dti_Context_t*)pContext;

   if (pDtiContext == DSL_NULL)
   {
      return DSL_ERROR;
   }

   /* unregister the exec within the DTI module */
#ifdef INCLUDE_DSL_API_CONSOLE_EXTRA
   if (pDtiContext->bEnabled == DSL_TRUE)
   {
#if defined(INCLUDE_DSL_CPE_CLI_SUPPORT)
      if (DSL_CPE_CLI_Unregister(pDtiContext->pCLIContext) == DSL_SUCCESS)
      {
         DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"oops, CLI DTI Exit - unregister failed" DSL_CPECRLF);
         DSL_CPE_Free(pDtiContext->pCLIContext);
         pDtiContext->pCLIContext = DSL_NULL;
      }
#endif /* #if defined(INCLUDE_DSL_CPE_CLI_SUPPORT) */
   }
#endif

   return ret;
}
Beispiel #3
0
/**
   Initialize the DTI
*/
DSL_Error_t DSL_CPE_Dti_Start(
                        DSL_CPE_Control_Context_t *pContext,
                        DSL_int_t      numOfPhyDevices,
                        DSL_int_t      numOfLinesPerPhyDevice,
                        DSL_uint16_t   dtiListenPort,
                        DSL_char_t     *pDtiServerIp,
                        DSL_boolean_t  bEnableCliAutoMsg,
                        DSL_boolean_t  bEnableDevAutoMsg,
                        DSL_boolean_t  bEnableSingleThreadMode)
{
   DSL_int_t                  ret = DSL_SUCCESS;
   DTI_AgentCtx_t             *pDtiAgent = DSL_NULL;
   DTI_AgentStartupSettings_t dtiStartup;

   if (DSL_CPE_GlobalDtiContext.pDtiAgent == DSL_NULL)
   {
      /* init the DTI control struct */
      memset(&DSL_CPE_GlobalDtiContext, 0, sizeof(DSL_CPE_Dti_Context_t));
      DSL_CPE_GlobalDtiContext.ifNum = -1;


      memset(&dtiStartup, 0x00, sizeof(DTI_AgentStartupSettings_t));

      /* physical device setup */
      dtiStartup.numOfDevices   = (IFX_int_t)numOfPhyDevices;
      dtiStartup.linesPerDevice = (IFX_int_t)numOfLinesPerPhyDevice;


      /* DTI IP Setup setup */
      strncpy(dtiStartup.serverIpAddr, pDtiServerIp, 16);
      dtiStartup.listenPort = (dtiListenPort == 0) ? 9000 : (IFX_uint16_t)dtiListenPort;

      /* DTI Agent configuration */
      dtiStartup.bStartupAutoCliMsgSupport = (bEnableCliAutoMsg == DSL_TRUE) ? 1 : 0;
      dtiStartup.bStartupAutoDevMsgSupport = (bEnableDevAutoMsg == DSL_TRUE) ? 1 : 0;

      dtiStartup.debugLevel = 3;

#if defined(DTI_SUPPORT_SINGLE_THREADED_MODE) && (DTI_SUPPORT_SINGLE_THREADED_MODE == 1)
      /*
         Out from the DTI Agent interface:
            This version ot the DTI Agent supports "single threaded mode"
      */
      if (bEnableSingleThreadMode == DSL_TRUE)
      {
         dtiStartup.bSingleThreadedMode = 1;
         dtiStartup.numOfUsedWorker     = 1;
      }
      else
      {
         dtiStartup.bSingleThreadedMode = 0;
         dtiStartup.numOfUsedWorker     = 4;
      }
#endif

      /*
         start the DTI Agent
      */
      if ( DTI_AgentStart(&pDtiAgent, &dtiStartup) != DTI_SUCCESS)
      {
         DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"ERROR - start DTI agent" DSL_CPE_CRLF);

         return DSL_ERROR;
      }
      DSL_CPE_GlobalDtiContext.pDtiAgent = pDtiAgent;
   }
   else
   {
      DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"WARNING - DTI agent already running" DSL_CPE_CRLF);
   }

#if defined(INCLUDE_DSL_CPE_CLI_SUPPORT)
   if (DSL_CPE_GlobalDtiContext.bEnabled != DSL_TRUE)
   {
      DSL_CPE_GlobalDtiContext.pDSLContext = pContext;

      if (dtiStartup.bStartupAutoCliMsgSupport == 1)
      {
         ret = DSL_CPE_CLI_Register(
                  &DSL_CPE_GlobalDtiContext.pCLIContext,
                  &DSL_CPE_GlobalDtiContext,
                  DSL_CPE_CLI_Dti_Exit,
                  DSL_CPE_CLI_Dti_Event);
      }
      else
      {
         ret = DSL_CPE_CLI_Register(
                  &DSL_CPE_GlobalDtiContext.pCLIContext,
                  &DSL_CPE_GlobalDtiContext,
                  DSL_CPE_CLI_Dti_Exit,
                  IFX_NULL);
      }


      /* register the exec within the DTI module */
      DSL_CPE_GlobalDtiContext.ifNum =  DTI_CLI_SendFunctionRegister(
                                            (IFX_void_t *)DSL_CPE_GlobalDtiContext.pDtiAgent,
                                            (IFX_void_t *)&DSL_CPE_GlobalDtiContext,
                                            "DSL_API",
                                            DSL_CPE_CLI_Dti_Exec,
                                            0x10000 /* size of response buffer */);
      if (DSL_CPE_GlobalDtiContext.ifNum < 0)
      {
         DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"ERROR - start DTI agent, send fct register" DSL_CPE_CRLF);

         if (DSL_CPE_CLI_Unregister(DSL_CPE_GlobalDtiContext.pCLIContext) == DSL_SUCCESS)
         {
            DSL_CPE_Free(DSL_CPE_GlobalDtiContext.pCLIContext);
            DSL_CPE_GlobalDtiContext.pCLIContext = DSL_NULL;
         }

         return DSL_ERROR;
      }
   }
   else
   {
      DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"WARNING - DTI agent already registered" DSL_CPE_CRLF);
   }
#endif /* #if defined(INCLUDE_DSL_CPE_CLI_SUPPORT)*/

   DSL_CPE_GlobalDtiContext.bEnabled = DSL_TRUE;

   return ret;
}
/* TCP CLI debug handler */
DSL_int_t DSL_CPE_TcpDebugCliHandle ( DSL_CPE_Thread_Params_t *params )
{
   DSL_int_t nSockFd, nRet;
   DSL_int_t nWidth;
   DSL_CPE_fd_set_t readFds, tempFds;
   DSL_Socket_t nSocketAccept;
   DSL_sockaddr_in_t myAddr;
   /* client address*/
   DSL_sockaddr_in_t remoteAddr;
#ifdef LINUX
   DSL_int_t nSockOpt = 1;
   DSL_TimeVal_t sendTimeout;
   DSL_SockOptLinger_t structLg;
#endif
   DSL_int_t c;
   /*number of requests*/
   DSL_int_t n = 0;
   /* stores the client information */
   DSL_CPE_TcpDebugCliClientInfo_t *clientInfo;
   DSL_int_t nClients = 0;
   DSL_CPE_Control_Context_t *pCtrlContext = (DSL_CPE_Control_Context_t*)params->nArg1;

   clientInfo = DSL_CPE_Malloc(DSL_FD_SETSIZE * sizeof(DSL_CPE_TcpDebugCliClientInfo_t));
   if (clientInfo == DSL_NULL)
   {
      return -1;
   }

   /* init variables */
   memset((char *) &readFds, 0x0, sizeof(DSL_CPE_fd_set_t));
   memset((char *) &tempFds, 0x0, sizeof(DSL_CPE_fd_set_t));

   /* Socket Address */
   memset((char *) &myAddr, '\0', sizeof(DSL_sockaddr_in_t));
   myAddr.sin_family = AF_INET;
   myAddr.sin_port = DSL_CPE_Htons(DSL_CPE_TCP_CLI_PORT); /* Listens at port 2001 */

   if (sTcpMessagesSocketAddr)
   {
      if (DSL_CPE_StringToAddress(sTcpMessagesSocketAddr, &myAddr.sin_addr) == 0)
      {
         DSL_CPE_Free(clientInfo);

         DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
            "ERROR - invalid IP address specified" DSL_CPE_CRLF));

         return -1;
      }

      DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
         "TCP CLI debug server: Address: %s" DSL_CPE_CRLF,
         DSL_CPE_AddressToString(myAddr.sin_addr)));
   }
   else
   {
      DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
         "Using multihomed host for TCP messages..." DSL_CPE_CRLF));

      myAddr.sin_addr.s_addr = DSL_CPE_Htonl(DSL_CPE_INADDR_ANY);
   }

   /* Initialise file descriptors to zero */
   DSL_CPE_FD_ZERO(&readFds);
   DSL_CPE_FD_ZERO(&tempFds);

   /* Set up socket parameters */
   if ((DSL_CPE_Socket(SOCK_STREAM, (DSL_Socket_t*)&nSockFd)) == -1)
   {
      DSL_CPE_Free(clientInfo);

      DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
         "ERROR - Socket was not created" DSL_CPE_CRLF));
      return 0;
   }

#ifdef LINUX
   /*$$ ND: I'm not sure whether all of options below are supported
        by another OS than Linux */

   /* set the socket to be reuseable */
   DSL_CPE_SockOptSet(nSockFd, SOL_SOCKET, SO_REUSEADDR, &nSockOpt,
      sizeof(nSockOpt));

   /* set up the struct timeval for the timeout If connected socket fails
      to respond to these messages, the connection is broken and processes
      writing to that socket are notified with an ENETRSET errno. This option
      takes an int value in the optval argument. This is a BOOL option */
   nSockOpt = 1;
   DSL_CPE_SockOptSet(nSockFd, SOL_SOCKET, SO_KEEPALIVE, &nSockOpt,
      sizeof(nSockOpt) );

   /* SO_DEBUG */
   /* Enables recording of debugging information */
   nSockOpt = 1;
   DSL_CPE_SockOptSet(nSockFd, SOL_SOCKET, SO_DEBUG, &nSockOpt, sizeof(nSockOpt) );

   /* SO_LINGER linger on close if data present SO_LINGER controls the action
      taken when unsent messages are queued on socket and a close(2)
      is performed */
   structLg.l_onoff=0;
   structLg.l_linger=0;
   DSL_CPE_SockOptSet(nSockFd, SOL_SOCKET, SO_LINGER, &structLg,
      sizeof(DSL_SockOptLinger_t) );

   /* SO_RCVTIME0 and SO_SNDTIME0 Specify the sending or receiving timeouts
      until reporting an error. They are fixed to a protocol specific setting
      in Linux adn cannot be read or written They can be easily emulated
      using alarm */
   sendTimeout.tv_sec=60;
   sendTimeout.tv_usec=0;
   DSL_CPE_SockOptSet(nSockFd, SOL_SOCKET, SO_SNDTIMEO, &sendTimeout,
      sizeof(DSL_TimeVal_t) );
#endif

   for (c = 0; c < DSL_FD_SETSIZE; c++)
   {
      clientInfo[c].fd = -1;
      clientInfo[c].buf = 0;
   }

   /* Set info in the Control Context*/
   pCtrlContext->pDebugCliClientInfo = clientInfo;

   if (DSL_CPE_SocketBind(nSockFd, &myAddr) == -1)
   {
      DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
         "ERROR - Could not bind to socket" DSL_CPE_CRLF));
   }
   else
   {
      if (listen(nSockFd, 1) == -1)
      {
         DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
            "ERROR - Listening Error" DSL_CPE_CRLF));
      }
      else
      {
         DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
            "TCP_IP Socket for CLI is Listening" DSL_CPE_CRLF));

         c = 0;

         DSL_CPE_FD_SET(nSockFd, &readFds);

         nWidth = nSockFd + 1;
         /* Listen to the selected port */
         while(1)
         {
            /* Update the local file descriptor by the copy in the task parameter  */
            memcpy(&tempFds, &readFds, sizeof(DSL_CPE_fd_set_t));

            /* Wait for incoming events */
            n = DSL_CPE_Select(nWidth, &tempFds, &tempFds, (DSL_uint32_t)-1);

            /* Look if messages were received */
            /* New connection */
            if (DSL_CPE_FD_ISSET(nSockFd,&tempFds))
            {
               /* Received socket stream Accept connection from socket*/
               nSocketAccept = DSL_CPE_Accept(nSockFd, &remoteAddr);

               DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
                  "Connected from %s" DSL_CPE_CRLF, DSL_CPE_AddressToString(remoteAddr.sin_addr)));

               /* store information to clientInfo table */
               for (c = 0; c < DSL_FD_SETSIZE; c++)
               {
                  if (nClients >= DSL_FD_SETSIZE)
                  {
                     DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
                        "ERROR - Too many clients" DSL_CPE_CRLF));

                     DSL_CPE_SocketClose(nSocketAccept);
                     continue;
                  }

                   if (clientInfo[c].fd < 0)
                   {
                     clientInfo[c].out = DSL_CPE_FdOpen((DSL_int_t)nSocketAccept, "w");
                     if (clientInfo[c].out != DSL_NULL)
                     {
                        if (clientInfo[c].buf != DSL_NULL)
                        {
                           DSL_CPE_Free(clientInfo[c].buf);
                        }

                        clientInfo[c].buf =
                           DSL_CPE_Malloc(DSL_CPE_TCP_CLI_COMMAND_LENGTH_MAX);

                        if (clientInfo[c].buf == DSL_NULL)
                        {
                           DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
                              "ERROR - Could not allocate buffer for CLI command" DSL_CPE_CRLF));
                        }
                        else
                        {
                          clientInfo[c].fd = (DSL_int_t)nSocketAccept;
                          clientInfo[c].client_addr = remoteAddr;
                          nClients++;
                          /* update fd to readFds */
                           if ((DSL_int_t)nSocketAccept >= nWidth)
                           {
                              nWidth = (DSL_int_t)nSocketAccept + 1;
                           }

                           DSL_CPE_FD_SET((DSL_int_t)nSocketAccept,&readFds);
                          n--;
                        }
                     }
                     else
                     {
                        DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
                           "ERROR - Could not create file structure for socket"DSL_CPE_CRLF));
                     }
                     break;
                 }
               }
            }

            /* check fd for all clients  */
            for (c = 0; c < DSL_FD_SETSIZE; c++)
            {
               if (n == 0)
               {
                  break;
               }

               if ((nSocketAccept = (DSL_Socket_t)clientInfo[c].fd) < 0)
               {
                 continue;
               }

               /* Check for receive time-out */
               if (DSL_CPE_FD_ISSET((DSL_int_t)nSocketAccept, &tempFds))
               {
                 n--;
                 nRet = DSL_CPE_TcpCliHandle((DSL_CPE_Control_Context_t*) params->nArg1,
                     &clientInfo[c], (DSL_int_t)nSocketAccept);

                  if (nRet == -ENODATA) /* read 0 bytes, client closed the connection */
                  {
                     DSL_CCA_DEBUG(DSL_CCA_DBG_WRN, (DSL_CPE_PREFIX
                        "Connection closed from %s." DSL_CPE_CRLF,
                        DSL_CPE_AddressToString(clientInfo[c].client_addr.sin_addr)));

                     if (clientInfo[c].out != DSL_NULL)
                     {
                        DSL_CPE_FClose(clientInfo[c].out);
                        clientInfo[c].out = DSL_NULL;
                        if (clientInfo[c].buf != DSL_NULL)
                        {
                           DSL_CPE_Free(clientInfo[c].buf);
                           clientInfo[c].buf = DSL_NULL;
                        }
                     }
                     else
                     {
                          DSL_CPE_SocketClose(nSocketAccept);
                     }

                     DSL_CPE_FD_CLR((DSL_int_t)nSocketAccept, &readFds);
                    clientInfo[c].fd = -1;
                    nClients--;
                  }
               }
            }
         }
      }
   }

   for (c = 0; c < DSL_FD_SETSIZE; c++)
   {
      if ((nSocketAccept = (DSL_Socket_t)clientInfo[c].fd) != -1)
      {
         DSL_CPE_SocketClose(nSocketAccept);
      }
      if (clientInfo[c].buf != DSL_NULL)
      {
         DSL_CPE_Free(clientInfo[c].buf);
      }
   }

   DSL_CPE_SocketClose(nSockFd);

   return 0;
}
/* Tcp messages debug handler */
DSL_int_t DSL_CPE_TcpDebugMessageHandle (DSL_CPE_Thread_Params_t *params )
{
   DSL_int_t sockfd, nRet;
   DSL_int_t width;
   DSL_CPE_fd_set_t readFds,tempFds;
   DSL_Socket_t socketaccept;
   DSL_sockaddr_in_t my_addr;
   /* client address*/
   DSL_sockaddr_in_t remoteaddr;
#ifdef LINUX
   DSL_int_t so_reuseaddr=1;
   DSL_int_t so_keepalive =1 ;
   DSL_int_t so_debug =1;
   DSL_TimeVal_t tv_sendtimeout;
   DSL_SockOptLinger_t struct_lg;
#endif /* LINUX*/
   DSL_int_t c;
   /*number of requests*/
   DSL_int_t n=0;
   /* stores the client information */
   DSL_CPE_TcpDebugClientInfo_t *clientInfo;
   DSL_int_t nClients=0;
   DSL_CPE_Control_Context_t *pCtrlContext = (DSL_CPE_Control_Context_t*)params->nArg1;

   /**$$ND FIXME: all linux and BSD sockets calls should be renamed to DSL_xxx() */

   /* init variables */
   memset((char *) &readFds, 0x0, sizeof(DSL_CPE_fd_set_t));
   memset((char *) &tempFds, 0x0, sizeof(DSL_CPE_fd_set_t));

   /* Socket Address */
   memset((char *) &my_addr, '\0', sizeof(DSL_sockaddr_in_t));
   my_addr.sin_family = AF_INET;
   my_addr.sin_port   = DSL_CPE_Htons(DSL_CPE_TCP_MESSAGES_PORT); /* Listens at port 2000 */

   if (sTcpMessagesSocketAddr)
   {
      if (DSL_CPE_StringToAddress(sTcpMessagesSocketAddr, &my_addr.sin_addr) == 0)
      {
         DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
            "ERROR - invalid IP address specified" DSL_CPE_CRLF));

         return -1;
      }

      DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
         "TCP messages debug server: Address: %s" DSL_CPE_CRLF,
         DSL_CPE_AddressToString(my_addr.sin_addr)));
   }
   else
   {
      DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
         "Using multihomed host for TCP messages..." DSL_CPE_CRLF));
      my_addr.sin_addr.s_addr = DSL_CPE_Htonl(DSL_CPE_INADDR_ANY);
   }

   /* Initialise file descriptor to zero */
   DSL_CPE_FD_ZERO(&readFds);
   DSL_CPE_FD_ZERO(&tempFds);

   /* Set up socket parameters */
   if ((DSL_CPE_Socket(SOCK_STREAM, (DSL_Socket_t*)&sockfd)) == -1)
   {
      DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
         "ERROR - Socket was not created" DSL_CPE_CRLF));
      return 0;
   }

#ifdef LINUX
   /*$$ ND: I'm not sure whether all of options below are supported
        by another OS than Linux */

   /* set the socket to be reuseable */
   DSL_CPE_SockOptSet(sockfd, SOL_SOCKET, SO_REUSEADDR, &so_reuseaddr,
      sizeof(so_reuseaddr));

   /* set up the struct timeval for the timeout If connected socket fails
      to respond to these messages, the connection is broken and processes
      writing to that socket are notified with an ENETRSET errno. This option
      takes an int value in the optval argument. This is a BOOL option */
   DSL_CPE_SockOptSet(sockfd, SOL_SOCKET, SO_KEEPALIVE, &so_keepalive,
      sizeof(so_keepalive) );

   /* SO_DEBUG */
   /* Enables recording of debugging information */
   DSL_CPE_SockOptSet(sockfd, SOL_SOCKET, SO_DEBUG, &so_debug, sizeof(so_debug) );

   /* SO_LINGER linger on close if data present SO_LINGER controls the action
      taken when unsent messages are queued on socket and a close(2)
      is performed */
   struct_lg.l_onoff=0;
   struct_lg.l_linger=0;
   DSL_CPE_SockOptSet(sockfd, SOL_SOCKET, SO_LINGER, &struct_lg,
      sizeof(DSL_SockOptLinger_t) );

   /* SO_RCVTIME0 and SO_SNDTIME0 Specify the sending or receiving timeouts
      until reporting an error. They are fixed to a protocol specific setting
      in Linux adn cannot be read or written They can be easily emulated
      using alarm */
   tv_sendtimeout.tv_sec=60;
   tv_sendtimeout.tv_usec=0;
   DSL_CPE_SockOptSet(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv_sendtimeout, sizeof(DSL_TimeVal_t) );
#endif /* LINUX*/
#if 0
   if (jtag_debug_enable)
   {
      if(ioctl(nLowFd, IFX_ADSL_BSP_IOC_JTAG_ENABLE)!=MEI_SUCCESS)
      {
         printf("\n IFX_ADSL_BSP_IOC_JTAG_ENABLE failed");
         close(nLowFd);
         return -1;
      }
   }
#endif

   clientInfo = DSL_CPE_Malloc(DSL_FD_SETSIZE * sizeof(DSL_CPE_TcpDebugClientInfo_t));
   if (clientInfo == DSL_NULL)
   {
      DSL_CPE_SocketClose(sockfd);
      return -1;
   }

   for (c = 0; c < DSL_FD_SETSIZE; c++)
   {
      clientInfo[c].fd = -1;
      clientInfo[c].pDevData = DSL_NULL;
   }

   /* Set info in the Control Context*/
   pCtrlContext->pDebugClientInfo = clientInfo;

   if (DSL_CPE_SocketBind(sockfd, &my_addr) == -1)
   {
      DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
         "ERROR - Could not bind to socket!" DSL_CPE_CRLF));
   }
   else
   {
      if (listen(sockfd, 1) == -1)
      {
         DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
            "ERROR - Listening Error" DSL_CPE_CRLF));
      }
      else
      {
         DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
            "TCP_IP Socket is Listening" DSL_CPE_CRLF));

         c = 0;

#if 0
         if (firmare_flag)
         {
            nRet = Download_Firmware(filename,nLowFd);
            nRet=ioctl(nLowFd, IFX_ADSL_BSP_IOC_DSLSTART, NULL);
         }

         if (ioctl(nLowFd, AUTOBOOT_CONTROL_SET , 0)<0)
         {
            printf("\n\n mei ioctl AUTOBOOT_CONTROL_SET fail.\n");
         }
#endif

         DSL_CPE_FD_SET(sockfd, &readFds);

         width = sockfd + 1;
         /* Listen to the selected port */
         while(1)
         {
            /* Update the local file descriptor by the copy in the task parameter  */
            memcpy(&tempFds,&readFds,sizeof(DSL_CPE_fd_set_t));

            /* Wait for incoming events */
            /*n=select(width, &tempFds,(fd_set *)NULL, (fd_set *)NULL, &tv);*/
            n = DSL_CPE_Select(width, &tempFds, &tempFds, (DSL_uint32_t)-1);

            /* Look if messages were received */
            /* New connection */
            if (DSL_CPE_FD_ISSET(sockfd,&tempFds))
            {
               /* Received socket stream Accept connection from socket*/
               socketaccept = DSL_CPE_Accept(sockfd, &remoteaddr);

               DSL_CCA_DEBUG(DSL_CCA_DBG_MSG, (DSL_CPE_PREFIX
                  "Connected from %s, sock = %d." DSL_CPE_CRLF,
                  DSL_CPE_AddressToString(remoteaddr.sin_addr), socketaccept));

               /* store information to clientInfo table */
               for (c = 0; c < FD_SETSIZE; c++)
               {
                  if (nClients >= FD_SETSIZE)
                  {
                     DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX
                        "ERROR - Too many clients" DSL_CPE_CRLF));

                     DSL_CPE_SocketClose(socketaccept);
                     continue;
                  }

                   if (clientInfo[c].fd < 0)
                   {
                     /* try to create FILE structure for socket */
                     clientInfo[c].fd = (DSL_int_t)socketaccept;
                     clientInfo[c].client_addr = remoteaddr;
                     nClients++;

                     /* update fd to readFds */
                     if ((DSL_int_t)socketaccept >= width)
                        width = (DSL_int_t)socketaccept + 1;
                     DSL_CPE_FD_SET((DSL_int_t)socketaccept,&readFds);
                     n--;

                     break;
                 }
               }
            }

            /* check fd for all clients  */
            for (c = 0; c < FD_SETSIZE; c++)
            {
               if (n==0)
               {
                  break;
               }

               if ((socketaccept = (DSL_Socket_t)clientInfo[c].fd) < 0)
               {
                  continue;
               }


               /* Check for receive time-out */
               if (FD_ISSET((DSL_int_t)socketaccept ,&tempFds))
               {
                 n--;
                 nRet = DSL_CPE_DEV_TcpMessageHandle(&clientInfo[c]);
                  if (nRet == -ENODATA) /* read 0 bytes, client closed the connection */
                  {
                     DSL_CCA_DEBUG(DSL_CCA_DBG_WRN, (DSL_CPE_PREFIX
                        "Connection closed from %s." DSL_CPE_CRLF,
                        DSL_CPE_AddressToString(clientInfo[c].client_addr.sin_addr)));

                    DSL_CPE_SocketClose(socketaccept);
                    DSL_CPE_FD_CLR((DSL_int_t)socketaccept,&readFds);
                    clientInfo[c].fd = -1;

                     if (clientInfo[c].pDevData)
                     {
                        DSL_CPE_DEV_DeviceDataFree(clientInfo[c].pDevData);
                        clientInfo[c].pDevData = DSL_NULL;
                     }

                     nClients--;
                  }
               }
            }
         }
      }
   }

   /* Free device data*/
   for (c = 0; c < DSL_FD_SETSIZE; c++)
   {
      if ((socketaccept = (DSL_Socket_t)clientInfo[c].fd) != -1)
      {
         DSL_CPE_SocketClose(socketaccept);
      }
      if (clientInfo[c].pDevData)
      {
         DSL_CPE_DEV_DeviceDataFree(clientInfo[c].pDevData);
      }
   }

   DSL_CPE_Free(clientInfo);

   DSL_CPE_SocketClose(sockfd);

   return 0;
}