/** Handle a incoming command form the Debug & Trace interface */ DTI_STATIC DSL_int_t DSL_CPE_CLI_Dti_Exec( DSL_void_t *pCliDtiDescriptor, const DSL_char_t *pCmdIn, DSL_char_t *pResultOut, DSL_int_t *pResultBufSize_byte, DSL_int_t *pResultCode) { DSL_int_t retVal = 0, writtenBytes = 0; DSL_CPE_Dti_Context_t *pCliDtiContext = (DSL_CPE_Dti_Context_t *)pCliDtiDescriptor; DSL_CPE_File_t *pOutStream = DSL_CPE_STDOUT; if (pResultOut && pResultBufSize_byte) { memset(pResultOut, 0, *pResultBufSize_byte); } else { DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"oops, missing DTI result buffer" DSL_CPE_CRLF); return DSL_ERROR; } if (!pCliDtiDescriptor) { DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"oops, missing CLI DTI handle" DSL_CPE_CRLF); writtenBytes = DSL_CPE_snprintf(pResultOut, *pResultBufSize_byte, "nReturn=-1 nError=\"oops, missing CLI DTI handle\n\r\""); *pResultBufSize_byte = writtenBytes; return DSL_ERROR; } if (!pCmdIn) { DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"oops, missing DTI command" DSL_CPE_CRLF); writtenBytes = DSL_CPE_snprintf(pResultOut, *pResultBufSize_byte, "nReturn=-1 nError=\"oops, missing DTI command\n\r\""); *pResultBufSize_byte = writtenBytes; return DSL_ERROR; } #if defined(IFXOS_HAVE_MEMORY_FILE) && (IFXOS_HAVE_MEMORY_FILE == 1) pOutStream = DSL_CPE_FMemOpen(pResultOut, *pResultBufSize_byte - 1, "w"); if(pOutStream == NULL) { DSL_CPE_FPrintf(DSL_CPE_STDOUT, DSL_CPE_PREFIX"oops, cannot open DTI stream" DSL_CPE_CRLF); writtenBytes = DSL_CPE_snprintf(pResultOut, *pResultBufSize_byte, "nReturn=-1 nError=\"oops, cannot open DTI stream\n\r\""); *pResultBufSize_byte = writtenBytes; return DSL_ERROR; } #endif /* execute the given DTI command. */ retVal = DSL_CPE_CLI_Dti_Command_Exec(pCliDtiContext, pCmdIn, pOutStream); #if defined(IFXOS_HAVE_MEMORY_FILE) && (IFXOS_HAVE_MEMORY_FILE == 1) DSL_CPE_FClose(pOutStream); writtenBytes = strlen(pResultOut); pResultOut[writtenBytes] = '\0'; #else writtenBytes = DSL_CPE_snprintf(pResultOut, *pResultBufSize_byte, "nReturn=%d nWarning=\"result written to stdout\n\r\"", retVal); #endif *pResultBufSize_byte = writtenBytes; return DSL_SUCCESS; }
int ifx__DslCpeCliAccess (struct soap *soap_server, char *pCommand, char **pReturn ) { char cmd[256] = ""; char *pcArg = DSL_NULL; Soap_env_t *pSoapEnv = soap_server->user; DSL_CPE_File_t *stream = DSL_NULL; struct soap_multipart *attachment; #ifdef DSL_CPE_SOAP_FW_UPDATE DSL_CPE_Firmware_t nFirmware; DSL_CPE_Firmware_t nFirmware2; memset(&nFirmware, 0, sizeof(nFirmware)); memset(&nFirmware2, 0, sizeof(nFirmware2)); #endif /* DSL_CPE_SOAP_FW_UPDATE */ if(pCommand == DSL_NULL) { sprintf(soap_result, "nReturn=-1 nError=\"oops, CLI command received via SOAP is zero\n\r\""); *pReturn = soap_result; return SOAP_OK; } /* get command name */ sscanf(pCommand, "%255s", cmd); if(strlen(cmd) < strlen(pCommand)) { pcArg = pCommand + strlen(cmd) + 1; } for (attachment = soap_server->dime.list; attachment; attachment = attachment->next) { #ifdef DSL_CPE_SOAP_FW_UPDATE if(attachment->type && (strcmp(attachment->type, "image/firmware1") == 0)) { fprintf(stderr, "DIME attachment: firmware1.bin\n\r"); nFirmware.pData = (DSL_uint8_t *)attachment->ptr; nFirmware.nSize = attachment->size; } else if(attachment->type && (strcmp(attachment->type, "image/firmware2") == 0)) { fprintf(stderr, "DIME attachment: firmware2.bin\n\r"); nFirmware2.pData = (DSL_uint8_t *)attachment->ptr; nFirmware2.nSize = attachment->size; } else { fprintf(stderr, "DSL: cannot decode DIME attachment\n\r"); fprintf(stderr, "DIME attachment:\n\r"); fprintf(stderr, "Memory=%p\n\r", attachment->ptr); fprintf(stderr, "Size=%u\n\r", (unsigned int)attachment->size); fprintf(stderr, "Type=%s\n\r", attachment->type ? attachment->type:"null"); fprintf(stderr, "ID=%s\n\r", attachment->id ? attachment->id:"null"); } #else fprintf(stderr, "Firmware download via DIME attachment not supported.\n\r"); #endif } #ifdef DSL_CPE_SOAP_FW_UPDATE if((nFirmware.pData != DSL_NULL) || (nFirmware2.pData != DSL_NULL)) { DSL_CPE_SoapFirmwareUpdate(&nFirmware, &nFirmware2); } #endif /* DSL_CPE_SOAP_FW_UPDATE */ memset(soap_result, 0, sizeof(soap_result)); stream = DSL_CPE_FMemOpen(soap_result, sizeof(soap_result)-1, "w"); if(stream != DSL_NULL) { DSL_CPE_CliDeviceCommandExecute(pSoapEnv->pContext, -1, cmd, pcArg, stream); } else { DSL_CCA_DEBUG(DSL_CCA_DBG_ERR, (DSL_CPE_PREFIX "cannot open SOAP stream" DSL_CPE_CRLF)); } DSL_CPE_FClose(stream); *pReturn = soap_result; return SOAP_OK; }