diff --git a/firmware/host/Makefile b/firmware/host/Makefile new file mode 100644 index 0000000000..556fdc9f91 --- /dev/null +++ b/firmware/host/Makefile @@ -0,0 +1,44 @@ + +#Makefile for ocmw and cli + +CC=gcc +CFLAGS= -I./ocwdg -I./include -I./../ec -I./../ec/common -I./../ec/platform/oc-sdr/schema -I./../ec/common/inc/global -Wall -Werror -g -fshort-enums +LIBS = -lpthread -ledit -lm -lrt +src_ocmw = $(wildcard ocmw/*.c) $(wildcard ocwdg/*.c) $(wildcard util/*.c) $(wildcard ../ec/platform/oc-sdr/schema/*.c) +src_occli = $(wildcard occli/*.c) $(wildcard util/*.c) $(wildcard ../ec/platform/oc-sdr/schema/*.c) +src_ocware_stub = $(wildcard ocwarestub/*.c) $(wildcard ../ec/platform/oc-sdr/schema/*.c) +output_dir = bin + +# --- Build binary and executable files + +default: + @mkdir -p $(output_dir) + make all + +all: ocmw_uart ocmw_usb ocmw_eth occli ocmw_eth_stub ocware_stub + +.PHONY: occli + +ocmw_uart: $(OBJECTS) + $(CC) $(src_ocmw) -o $(output_dir)/ocmw_uart $(LIBS) $(CFLAGS) -DOCWARE_HOST + +ocmw_usb: $(OBJECTS) + $(CC) $(src_ocmw) -o $(output_dir)/ocmw_usb $(LIBS) $(CFLAGS) -DINTERFACE_USB -DOCWARE_HOST + +ocmw_eth: $(OBJECTS) + $(CC) $(src_ocmw) -o $(output_dir)/ocmw_eth $(LIBS) $(CFLAGS) -DINTERFACE_ETHERNET -DOCWARE_HOST + +ocmw_eth_stub: $(OBJECTS) + $(CC) $(src_ocmw) -o $(output_dir)/ocmw_eth_stub $(LIBS) $(CFLAGS) -DINTERFACE_STUB_EC -DOCWARE_HOST + +ocware_stub: $(OBJECTS) + $(CC) $(src_ocware_stub) -o $(output_dir)/ocware_stub $(LIBS) $(CFLAGS) -DOCWARE_HOST + +occli: $(OBJECTS) + $(CC) $(src_occli) -o $(output_dir)/occli $(LIBS) $(CFLAGS) -DOCWARE_HOST + ln -sf occli $(output_dir)/occmd + + +# --- remove binary and executable files +clean: + rm -fr $(output_dir)/ocmw_eth_stub $(output_dir)/ocmw_eth $(output_dir)/ocmw_usb $(output_dir)/ocmw_uart $(output_dir)/occli $(output_dir)/ocware_stub diff --git a/firmware/host/include/logger.h b/firmware/host/include/logger.h new file mode 100644 index 0000000000..9a1142b163 --- /dev/null +++ b/firmware/host/include/logger.h @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef __LOGGER_H__ +#define __LOGGER_H__ + +#include +#include + +#define __filename__ (basename(__FILE__)) +#ifdef CONSOLE_LOG +#define logit(facility, fmt, ...) \ +{ \ + if(facility != LOG_DEBUG) \ + printf(fmt "\n", ##__VA_ARGS__); \ + else \ + printf ("[%s:%d, %s()]:" fmt "\n", __filename__, \ + __LINE__, __func__, ##__VA_ARGS__); \ +} + +#else /* syslog */ + +#define logit(facility, fmt, ...) \ +{ \ + if(facility != LOG_DEBUG) \ + syslog(facility, fmt "\n", ##__VA_ARGS__); \ + else \ + syslog(facility, " [%s:%d, %s()]: " fmt "\n", \ + __filename__, __LINE__, __func__, ##__VA_ARGS__); \ +} + +#endif + +#define logemerg(fmt, ...) logit(LOG_EMERG, " " fmt, ##__VA_ARGS__) +#define logalert(fmt, ...) logit(LOG_ALERT, " " fmt, ##__VA_ARGS__) +#define logcrit(fmt, ...) logit(LOG_CRIT, " " fmt, ##__VA_ARGS__) +#define logerr(fmt, ...) logit(LOG_ERR, " " fmt, ##__VA_ARGS__) +#define logwarn(fmt, ...) logit(LOG_WARNING, " " fmt, ##__VA_ARGS__) +#define lognotice(fmt, ...) logit(LOG_NOTICE, " " fmt, ##__VA_ARGS__) +#define loginfo(fmt, ...) logit(LOG_INFO, " " fmt, ##__VA_ARGS__) +#define logdebug(fmt, ...) logit(LOG_DEBUG, fmt, ##__VA_ARGS__) + +/* + * @param ident an input value (by pointer) + * + */ +void initlog(const char* ident); +/* + * deinitialize the logging routine + * + */ +void deinitlog(void); + +#endif /* __LOGGER_H__ */ diff --git a/firmware/host/include/occli_common.h b/firmware/host/include/occli_common.h new file mode 100644 index 0000000000..b6527d5526 --- /dev/null +++ b/firmware/host/include/occli_common.h @@ -0,0 +1,190 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCCLI_COMM_H_ +#define _OCCLI_COMM_H_ + +/* OC Inlucdes */ +#include +#include +#include + +#define HIT_FILE_BUFF_SIZE 50 +#define OCCLI_STRING_SIZE 128 +#define RES_STR_BUFF_SIZE 10000 +#define OCMP_MAX_SIZE 10 +#define OCCLI_CHAR_ARRAY_SIZE 30 +#define OCMW_MAX_SUBSYSTEM 11 +/* This timeout must be more than OCMW timeout */ +#define OCCLI_TIMEOUT_PERIOD 12 +#define FAILED -1 +#define SUCCESS 0 +#define OCCLI_SNPRINTF_MAX_LEN 200 +#define OCCLI_HELP_MAX_SIZE 400 + +typedef struct { + char option; + int sizeNum; + int totalStr; +}OCCLI_ARRAY_PARAM; + +typedef struct { + char subsystem[OCCLI_CHAR_ARRAY_SIZE]; + char component[OCCLI_CHAR_ARRAY_SIZE]; + char subcomponent[OCCLI_CHAR_ARRAY_SIZE]; + char msgtype[OCCLI_CHAR_ARRAY_SIZE]; + char parameter[OCCLI_CHAR_ARRAY_SIZE]; +}strMsgFrame; + +typedef struct { + int8_t subsystem; + int8_t component; + int8_t msgtype; + int16_t parameter; +}sMsgParam; + +typedef struct{ + char *subsystem; + char *component; + char *msgtype; + char *subcomponent; + char *parameter; +} OCCLI_STRING_MSG; + + +typedef struct { + int32_t totalNum; + struct name { + int32_t number; + char name[OCCLI_CHAR_ARRAY_SIZE]; + } Info[OCCLI_CHAR_ARRAY_SIZE]; +}subSystemInfo; + +//Help Menu structure +typedef struct { + char subSystem[OCMW_MAX_SUBSYSTEM_SIZE]; + char component[OCMW_HELP_FRAME_SIZE]; + char subComponent[OCMW_HELP_FRAME_SIZE]; + char msgType[OCMW_MAX_MSGTYPE_SIZE]; + char actionType[OCMW_MAX_ACTION_SIZE]; + char arguments[OCMW_HELP_FRAME_SIZE]; + char parameter[OCMW_HELP_FRAME_SIZE]; +}helpMenu; + +typedef struct { + char subsystem[OCCLI_CHAR_ARRAY_SIZE]; + char component[OCCLI_CHAR_ARRAY_SIZE]; + char subComponent[OCCLI_CHAR_ARRAY_SIZE]; +}commandFrame; +/* + + * Initialize the ocmw communication + */ +int32_t occli_init_comm(void); +/* + * Deinitialize the ocmw communication + */ +int8_t occli_deinit_comm(void); +/* + * @param cmd an input string (by pointer) + * @param cmdlen an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t occli_send_cmd_to_ocmw(const char *cmd, int32_t cmdlen); +/* + * @param resp an output value (by pointer) + * @param resplen an output value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t occli_recv_cmd_resp_from_ocmw(char *resp, int32_t resplen); +/* + * @param resp an output value (by pointer) + * @param resplen an output value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t occli_recv_alertmsg_from_ocmw(char *resp, int32_t resplen); +/* + * @param root an input value (by pointer) + * @param msgFrame an input value (by pointer) + * @param ecSendBuf an input value (by pointer) + * @param actiontype an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_parse_msgframe(const Component *root, strMsgFrame *msgFrame, + uint8_t actiontype,ocmwSchemaSendBuf *ecSendBuf); +/* + * @param root an output value (by pointer) + * @param dMsgFrameParam an output value (by pointer) + * @param ecReceivedMsg an output value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +void ocmw_deserialization_msgframe(const Component *root, + sMsgParam *dMsgFrameParam, + OCMPMessageFrame *ecReceivedMsg); +/* + * @param compBase an output value (by pointer) + * @param msgFrame an output value (by pointer) + * @param ecSendBuf an output value (by pointer) + * @param actiontype an output value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_parse_command_msgframe(const Component *compBase, + strMsgFrame *msgFrame, uint8_t actiontype, + ocmwSchemaSendBuf *ecSendBuf); +/* + * @param compBase an output value (by pointer) + * @param msgFrame an output value (by pointer) + * @param ecSendBuf an output value (by pointer) + * @param actiontype an output value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_parse_post_msgframe(const Component *compBase, + strMsgFrame *msgFrame, uint8_t actiontype, + ocmwSchemaSendBuf *ecSendBuf); +/* + * @param root an output value (by pointer) + * @param systemInfo an output value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_frame_subsystem_from_schema(const Component *root, + subSystemInfo *systemInfo); + +/* + * @param root an output value (by pointer) + * @param systemInfo an output value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_frame_postTable_from_schema(const Component *root); + +/* + * @param pointer to global memory + * + * @return NONE + */ +extern inline void ocmw_free_global_pointer(void **ptr); +/* + * @param root an output value (by pointer) + * @param systemInfo an output value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int8_t occli_printHelpMenu(const Component *root,char *cmd); + +/*Display CLI window*/ +void occli_print_opencelluar(); + +#endif /* _OCCLI_COMM_H_ */ diff --git a/firmware/host/include/ocmw_core.h b/firmware/host/include/ocmw_core.h new file mode 100644 index 0000000000..e752fc559a --- /dev/null +++ b/firmware/host/include/ocmw_core.h @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCMW_CORE_H_ +#define _OCMW_CORE_H_ + +/* OC includes */ +#include + +sem_t semecMsgParser; +sem_t semCliReturn; +sem_t semCommandPost; + +/* This timeout must be less than CLI timeout */ +#define OCMW_SEM_WAIT_TIME 10 +#define OCMW_BUSY_WAIT_INDEX 0 +#define OCMW_TIMED_WAIT_INDEX 1 +#define PARAM_STR_MAX_BUFF_SIZE 100 + +int32_t ocmw_init(); +/* + * @param actionType an input enum value (by value) + * @param msgType an input enum value (by value) + * @param paramStr an input string (by pointer) + * @param interface an input enum value (by value) + * @param paramVal an input value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_msg_packetize_and_send(char * argv[], uint8_t actionType, + uint8_t msgType, const int8_t * paramStr, uint8_t interface, + void* paramVal); +/* + * Message parser module + * + */ +void ocmw_ec_msgparser(void); +/* + * Thread to parse the data coming from EC to AP through uart + * @param pthreadData an input value (by pointer) + */ +void * ocmw_thread_uartmsgparser(void *pthreadData); + +/* + * Thread to parse the data coming from EC to AP through ethernet + * @param pthreadData an input value (by pointer) + */ +void * ocmw_thread_ethmsgparser(void *pthreadData); +/* + * @param ecMsgFrame an input structure (by value) + * @param interface an input enum value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_send_msg(OCMPMessageFrame ecMsgFrame, uint8_t interface); +/* + * @param semId an input value (by pointer) + * @param semWaitType an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_sem_wait(sem_t *semId, int32_t semWaitType); +#endif /* _OCMW_CORE_H_ */ diff --git a/firmware/host/include/ocmw_eth_comm.h b/firmware/host/include/ocmw_eth_comm.h new file mode 100644 index 0000000000..815b2e9692 --- /dev/null +++ b/firmware/host/include/ocmw_eth_comm.h @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCCLI_IPC_COMM_H_ +#define _OCCLI_IPC_COMM_H_ + +/* stdlib includes */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define OCMW_EC_DEV 1 +#define OCMW_EC_STUB_DEV 2 + +/* + * Initialize the ocmw ethernet communication + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_init_eth_comm(int32_t sentDev); +/* + * Deinitialize the ocmw ethernet communication + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_deinit_eth_comm(int32_t sentDev); +/* + * @param cmd an input string (by pointer) + * @param cmdlen an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_send_eth_msgto_ec(const int8_t *cmd, int32_t cmdlen,int32_t sentDev); +/* + * @param resp an input value (by pointer) + * @param resplen an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_recv_eth_msgfrom_ec(int8_t *resp, int32_t resplen, int32_t sentDev); + +#endif /* _OCCLI_IPC_COMM_H_ */ diff --git a/firmware/host/include/ocmw_helper.h b/firmware/host/include/ocmw_helper.h new file mode 100644 index 0000000000..f9aad134ce --- /dev/null +++ b/firmware/host/include/ocmw_helper.h @@ -0,0 +1,183 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCMW_HELPER_H_ +#define _OCMW_HELPER_H_ + +/* stdlib includes */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* OC includes */ +#include +#include + +#define Buf_PARAM_STRUCT_MAX_SIZE 16 +#define MAX_PARM_COUNT (OCMP_MSG_SIZE - (sizeof(OCMPMessage)\ + - sizeof(void *) + sizeof (OCMPHeader))) + +#define DEBUG_SUBSYSTEM_NBR 11 +#define DEBUG_I2C 3 +#define DEBUG_MDIO 8 + +#define PARAM_STR_BUFF_SIZE 100 +#define PARAM_TYPE_BUFF_SIZE 32 + +#define OCMW_MAX_SUBSYSTEM_SIZE 16 +#define OCMW_MAX_ACTION_SIZE 16 +#define OCMW_MAX_MSGTYPE_SIZE 16 +#define OCMW_COMMAND_BUFF_SIZE 20 +#define OCMW_POST_DESC_SIZE 24 +#define OCMW_HELP_FRAME_SIZE 40 +#define OCMW_POST_DEVICE_SIZE 40 +#define EEPROM_STATUS_MAX_SIZE 21 +#define EEPROM_SDR_STATUS_SIZE 19 +#define EEPROM_CONFIG_MAX_SIZE 14 +#define EEPROM_CONFIG_SIZE 18 +#define OCMW_MAX_POST_CODE_SIZE 100 +#define TEMP_STR_BUFF_SIZE 100 + + +typedef enum { + VOID = 0, + CHAR = 1, + UCHAR = 1, + SHORT = 2, + USHORT = 2, + INT = 4, + UINT = 4, + FLOAT = 4 +} DATA_TYPE; + +typedef enum { + FAILED = -1, + SUCCESS, + INVALID_POINTER, +} ocmw_db_ret; + +typedef struct { + int32_t paramindex; + int32_t paramval; +} bufParam; + +typedef struct { + int8_t msgType; + int8_t componentId; + int8_t subsystem; + int8_t actionType; + int16_t paramInfo; + int32_t numOfele; + int8_t pbuf[MAX_PARM_COUNT]; + int32_t paramSizebuf[MAX_PARM_COUNT]; +} ocmwSendRecvBuf; + +typedef struct { + int8_t subsystem; + int8_t componentId; + int8_t msgType; + int8_t actionType; + int16_t paramId; + int8_t paramPos; + int8_t paramSize; + char commandType[OCMW_COMMAND_BUFF_SIZE]; +} ocmwSchemaSendBuf; + +typedef struct __attribute__((packed, aligned(1))){ + uint8_t devsn; /* device serial Number */ + uint8_t subsystem; + char subsysName[OCMW_MAX_SUBSYSTEM_SIZE]; /* Subsystem Name */ + char deviceName[OCMW_POST_DEVICE_SIZE]; /* Device Name */ + uint8_t status; /* device status */ +}ocwarePostResultData; + +typedef struct { + unsigned int count; /* Device Status count */ + ocwarePostResultData results[OCMW_MAX_POST_CODE_SIZE]; /* Post result structure */ +} ocwarePostResults; + +typedef struct { + uint8_t msgtype; /* Post Message tyep */ + uint8_t replycode; /* Reply type */ + char desc[OCMW_POST_DESC_SIZE]; /* Device description */ +} ocwarePostReplyCode; + +/* + * @param sem an input value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_sem_wait_nointr(sem_t *sem); +/* + * @param sem an input value (by pointer) + * @param timeout an input value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_sem_timedwait_nointr(sem_t *sem, const struct timespec *timeout); +/* + * @param paramindex an input value (by value) + * @param paramSizebuf an input value (by pointer) + * @param dataSize an output value (by pointer) + * @param pos an output value (by pointer) + * + */ +void ocmw_dataparsing_from_db(int32_t paramIndex, int32_t *paramSizebuf, + int32_t *dataSize, int32_t *pos); +/* + * @param input an input buffer (by pointer) + * @param bufParamStruct an output buffer (by pointer) + * + */ +void ocmw_dataparsing_from_ec(ocmwSendRecvBuf *input, + bufParam * bufParamStruct); +/* + * @param uartInputBuf an input buffer (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_fill_inputstruct(ocmwSendRecvBuf *uartInputBuf); +/* + * @param ecInputData an input data (by value) + * + * @return true if function succeeds, false otherwise + */ +int8_t ocmw_parse_eepromdata_from_ec (ocmwSendRecvBuf ecInputData); +/* + * @param ecInputData an input data (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_parse_obc_from_ec(ocmwSendRecvBuf ecInputData); +/* + * @param ecInputData an input data (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_parse_testingmodule_from_ec(ocmwSendRecvBuf ecInputData); +/* + * @param msgaction an input value (by value) + * @param msgtype an input value (by value) + * @param paramstr an input string (by pointer) + * @param paramvalue an input value (by pointer) + * + */ +//int ocmw_msgproc_send_msg(int8_t msgaction, int8_t msgtype, + // const int8_t* paramstr, void* paramvalue); + +#endif /* _OCMW_HELPER_H_ */ diff --git a/firmware/host/include/ocmw_msgproc.h b/firmware/host/include/ocmw_msgproc.h new file mode 100755 index 0000000000..0bda2bb72d --- /dev/null +++ b/firmware/host/include/ocmw_msgproc.h @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCMW_MSGPROC_H_ +#define _OCMW_MSGPROC_H_ + +#include "ocmp_frame.h" + +int ocmw_msgproc_send_msg(char * argv[], uint8_t action, int8_t msgtype, + const int8_t* paramstr, void* paramvalue); + +#endif /* _OCMW_MSGPROC_H_ */ diff --git a/firmware/host/include/ocmw_occli_comm.h b/firmware/host/include/ocmw_occli_comm.h new file mode 100644 index 0000000000..5d5d2f0a21 --- /dev/null +++ b/firmware/host/include/ocmw_occli_comm.h @@ -0,0 +1,128 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCMW_IPC_COMM_H_ +#define _OCMW_IPC_COMM_H_ + +#include + +#define PARAMSTR_NUMBER_LEN 12 +#define TESTMOD_MAX_LEN 16 +#define RES_STR_BUFF_SIZE 10000 +#define TEMP_STR_BUFF_SIZE 100 +#define ALERT_STR_BUFF_SIZE 128 +#define CMD_STR_BUFF_SIZE 100 +#define OCMW_MAX_IMEI_SIZE 15 +#define OCMW_MAX_MSG_SIZE 20 + +typedef struct { + int8_t pin; + int8_t value; +}debugGPIOData; + +typedef struct { + uint16_t regAddress; + uint16_t regValue; +}debugMDIOData; + +typedef struct __attribute__((packed, aligned(1))){ + uint8_t slaveAddress; + uint8_t numOfBytes; + uint8_t regAddress; + uint16_t regValue; +}debugI2CData; + +typedef enum { + SET_STR, + GET_STR, + RESET_STR, + ENABLE_STR, + DISABLE_STR, + ACTIVE_STR, + ECHO_STR, + DISCONNECT_STR, + CONNECT_STR, + SEND_STR, + DIAL_STR, + ANSWER_STR, + HANGUP_STR, + ELOOPBK_STR, + DLOOPBK_STR, + EPKTGEN_STR, + DPKTGEN_STR, + MAX_STR +} ocmw_token_t; + +typedef enum { + HCI_STR, + DEBUG_STR, + RESULT_STR, + ENABLE_SET_STR, + GETSETMAX +} ocmw_setGet; + +/* + * Initialize the ocmw cli communication + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_init_occli_comm(void); + +/* + * Deinitialize the ocmw cli communication + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_deinit_occli_comm(void); +/* + * @param cmd an input string (by pointer) + * @param cmdlen an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_recv_clicmd_from_occli(char* cmdstr, int32_t cmdlen); +/* + * @param resp an input value (by pointer) + * @param resplen an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_send_clicmd_resp_to_occli(const char* resp, int32_t resplen); +/* + * @param cmdstr an input value (by pointer) + * @param response an output value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int ocmw_clicmd_handler(const char *cmdstr, char *response); +/* + * Initialize the ocmw alert communication + * + * @return true if function succeeds, false otherwise + */ +int32_t init_occli_alert_comm(); +/* + * Deinitialize the ocmw alert communication + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_deinit_occli_alert_comm(void); +/* + * @param buf an input value (by pointer) + * @param buflen an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_send_alert_to_occli(const char* buf, int32_t buflen); + +char ocmw_retrieve_post_results_count(ocwarePostResults *psData); + +char ocmw_retrieve_post_results(ocwarePostResults *psData); + +char ocmw_retrieve_reply_code_desc(ocwarePostReplyCode *replyCode); +#endif /* _OCMW_IPC_COMM_H_ */ diff --git a/firmware/host/include/ocmw_schema.h b/firmware/host/include/ocmw_schema.h new file mode 100644 index 0000000000..e9fe807a48 --- /dev/null +++ b/firmware/host/include/ocmw_schema.h @@ -0,0 +1,52 @@ +/* OC Includes */ +#include + +#ifndef _OCMW_SCHEMA_H_ +#define _OCMW_SCHEMA_H_ + +#define OCMW_VALUE_TYPE_UINT8 1 +#define OCMW_VALUE_TYPE_INT8 2 +#define OCMW_VALUE_TYPE_UINT16 3 +#define OCMW_VALUE_TYPE_INT16 6 +#define OCMW_VALUE_TYPE_UINT32 11 +#define OCMW_VALUE_TYPE_ENUM 9 +#define OCMW_VALUE_TYPE_MFG 10 +#define OCMW_VALUE_TYPE_MODEL 4 +#define OCMW_VALUE_TYPE_GETMODEL 5 +#define OCMW_VALUE_TYPE_STRUCT 7 +#define OCMW_VALUE_TYPE_NWOP_STRUCT 12 +#define IRIDIUM_LASTERR_ERROR_CODE_OFFSET 2 +#define TWO_G_SIM_NET_OPTR_STATUS_OFFSET 2 +#define BUF_SIZE 50 +#define ENUM_BUF_SIZE 30 +#define OCMW_VALUE_TYPE_COMPLEX 3 + +static const char *DATA_TYPE_MAP[] = { + [TYPE_NULL] = "NULL", + [TYPE_INT8] = "int8", + [TYPE_UINT8] = "uint8", + [TYPE_INT16] = "int16", + [TYPE_UINT16] = "uint16", + [TYPE_INT32] = "int32", + [TYPE_UINT32] = "uint32", + [TYPE_INT64] = "int64", + [TYPE_UINT64] = "uint64", + [TYPE_STR] = "string", + [TYPE_BOOL] = "bool", + [TYPE_ENUM] = "enum", +}; + +typedef enum ErrorSource { + ERR_RC_INTERNAL = 0, + ERR_SRC_CMS = 1, + ERR_SRC_CME = 2 +}Source; + +typedef enum OperatorStat { + TWOG_SIM_STAT_UNKNOWN = 0x00, + TWOG_SIM_STAT_AVAILABLE = 0x01, + TWOG_SIM_STAT_CURRENT = 0x02, + TWOG_SIM_STAT_FORBIDDEN = 0x03, +}eOperatorStat; +#endif /* _OCMW_SCHEMA_H_ */ + diff --git a/firmware/host/include/ocmw_socket_comm.h b/firmware/host/include/ocmw_socket_comm.h new file mode 100644 index 0000000000..9d9ae003dc --- /dev/null +++ b/firmware/host/include/ocmw_socket_comm.h @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCMW_SOCK_COMM_H_ +#define _OCMW_SOCK_COMM_H_ + +#define OCMW_SOCK_SERVER_IP ("127.0.0.1") +#define OCMW_SOCK_SERVER_PORT (5000) +#define OCMW_SOCK_SERVER_ALERT_PORT (6000) + +#define OCMW_SOCK_SERVER_CONN_COUNT (1) +#define OCMW_SOCK_SERVER_ALERT_CONN_COUNT (2) + +#define OCMW_SOCK_DOMAIN (AF_INET) +#define OCMW_SOCK_TYPE (SOCK_DGRAM) +#define OCMW_SOCK_PROTOCOL (IPPROTO_UDP) + +#define OCMW_SOCK_ALERT_SERVER_IP ("127.0.0.1") +#define OCMW_SOCK_ALERT_SERVER_PORT (6000) +#define OCMW_SOCK_ALERT_DOMAIN (AF_INET) +#define OCMW_SOCK_ALERT_TYPE (SOCK_DGRAM) +#define OCMW_SOCK_ALERT_PROTOCOL (IPPROTO_UDP) + +#define OCMW_ETH_SOCK_SERVER_IP ("192.168.1.2") +#define OCMW_ETH_SOCK_SERVER_PORT (1000) +#define OCMW_ETH_SOCK_DOMAIN (AF_INET) +#define OCMW_ETH_SOCK_TYPE (SOCK_STREAM) +#define OCMW_ETH_SOCK_PROTOCOL (IPPROTO_TCP) +#define OCMW_SOCKET_ERROR_SIZE 256 + + +#define OCMW_SOCK_STUB_SERVER_IP ("127.0.0.1") +#define OCMW_SOCK_STUB_SERVER_PORT (2000) +#define OCMW_SOCK_STUB_DOMAIN (AF_INET) +#define OCMW_SOCK_STUB_TYPE (SOCK_DGRAM) +#define OCMW_SOCK_STUB_PROTOCOL (IPPROTO_UDP) +#endif /* _OCMW_SOCK_COMM_H_ */ diff --git a/firmware/host/include/ocmw_uart_comm.h b/firmware/host/include/ocmw_uart_comm.h new file mode 100644 index 0000000000..135c9156d9 --- /dev/null +++ b/firmware/host/include/ocmw_uart_comm.h @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCMW_UART_COMM_H_ +#define _OCMW_UART_COMM_H_ + +#ifdef INTERFACE_USB +#define ECTTY "sudo find /dev/ -iname \"ttyACM*\" | tr -cd [:digit:]" +#else +#define ECTTY "/dev/ttyS4" +#endif +#define OCMP_MSG_SIZE (64) + +/* + * @param msgstr an input value (by pointer) + * @param msgsize an input value (by value) + * + * @return the function handler + */ +typedef void + (*handle_msg_from_ec_t)(const unsigned char* msgstr, int32_t msgsize); +/* + * @param msgstr an input value (by pointer) + * @param msgsize an input value (by value) + * + */ +void ocmw_ec_uart_msg_hndlr(const unsigned char* msgstr, int32_t msgsize); +/* + * Initialize the ocmw ec communication + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_init_ec_comm(handle_msg_from_ec_t msghndlr); +/* + * Deinitialize the ocmw ec communication + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_deinit_ec_comm(void); +/* + * @param msgstr an input value (by pointer) + * @param size an input value (by value) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_send_uart_msg_to_ec(const uint8_t* msgstr, int32_t size); +/* + * @param pathName an input value (by pointer) + * + * @return true if function succeeds, false otherwise + */ +int32_t ocmw_find_ttyacm_port(char *pathName); + +#endif /* _OCMW_UART_COMM_H_ */ diff --git a/firmware/host/include/ocware_stub_eth_comm.h b/firmware/host/include/ocware_stub_eth_comm.h new file mode 100755 index 0000000000..9b80152d5a --- /dev/null +++ b/firmware/host/include/ocware_stub_eth_comm.h @@ -0,0 +1,16 @@ +#ifndef _STUB_ETH_COMM_H_ +#define _STUB_ETH_COMM_H_ + +#include +#include +#include +#include + +#define OCMW_STUB_ETH_SOCK_DOMAIN (AF_INET) +#define OCMW_STUB_ETH_SOCK_TYPE (SOCK_DGRAM) +#define OCMW_STUB_ETH_SOCK_PROTOCOL (IPPROTO_UDP) +#define OCMW_STUB_ETH_SOCK_SERVER_PORT (2000) +#define OCMW_STUB_ETH_SOCK_SERVER_IP ("127.0.0.1") +#define OCWARE_STUB_ERR_STR_LEN (80) + +#endif /* _STUB_ETH_COMM_H_ */ diff --git a/firmware/host/include/ocware_stub_main_module.h b/firmware/host/include/ocware_stub_main_module.h new file mode 100755 index 0000000000..64e6254828 --- /dev/null +++ b/firmware/host/include/ocware_stub_main_module.h @@ -0,0 +1,266 @@ +#ifndef _OCMW_STUB_H_ +#define _OCMW_STUB_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define OC_EC_MSG_SIZE (64) +#define MAX_PAYLOAD_COUNT (OC_EC_MSG_SIZE - sizeof (OCMPHeader)) + +/* Max parameters to be stored in database */ +#define MAX_NUMBER_PARAM 400 +#define MAX_POST_DEVICE 400 +#define MAX_I2C_COMP_NBR 1 +#define MAX_GPIO_COMP_NBR 1 +#define MAX_MDIO_COMP_NBR 1 + +/* Default values in the database */ +#define DEFAULT_INT8 0x11 +#define DEFAULT_INT16 0x2222 +#define DEFAULT_INT32 0x33333333 +#define DEFAULT_INT64 0x4444444444444444 +#define DEFAULT_ENUM 0x05 +#define DEFAULT_STRING "stub" + +/* default values in the debug subsystem */ +#define I2C_SLAVE_ADDRESS 1 +#define I2C_NUM_BYTES 1 +#define I2C_REG_ADDRESS 1 +#define I2C_REG_VALUE 1 +#define GPIO_PIN_NBR 1 +#define GPIO_VALUE 1 + +/* size of strings and enum dataypes in schema */ +#define SIZE_OF_TYPE_REGISTRATION 1 +#define SIZE_OF_NWOP_STRUCT 3 +#define SIZE_OF_LAST_ERROR 3 +#define SIZE_OF_TYPE_MFG 10 +#define SIZE_OF_TYPE_GETMODEL 5 +#define SIZE_OF_TYPE_MODEL 4 +#define SIZE_OF_NWOP_STRUCT 3 +#define SIZE_OF_LAST_ERROR 3 +#define SIZE_OF_TYPE_OCSERIAL_INFO 18 +#define SIZE_OF_TYPE_GBCBOARD_INFO 18 +#define SIZE_OF_TYPE_MACADDR 13 + +/* Masking related defines */ +#define MASK_MSB 0xFF00 +#define MASK_LSB 0xFF +#define SHIFT_NIBBLE 8 + +typedef struct { + uint8_t subsystemId; + uint8_t componentId; + uint8_t msgtype; + uint16_t paramId; + uint8_t paramSize; + uint8_t paramPos; + uint8_t datatype; + void *data; +}OCWareStubDatabase; + +typedef struct{ + uint8_t SubsystemId; + uint8_t DeviceNumber; + ePostCode Status; +}OCWareStubPostData; + +typedef enum { + OCSTUB_VALUE_ZERO, + OCSTUB_VALUE_TYPE_MFG, + OCSTUB_VALUE_TYPE_GETMODEL, + OCSTUB_VALUE_TYPE_MODEL, + OCSTUB_VALUE_TYPE_REGISTRATION, + OCSTUB_VALUE_TYPE_NWOP_STRUCT, + OCSTUB_VALUE_TYPE_LAST_ERROR, + OCSTUB_VALUE_TYPE_OCSERIAL_INFO, + OCSTUB_VALUE_TYPE_GBCBOARD_INFO, + OCSTUB_VALUE_TYPE_I2C_DEBUG, + OCSTUB_VALUE_TYPE_GPIO_DEBUG, + OCSTUB_VALUE_TYPE_MDIO_DEBUG, +}OCWareStubsizeflag; + +typedef struct { + uint8_t slaveAddress; + uint8_t numOfBytes; + uint8_t regAddress; + uint16_t regValue; +}OCWareDebugI2Cinfo; + +typedef struct { + uint16_t regAddress; + uint16_t regValue; +}OCWareDebugMDIOinfo; + +typedef struct { + uint8_t pin_nbr; + uint8_t value; +}OCWareDebugGPIOinfo; + +typedef enum ocware_ret{ + STUB_FAILED = -1, + STUB_SUCCESS = 0 +}ocware_stub_ret; + + +extern int8_t debugGetCommand; +extern int8_t debugSetCommand; +extern int8_t PostResult; +extern int8_t PostEnable; + +/****************************************************************************** + * Function Name : ocware_stub_parse_post_get_message + * Description : Parse post messages from MW + * + * @param buffer - output pointer to the message from MW + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_parse_post_get_message(char *buffer); + +/****************************************************************************** + * Function Name : ocware_stub_parse_command_message + * Description : Parse command messages from MW + * + * @param buffer - output pointer to the message from MW + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_parse_command_message(char *buffer); + +/****************************************************************************** + * Function Name : ocware_stub_get_set_params + * Description : Function to check if GET/SET operation is to be performed + * + * @param msgFrameData - Pointer to the message frame field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_set_params(OCMPMessage *msgFrameData); +/****************************************************************************** + * Function Name : ocware_stub_init_database + * Description : Parse the schema and add entries in the DB + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_init_database(void); +/****************************************************************************** + * Function Name : ocware_stub_send_msgframe_middleware + * Description : send message to the MW + * + * @param bufferlen - length of the message (by value) + * @param buffer - pointer to the message to be sent to MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_send_msgframe_middleware(char **buffer, int32_t bufferlen); +/****************************************************************************** + * Function Name : ocware_stub_init_ethernet_comm + * Description : initialise the socket IPC + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_init_ethernet_comm(void); +/****************************************************************************** + * Function Name : ocware_stub_deinit_ethernet_comm + * Description : close the IPC socket + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_deinit_ethernet_comm(); +/****************************************************************************** + * Function Name : ocware_stub_recv_msgfrom_middleware + * Description : Receive message from MW + * + * @param bufferlen - length of the message (by value) + * @param buffer - pointer to the location where the message from MW is to be + * stored for further processing (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_recv_msgfrom_middleware(char **buffer, int32_t bufferlen); +/****************************************************************************** + * Function Name : ocware_stub_get_database + * Description : Function to retrieve data from the DB + * + * @param msgFrameData - Pointer to the message frame field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_database(OCMPMessage *msgFrameData); +/****************************************************************************** + * Function Name : ocware_stub_set_database + * Description : Function to modify data in the DB + * + * @param msgFrameData - Pointer to the message frame field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_set_database(OCMPMessage *msgFrameData); +/****************************************************************************** + * Function Name : ocware_stub_get_post_result_paramvalue_from_table + * Description : Fill payload with the post information + * + * @param message - output pointer to the message from MW + * @param payload - output pointer to the payload field of the message from MW + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_post_result_paramvalue_from_table( + OCMPMessage *msgFrameData, + int8_t *payload); +/****************************************************************************** + * Function Name : ocware_stub_parse_debug_actiontype + * Description : Convert debug actiontype into the SET/GET + * + * @param msgFrameData - output pointer to the OCMPheader field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_parse_debug_actiontype(OCMPMessage *msgFrameData); +/****************************************************************************** + * Function Name : ocware_stub_get_post_database + * Description : extract device number and status from the post database + * depending on the subsytem id + * + * @param msgFrameData - output pointer to the OCMPheader field of the message + * from MW (by reference) + * @param payload - output pointer to the payload field of the message from MW + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_post_database(OCMPMessage *msgFrameData, + char *payload); + +#endif /* __OCMW_STUB_H__ */ diff --git a/firmware/host/include/ocwdg_daemon.h b/firmware/host/include/ocwdg_daemon.h new file mode 100644 index 0000000000..f096fcffb2 --- /dev/null +++ b/firmware/host/include/ocwdg_daemon.h @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _OCWGD_DAEMON_H_ +#define _OCWGD_DAEMON_H_ + +/* OC includes */ +#include +#include +#include + +sem_t semEcWdgMsg; +/* + * Initialize the watchdog daemon + * + * @return true if function succeeds, false otherwise + */ +int32_t ocwdg_init(void); +/* + * @param pthreadData an input value (by pointer) + * + */ +void * ocwdg_thread_comm_with_ec(void *pthreadData); + +#endif /* _OCWGD_DAEMON_H_ */ diff --git a/firmware/host/include/postframe.h b/firmware/host/include/postframe.h new file mode 100644 index 0000000000..c193a798ba --- /dev/null +++ b/firmware/host/include/postframe.h @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _POST_H_ +#define _POST_H_ + +/* stdlib includes */ +#include +#include +#include +#include + +#define POST_MAIN_PAYLOAD_SIZE 3 +#define POST_MAIN_PAYLOAD_SUBSYSTEM_OFFSET 0 +#define POST_MAIN_PAYLOAD_DEVSN_OFFSET 1 +#define POST_MAIN_PAYLOAD_STATUS_OFFSET 2 + +#endif /* _POST_H_ */ diff --git a/firmware/host/include/util.h b/firmware/host/include/util.h new file mode 100644 index 0000000000..ccca883213 --- /dev/null +++ b/firmware/host/include/util.h @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#ifndef _UTIL_H_ +#define _UTIL_H_ + +/* + * @param buf an input value (by pointer) + * @param buflen an input value (by value) + * + */ +void hexdisp(const unsigned char* buf, int buflen); + +#endif /* _UTIL_H_ */ diff --git a/firmware/host/occli/occli_helpMenu.c b/firmware/host/occli/occli_helpMenu.c new file mode 100644 index 0000000000..3e797670a7 --- /dev/null +++ b/firmware/host/occli/occli_helpMenu.c @@ -0,0 +1,460 @@ +#include +#include +#include +#include + +/************************************************************************** + * Function Name : occli_print_opencelluar + * Description : This Function print Opencelluar at prompt + * Input(s) : + * Output(s) : + ***************************************************************************/ +void occli_print_opencelluar() +{ + printf("\nHELP Usage:\n\t\"subsystem --help\"" + " OR \"subsystem.component --help\""); + printf("\nEXIT:\n\t\"quit\""); + + printf("\nDisplay:\n\t\"Press Double TAB\""); + printf("\nClear Screen:\n\t\"Press CTRL + L \"\n\n"); + return; +} + +/************************************************************************** + * Function Name : occli_fill_data_from_param + * Description : This Function fill array data based on msgType + * Input(s) : param, helpMsgType, index + * Output(s) : index, helpMenuArray + ***************************************************************************/ +int8_t occli_fill_data_from_param(const Parameter *param, + helpMenu *helpMenuArray[], int32_t *index, char *helpMsgType) +{ + int32_t helpIndex = *index; + + if ((helpMenuArray == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + if (param && param->name) { + strncpy(helpMenuArray[helpIndex]->msgType, + helpMsgType,strlen(helpMsgType)); + if (strcmp(helpMsgType, "config") == 0) { + strncpy(helpMenuArray[helpIndex]->actionType, + "get/set", strlen("get/set")); + } else { + strncpy(helpMenuArray[helpIndex]->actionType, "get", strlen("get")); + } + do { + strncpy(helpMenuArray[helpIndex]->parameter, + param->name, strlen(param->name)); + param += 1; + helpIndex++; + } while (param && param->name); + *index = helpIndex; + } + return SUCCESS; +} + +/************************************************************************** + * Function Name : occli_fill_data_from_command + * Description : This Function fill array data for command + * Input(s) : command, index + * Output(s) : index, helpMenuArray + ***************************************************************************/ +int8_t occli_fill_data_from_command(const Command *command, + helpMenu *helpMenuArray[], int32_t *index, + char *subSysComp) +{ + int32_t helpIndex = *index; + + if ((helpMenuArray == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + if (command && command->name) { + strncpy(helpMenuArray[helpIndex]->msgType, + "command", strlen("command")); + while (command && command->name) { + strncpy(helpMenuArray[helpIndex]->actionType, + command->name, strlen(command->name)); + + if (strncmp(subSysComp, "debug", strlen("debug")) == 0) { + if (strstr(subSysComp, "I2C")) { + if (strcmp(command->name, "get") == 0) { + strcpy(helpMenuArray[helpIndex++]->arguments, + "Slave Address(Decimal)"); + strcpy(helpMenuArray[helpIndex++]->arguments, + "Number of Bytes(1/2)"); + strcpy(helpMenuArray[helpIndex++]->arguments, + "Register Address(Decimal)"); + } else { + strcpy(helpMenuArray[helpIndex++]->arguments, + "Slave Address(Decimal)"); + strcpy(helpMenuArray[helpIndex++]->arguments, + "Number of Bytes(1/2)"); + strcpy(helpMenuArray[helpIndex++]->arguments, + "Register Address(Decimal)"); + strcpy(helpMenuArray[helpIndex]->arguments, + "Register Data(Decimal)"); + } + } else { + if (strcmp(command->name, "get") == 0) { + strcpy(helpMenuArray[helpIndex++]->arguments, + "Pin Number"); + } else { + strcpy(helpMenuArray[helpIndex++]->arguments, + "Pin Number"); + strcpy(helpMenuArray[helpIndex]->arguments, + "Value(0/1)"); + } + } + } else if ((strncmp(subSysComp, "hci", strlen("hci")) == 0) && + (strcmp(command->name, "set") == 0)) { + strcpy(helpMenuArray[helpIndex++]->arguments, "Off/Red/Green"); + } + if (strcmp(command->name, "send") == 0) { + strcpy(helpMenuArray[helpIndex++]->arguments, "MSISDN Number"); + strcpy(helpMenuArray[helpIndex]->arguments, "Message"); + } else if (strcmp(command->name, "dial") == 0) { + strcpy(helpMenuArray[helpIndex]->arguments, "MSISDN Number"); + } + command += 1; + helpIndex++; + } + *index = helpIndex; + } + + return SUCCESS; +} + +/************************************************************************** + * Function Name : occli_fill_data_from_post + * Description : This Function fill array data for command + * Input(s) : post, index + * Output(s) : index, helpMenuArray + ***************************************************************************/ +int8_t occli_fill_data_from_post(const Post *post, + helpMenu *helpMenuArray[], int32_t *index, + char *subSysComp) +{ + int32_t helpIndex = *index; + + if ((helpMenuArray == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + if (post && post->name) { + strncpy(helpMenuArray[helpIndex]->msgType, + "post", strlen("post")); + while (post && post->name) { + strncpy(helpMenuArray[helpIndex]->actionType, + post->name, strlen(post->name)); + post += 1; + helpIndex++; + } + *index = helpIndex; + } + + return SUCCESS; +} + +/************************************************************************** + * Function Name : occli_fill_data_from_driver + * Description : This Function will fill array data from driver + * Input(s) : devDriver + * Output(s) : helpMenuArray, index + ***************************************************************************/ +int8_t occli_fill_data_from_driver(const Driver *devDriver, + helpMenu *helpMenuArray[], int32_t *index, char *subSysComp) +{ + const Parameter *param = NULL; + const Command *command = NULL; + const Post *post = NULL; + int8_t ret = FAILED; + + if ((helpMenuArray == NULL) || (devDriver == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + param = devDriver->config; + ret = occli_fill_data_from_param(param, helpMenuArray, index, "config"); + + param = devDriver->status; + ret = occli_fill_data_from_param(param, helpMenuArray, index, "status"); + + command = devDriver->commands; + ret = occli_fill_data_from_command(command, helpMenuArray, + index, subSysComp); + post = devDriver->post; + ret = occli_fill_data_from_post (post, helpMenuArray, + index, subSysComp); + return ret; +} + +/************************************************************************** + * Function Name : occli_printHelpMenu_on_console + * Description : This Function will print CLI help Menu + * Input(s) : helpMenuArray, index, subSystem + * Output(s) : NA + ***************************************************************************/ +void occli_printHelpMenu_on_console(helpMenu *helpMenuArray[], + int32_t index, char *subSystem) +{ + int32_t printIndex = 0; + + if ((strcmp(subSystem, "testmodule") == 0) || + (strcmp(subSystem, "hci") == 0)) { + /*Printing for testmodule and hci subSystem */ + printf("\nExample :\n"); + if (strcmp(subSystem, "testmodule") == 0) { + printf("testmodule.2gsim send 9789799425 hi\n"); + printf("testmodule.2gsim dial 9789799425\n"); + printf("testmodule.2gsim connect_nw\n\n"); + } else { + printf("hci.led set 1\n\n"); + } + + printf("----------------------------------------------------------" + "-------------------------------------------\n"); + printf("%-12s%-12s%-15s%-10s%-15s%-20s%-15s\n", + "Subsystem", "Component", "SubComponent", "MsgType", + "ActionType", "Parameter", "Arguments"); + printf("----------------------------------------------------------" + "-------------------------------------------\n"); + for(printIndex = 0; printIndex < index; printIndex++) { + printf("%-12s%-12s%-15s%-10s%-15s%-20s%-15s\n", + helpMenuArray[printIndex]->subSystem, + helpMenuArray[printIndex]->component, + helpMenuArray[printIndex]->subComponent, + helpMenuArray[printIndex]->msgType, + helpMenuArray[printIndex]->actionType, + helpMenuArray[printIndex]->parameter, + helpMenuArray[printIndex]->arguments); + } + printf("----------------------------------------------------------" + "-------------------------------------------\n"); + } else if (strcmp(subSystem, "debug") == 0) { + /*Printing for debug subSystem */ + printf("\nGet Example :\n"); + printf("debug.I2C.bus0 get 104 2 58\n"); + printf("debug.gbc.ioexpanderx70 get 1\n\n"); + printf("Set Example :\n"); + printf("debug.I2C.bus0 set 104 2 58 1\n"); + printf("debug.gbc.ioexpanderx70 set 1 0\n"); + printf("\n-------------------------------------------------------" + "----------------------------------------" + "---------\n"); + printf("%-15s%-15s%-15s%-15s%-15s%-20s\n", + "Subsystem", "Component", "SubComponent", "MsgType", + "ActionType", "Arguments"); + printf("-------------------------------------------------------" + "----------------------------------------" + "---------\n"); + for(printIndex = 0; printIndex < index; printIndex++) { + printf("%-15s%-15s%-15s%-15s%-15s%-20s\n", + helpMenuArray[printIndex]->subSystem, + helpMenuArray[printIndex]->component, + helpMenuArray[printIndex]->subComponent, + helpMenuArray[printIndex]->msgType, + helpMenuArray[printIndex]->actionType, + helpMenuArray[printIndex]->arguments); + } + printf("-------------------------------------------------------" + "----------------------------------------" + "---------\n"); + } else { + /*Printing for all othere subSystem */ + /* Dispalay of parameter default value and unit in help menu + * will be take care with common schema factory config + */ + printf("\n------------------------------------------------------------" + "----------------------------------\n"); + printf("%-12s%-17s%-18s%-12s%-12s%-23s\n", + "Subsystem", "Component", "SubComponent", "MsgType", + "ActionType", "Parameter"); + printf("\n------------------------------------------------------------" + "----------------------------------\n"); + for(printIndex = 0; printIndex < index; printIndex++) { + printf("%-12s%-17s%-18s%-12s%-12s%-23s\n", + helpMenuArray[printIndex]->subSystem, + helpMenuArray[printIndex]->component, + helpMenuArray[printIndex]->subComponent, + helpMenuArray[printIndex]->msgType, + helpMenuArray[printIndex]->actionType, + helpMenuArray[printIndex]->parameter); + } + printf("\n------------------------------------------------------------" + "----------------------------------\n"); + } +} + +/************************************************************************** + * Function Name : occli_free_helpMenupointer + * Description : This is an inline function to free memory + * Input(s) : helpMenuArray + * Output(s) : helpMenuArray + ***************************************************************************/ +inline void occli_free_helpMenupointer(helpMenu *helpMenuArray[]) +{ + int32_t mallocIndex = 0; + + for (mallocIndex = 0; mallocIndex < OCCLI_HELP_MAX_SIZE; mallocIndex++) { + if(helpMenuArray[mallocIndex]) + free(helpMenuArray[mallocIndex]); + } + + return; +} + +/************************************************************************** + * Function Name : occli_printHelpMenu + * Description : This Function will print CLI help Menu + * Input(s) : root, cmd + * Output(s) : NA + ***************************************************************************/ +int8_t occli_printHelpMenu(const Component *root, char *cmd) +{ + int32_t index = 0; + int32_t mallocIndex = 0; + const Component *subSystem = root; + const Component *component = NULL; + const Component *subComponent = NULL; + const Driver *devDriver = NULL; + const Command *command = NULL; + char *token = NULL; + char *cliStr = NULL; + char *cmdBkp = NULL; + char componentStr[OCCLI_CHAR_ARRAY_SIZE] = {0}; + char subSys[OCCLI_CHAR_ARRAY_SIZE] = {0}; + char subSysComp[OCCLI_CHAR_ARRAY_SIZE] = {0}; + int8_t ret = FAILED; + int8_t count = 1; + int8_t subCount = 0; + int8_t compCount = 0; + helpMenu *helpMenuArray[OCCLI_HELP_MAX_SIZE]; + + if ((subSystem == NULL) || (cmd == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + cmdBkp = (char *)malloc (sizeof(cmd)); + if (cmdBkp == NULL) { + logerr("Invalid Memory \n"); + return FAILED; + } + strcpy(cmdBkp,cmd); + + /* Tokenizing string for subsystem and component */ + cliStr = strtok(cmd, " "); + if ((cliStr == NULL) || (strstr(cliStr, "help"))) { + printf("%s : Error : Incorrect request\n", cmdBkp); + printf ("Usage : subsystem --help or subsystem.component --help\n"); + free(cmdBkp); + return FAILED; + } else { + token = strtok(cliStr, " ."); + strcpy(subSys, token); + while (token) { + token = strtok(NULL, " ."); + if (token == NULL) + break; + count++; + if (count > 2) { + printf("%s : Error : Incorrect request\n", cmdBkp); + printf ("Usage : subsystem --help" + " OR subsystem.component --help\n"); + free(cmdBkp); + return FAILED; + } + strcpy(componentStr, token); + } + } + for (mallocIndex = 0; mallocIndex < OCCLI_HELP_MAX_SIZE; mallocIndex++) { + helpMenuArray[mallocIndex] = (helpMenu *)malloc(sizeof(helpMenu)); + if (helpMenuArray[mallocIndex] == NULL) { + logerr("Invalid Memory \n"); + free(cmdBkp); + return FAILED; + } else { + memset(helpMenuArray[mallocIndex], '\0', sizeof(helpMenu)); + } + } + /* Parsing schema */ + while (subSystem && subSystem->name) { + if (strcmp(subSys, subSystem->name) == 0) { + subCount++; + strncpy((helpMenuArray[index++]->subSystem), + subSystem->name, strlen(subSystem->name)); + component = subSystem->components; + while (component && component->name) { + if ((count == 2)) { + if (strcmp(component->name, componentStr)) { + component += 1; + continue; + } else { + compCount++; + } + } + strncpy((helpMenuArray[index]->component), + component->name, strlen(component->name)); + sprintf(subSysComp, "%s.%s", subSystem->name, component->name); + command = component->commands; + ret = occli_fill_data_from_command(command, + helpMenuArray, &index, subSysComp); + devDriver = component->driver; + if (devDriver != NULL) { + ret = occli_fill_data_from_driver(devDriver, + helpMenuArray, &index, subSysComp); + if (ret == FAILED) { + logerr("\noccli_fill_data_from_driver Error"); + occli_free_helpMenupointer(helpMenuArray); + return ret; + } + } + index++; + subComponent = component->components; + while (subComponent && subComponent->name) { + strncpy((helpMenuArray[index]->subComponent), + subComponent->name, strlen(subComponent->name)); + command = subComponent->commands; + ret = occli_fill_data_from_command(command, + helpMenuArray, &index, subSysComp); + devDriver = subComponent->driver; + if (devDriver != NULL) { + ret = occli_fill_data_from_driver(devDriver, + helpMenuArray, &index, subSysComp); + if (ret == FAILED) { + logerr("\noccli_fill_data_from_driver Error"); + occli_free_helpMenupointer(helpMenuArray); + return ret; + } + } + index++; + subComponent += 1; + } + component += 1; + } + if ((count == 2) && (compCount == 0)) { + printf("%s : Error : Invalid Component\n", cmdBkp); + occli_free_helpMenupointer(helpMenuArray); + free(cmdBkp); + return FAILED; + } + } + subSystem += 1; + } + if (subCount == 0) { + printf("%s : Error : Invalid Subsystem\n", cmdBkp); + occli_free_helpMenupointer(helpMenuArray); + free(cmdBkp); + return FAILED; + } + occli_printHelpMenu_on_console(helpMenuArray, index, subSys); + occli_free_helpMenupointer(helpMenuArray); + free(cmdBkp); + return SUCCESS; +} diff --git a/firmware/host/occli/occli_main.c b/firmware/host/occli/occli_main.c new file mode 100644 index 0000000000..91b79087a9 --- /dev/null +++ b/firmware/host/occli/occli_main.c @@ -0,0 +1,860 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* stdlib includes */ +#include +#include +#include +#include +#include +#include +#include +#include + +/* sudo apt-get install libedit-dev : Install editline */ +#include + +/* OC includes */ +#include + +#define HISTORY ".occli_history" /* Saved under ${HOME} direcotory */ + +#define SWAP(s, e) do { \ + int32_t t; t = s; s = e; e = t; \ + } while (0) + +/* MAX_CLIENTRY represents the maximum entries which autofill can take */ +#define OCCLI_MAX_CLISTRING 1000 +#define OCCLI_MAX_SUBSTRING 75 +#define OCCLI_STRING_MAX_LEN 100 +#define OCCLI_CALC_SCHEMA_SIZE 1 +#define OCCLI_PARSE_SCHEMA 2 +#define MAX_ETHERNET_PORT 4 +#define OPENCELLULAR "opencellular# " + +extern char *rl_line_buffer; +static char *s_allParams[OCCLI_MAX_CLISTRING]; +static char *s_subSetParams[OCCLI_MAX_SUBSTRING]; +static char *s_strCli = NULL; +extern const Component sys_schema[]; + +/************************************************************************** + * Function Name : occli_trim_extra_spaces + * Description : This Function used to remove extra space inbetween + * words and trailing spaces from the string + * Input(s) : string + * Output(s) : string + ***************************************************************************/ +int8_t occli_trim_extra_spaces(char *string) +{ + int8_t length = 0; + char *end = NULL; + + if (string == NULL) { + logerr("Invalid memory location \n"); + return FAILED; + } + + /* Logic to remove trailing spaces */ + length = strlen(string); + end = string + length - 1; + + while(end >= string && isblank(*end)) { + end--; + } + + *(end + 1) = '\0'; + return SUCCESS; +} +/************************************************************************** + * Function Name : occli_copy_text + * Description : This Function Return a copy of the string entered + by the user in cli + * Input(s) : + * Output(s) : s_strCli + ***************************************************************************/ +static int8_t occli_copy_text () +{ + int8_t ret = FAILED; + int16_t length; + + if (isblank(rl_line_buffer[0])) { + printf("\nBlank Space is not allowed as the first character\n"); + printf("Please press ctrl+L to clear screen\n"); + return ret; + } + + length = rl_point; + s_strCli = (char*)realloc(s_strCli, length + 1); + + if (s_strCli == NULL) { + printf("\n ERROR: realloc"); + } else { + ret = SUCCESS; + strncpy (s_strCli, rl_line_buffer, length); + s_strCli[length] = '\0'; + } + + if (ret == SUCCESS) { + ret = occli_trim_extra_spaces(s_strCli); + } + + return ret; +} +/************************************************************************** + * Function Name : occli_init_subSetParams + * Description : This Function is used to allocate memory for + * subSetParams + * Input(s) : text + * Output(s) : + ***************************************************************************/ +static int8_t occli_init_subSetParams(const char *text) +{ + char *paramStr = NULL; + int32_t len = 0; + int16_t listIdx = 0; + int16_t subsetIdx = 0; + + if (text == NULL) { + logerr("Invalid memory location \n"); + return FAILED; + } + + if (s_subSetParams != NULL) { + for (listIdx = 0; (s_subSetParams[listIdx] != NULL && + listIdx < OCCLI_MAX_SUBSTRING) ; listIdx++) { + free(s_subSetParams[listIdx]); + s_subSetParams[listIdx] = NULL; + } + } + + len = strlen(text); + listIdx = 0; + while ((paramStr = s_allParams[listIdx])) { + if (strncmp(text, paramStr, len) == 0) { + subsetIdx++; + if(subsetIdx >= OCCLI_MAX_SUBSTRING) { + break; + } + } + listIdx++; + } + + for (listIdx= 0; listIdx < subsetIdx; listIdx++) { + s_subSetParams[listIdx] = (char *)calloc(1, OCCLI_STRING_MAX_LEN); + if ((s_subSetParams[listIdx]) == NULL) { + logerr("calloc error"); + return -ENOMEM; + } + } + + return SUCCESS; +} +/************************************************************************** + * Function Name : occli_all_param_generator + * Description : This Function used to generate the all param + * list + * Input(s) : text, state + * Output(s) : + ***************************************************************************/ +static char* occli_all_param_generator(const char* text, int32_t state) +{ + char *paramstr = NULL; + char *token = NULL; + char subStr[OCCLI_STRING_MAX_LEN] = {0}; + char tempStr[OCCLI_STRING_MAX_LEN] = {0}; + static int32_t s_listidx = 0; + static int32_t s_subSetIdx = 0; + static int32_t s_len = 0; + int8_t index = 0 ; + bool isEntryFound = false; + + if (text == NULL) { + logerr("Invalid memory location \n"); + rl_attempted_completion_over = 1; + return NULL; + } + + if (state == 0) { + s_listidx = 0; + s_subSetIdx = 0; + s_len = strlen(text); + if (occli_init_subSetParams(text) != SUCCESS) { + rl_attempted_completion_over = 1; + return NULL; + } + } + + while ((paramstr = s_allParams[s_listidx]) != NULL) { + isEntryFound = false; + s_listidx++; + if (strncmp(s_strCli, paramstr, s_len) == 0) { + strcpy(subStr, paramstr); + token = strtok(subStr + s_len, "."); + + memset(tempStr, 0, OCCLI_STRING_MAX_LEN); + rl_completion_append_character = '\0'; + if (token == NULL) { + /* + * case where the user has entered the complete string, + * autofill is not needed in this case , append a space + */ + sprintf(tempStr, "%s ", text); + } else { + /* Autofill will be needed in all cases here */ + if (strncmp(text, "", 1) == 0) { + /* case where the user hasn't entered any string */ + sprintf(tempStr, "%s", token); + } else if(strncmp(paramstr + s_len, "." , 1) == 0) { + /* + * case where the user has entered complete string + * for either subsystem/component (ie) "system" + */ + sprintf(tempStr, "%s.%s", text,token); + } else { + /* + * case where the user has entered subset of the string + * for example "sys" + */ + sprintf(tempStr, "%s%s", text,token); + } + } + /* + * The for loop below is to ensure that duplicate entries arent + * displayed in the cli + */ + for (index = 0; index < s_subSetIdx; index++) { + if (strcmp(s_subSetParams[index], tempStr) == 0) { + isEntryFound = true; + break; + } + } + if(isEntryFound != true) { + strcpy(s_subSetParams[s_subSetIdx], tempStr); + s_subSetIdx++; + return strdup(s_subSetParams[s_subSetIdx - 1]); + } + } + } + return NULL; +} +/************************************************************************** + * Function Name : occli_custom_completion + * Description : This Function used to handle the TAB operation + * Input(s) : text, start, end + * Output(s) : + ***************************************************************************/ +static char** occli_custom_completion(const char* text, int32_t start, + int32_t end) +{ + char** matches = NULL; + int8_t ret = FAILED; + + if (text == NULL) { + logerr("Invalid memory location \n"); + rl_attempted_completion_over = 1; + return NULL; + } + + ret = occli_copy_text(); + if (ret != SUCCESS) { + rl_attempted_completion_over = 1; + return NULL; + } + + if (start == 0) { + matches = rl_completion_matches(text, occli_all_param_generator); + } else { + rl_attempted_completion_over = 1; + } + + return matches; +} + +/************************************************************************** + * Function Name : occli_strjoin + * Description : This Function used to join the string + * Input(s) : srcstr, delimstr + * Output(s) : deststrPtr + ***************************************************************************/ +static int8_t occli_strjoin(char **deststrPtr, const char *srcstr, + const char *delimstr) +{ + char *tmp; + const int32_t alloclen = OCCLI_STRING_SIZE; + size_t destSize, deststrLen, srcstrLen, delimstrLen; + + if (deststrPtr == NULL || srcstr == NULL || delimstr == NULL) { + logerr("NULL pointer error"); + return -EFAULT; + } + + if (*deststrPtr == NULL) { + *deststrPtr = calloc(alloclen, sizeof(char)); + if (*deststrPtr == NULL) { + logerr("calloc error"); + return -ENOMEM; + } + deststrLen = strlen(*deststrPtr); + } else { + delimstrLen = strlen(delimstr); + srcstrLen = strlen(srcstr); + deststrLen = strlen(*deststrPtr); + destSize = ((deststrLen / alloclen) + 1) * alloclen; + + if ((srcstrLen + delimstrLen + 1) > (destSize - deststrLen)) { + /* allocate more memory to concatenate the srcstr */ + tmp = *deststrPtr; + *deststrPtr = realloc(*deststrPtr, destSize + alloclen); + if (*deststrPtr == NULL) { + logerr("realloc error"); + free(tmp); + return -ENOMEM; + } + } + } + + /* strcat the delimiting string to deststr, only when the deststr is not + an empty string */ + if (deststrLen > 0) { + strcat(*deststrPtr, delimstr); + } + /* strcat the new string */ + strcat(*deststrPtr, srcstr); + + logdebug("*deststrPtr='%s'", *deststrPtr); + + return SUCCESS; +} + +/************************************************************************** + * Function Name : occli_alertthread_messenger_to_ocmw + * Description : This Function is used to handle the alert message + * Input(s) : pThreadData + * Output(s) : + ***************************************************************************/ +void * occli_alertthread_messenger_to_ocmw(void *pThreadData) +{ + char response[RES_STR_BUFF_SIZE] = {0}; + int32_t ret = 0; + + /* Receive the CLI command execution response string from OCMW over UDP + * socket */ + + while (1) { + memset(response, 0, sizeof(response)); + ret = occli_recv_alertmsg_from_ocmw(response, sizeof(response)); + if (ret < 0) { + printf("occli_recv_alertmsg_from_ocmw failed: error value : %d\n", ret); + } else { + printf("%s\n", response); + } + } +} +/************************************************************************** + * Function Name : occli_parse_cliString + * Description : This Function is used to check the validity of the + * cli string + * Input(s) : cliString + * Output(s) : SUCCESS/FAILURE + ***************************************************************************/ +int8_t occli_parse_cliString(char *cliString) +{ + int8_t ret = FAILED; + int16_t index = 0; + char tempStr[OCCLI_STRING_MAX_LEN] = {0}; + char *token = NULL; + + strcpy(tempStr, cliString); + token = strtok(tempStr, " "); + + for(index = 0; ((index < OCCLI_MAX_CLISTRING) && + (s_allParams[index] != NULL)); index++) { + + if (strcmp(token, s_allParams[index]) == 0) { + ret = SUCCESS; + break; + } + } + + return ret; +} +/************************************************************************** + * Function Name : occli_frame_commands + * Description : This Function is used to frame the cli commands + * Input(s) : root, occliData->option + * Output(s) : s_allParams, occliData->totalStr, occliData->sizeNum + ***************************************************************************/ +int8_t occli_frame_commands(const Component *root, + OCCLI_ARRAY_PARAM *occliData) +{ + const Component *subSystem = root; + const Component *component = subSystem->components; + const Component *subComponent = NULL; + const Command *command = NULL; + const Driver *driver = NULL; + + + if ((root == NULL) || + (occliData == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + /* subsytem->component->command */ + subSystem = root; + while (subSystem && subSystem->name) { + component = subSystem->components; + while (component && component->name) { + command = component->commands; + while (command && + command->name) { + if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) { + occliData->sizeNum += 1; + } else { + snprintf(s_allParams[occliData->totalStr++], + OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s", + subSystem->name, component->name, command->name); + } + command += 1; + } + component += 1; + } + subSystem += 1; + } + + /* subsytem->component->driver->command */ + subSystem = root; + while (subSystem && subSystem->name) { + component = subSystem->components; + while (component && component->name) { + driver = component->driver; + if(driver != NULL) { + command = driver->commands; + while (command && + command->name) { + if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) { + occliData->sizeNum += 1; + } else { + snprintf(s_allParams[occliData->totalStr++], + OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s", + subSystem->name, component->name, + command->name); + } + command += 1; + } + } + component += 1; + } + subSystem += 1; + } + + /* subsytem->component->subComponent->driver->command */ + subSystem = root; + while (subSystem && subSystem->name) { + component = subSystem->components; + while (component && component->name) { + subComponent = component->components; + while (subComponent && subComponent->name) { + driver = subComponent->driver; + if(driver != NULL) { + command = driver->commands; + while (command && + command->name) { + if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) { + occliData->sizeNum += 1; + } else { + snprintf(s_allParams[occliData->totalStr++], + OCCLI_STRING_MAX_LEN, "%s.%s.%s.%s", + subSystem->name, component->name, + subComponent->name, command->name); + } + command += 1; + } + } + subComponent += 1; + } + component += 1; + } + subSystem += 1; + } + return SUCCESS; +} +/************************************************************************** + * Function Name : occli_frame_string_from_schemaDriver + * Description : This Function is used to frame the cli string + * Input(s) : param, strFrame, msgTypeStr + * Output(s) : ocmwclistr, occliData + ***************************************************************************/ +int8_t occli_frame_string_from_schemaDriver(const Parameter *param, + OCCLI_ARRAY_PARAM *occliData, + strMsgFrame *strFrame) +{ + if ((occliData == NULL) || (param == NULL) || (strFrame == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) { + occliData->sizeNum += 1; + } else { + if (strlen(strFrame->subcomponent)) { + snprintf(s_allParams[occliData->totalStr++], + OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s.%s.%s.%s", + strFrame->subsystem, strFrame->component, + strFrame->msgtype, strFrame->subcomponent, + param->name, strFrame->parameter); + } else { + snprintf(s_allParams[occliData->totalStr++], + OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s.%s.%s", + strFrame->subsystem, strFrame->component, + strFrame->msgtype, param->name, strFrame->parameter); + } + } + return SUCCESS; +} +// TO use for POST +/************************************************************************** + * Function Name : occli_frame_string_from_postDriver + * Description : This Function is used to frame the cli string + * Input(s) : param, strFrame, msgTypeStr + * Output(s) : ocmwclistr, occliData + ***************************************************************************/ +int8_t occli_frame_string_from_postDriver(const Post *param, + OCCLI_ARRAY_PARAM *occliData, + strMsgFrame *strFrame) +{ + if ((occliData == NULL) || (param == NULL) || (strFrame == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + if (occliData->option == OCCLI_CALC_SCHEMA_SIZE) { + occliData->sizeNum += 1; + } else { + if (strlen(strFrame->subcomponent)) { + snprintf(s_allParams[occliData->totalStr++], + OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s.%s.%s.%s", + strFrame->subsystem, strFrame->component, + strFrame->msgtype, strFrame->subcomponent, + param->name, strFrame->parameter); + } else { + snprintf(s_allParams[occliData->totalStr++], + OCCLI_SNPRINTF_MAX_LEN, "%s.%s.%s.%s.%s", + strFrame->subsystem, strFrame->component, + strFrame->msgtype, param->name, strFrame->parameter); + } + } + return SUCCESS; +} +/************************************************************************** + * Function Name : occli_frame_string_from_schema + * Description : This Function is used to frame the cli string + * Input(s) : devDriver, strFrame + * Output(s) : ocmwclistr, occliData + ***************************************************************************/ +int8_t occli_frame_string_from_schema(const Driver *devDriver, + OCCLI_ARRAY_PARAM *occliData, + strMsgFrame *strFrame) +{ + const Post *postParam = NULL; + const Parameter *param = NULL; + int8_t ret = SUCCESS; + + if ((devDriver == NULL) || (occliData == NULL) || (strFrame == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + postParam = devDriver->post; + while (postParam && postParam->name) { + strcpy(strFrame->msgtype, "post"); + if (strncmp(postParam->name, "enable", strlen(postParam->name)) == 0) { + strcpy(strFrame->parameter, "set"); + } else { + strcpy(strFrame->parameter, "get"); + } + ret = occli_frame_string_from_postDriver(postParam, occliData, strFrame); + postParam++; + } + + param = devDriver->config; + while (param && param->name) { + strcpy(strFrame->msgtype, "config"); + strcpy(strFrame->parameter, "set"); + ret = occli_frame_string_from_schemaDriver(param, occliData, strFrame); + + strcpy(strFrame->parameter, "get"); + ret = occli_frame_string_from_schemaDriver(param, occliData, strFrame); + param++; + } + + param = devDriver->status; + while (param && param->name) { + strcpy(strFrame->msgtype, "status"); + strcpy(strFrame->parameter, "get"); + ret = occli_frame_string_from_schemaDriver(param, occliData, strFrame); + param++; + } + +#ifdef OCCLI_ALERT_STRING + param = devDriver->alerts; + strcpy(strFrame->msgtype, "alert"); + ret = occli_frame_string_from_schemaDriver(param, occliData, strFrame); +#endif + + return ret; +} +/************************************************************************** + * Function Name : occli_frame_string + * Description : This Function is used to frame the cli string + * Input(s) : root + * Output(s) : ocmwclistr, occliData + ***************************************************************************/ +int8_t occli_frame_string(const Component *root, OCCLI_ARRAY_PARAM *occliData) +{ + const Component *component = NULL, *subComponent = NULL, *subSystem = root; + const Driver *devDriver = NULL; + int8_t ret = 0; + + strMsgFrame *strFrame = (strMsgFrame *) malloc(sizeof(strMsgFrame)); + + if ((strFrame == NULL) || (root == NULL) || + (occliData == NULL)) { + logerr("Invalid Memory \n"); + return FAILED; + } + + /* Config/Status/Alerts Table array entry Creation */ + while (subSystem && subSystem->name) { + memset(strFrame, '\0', sizeof(strMsgFrame)); + strcpy(strFrame->subsystem, subSystem->name); + component = subSystem->components; + while (component && component->name) { + memset(strFrame->subcomponent, '\0', OCCLI_CHAR_ARRAY_SIZE); + strcpy(strFrame->component, component->name); + devDriver = component->driver; + if (devDriver != NULL) { + ret = occli_frame_string_from_schema(devDriver, + occliData, strFrame); + if (ret == FAILED) { + return ret; + } + } + subComponent = component->components; + while (subComponent && subComponent->name) { + strcpy(strFrame->subcomponent, subComponent->name); + devDriver = subComponent->driver; + if (devDriver != NULL) { + ret = occli_frame_string_from_schema(devDriver, + occliData, strFrame); + if (ret == FAILED) { + return ret; + } + } + subComponent += 1; + } + component += 1; + } + subSystem += 1; + } + free(strFrame); + return SUCCESS; +} + +/************************************************************************** + * Function Name : main + * Description : + * Input(s) : argc, argv + * Output(s) : + ***************************************************************************/ +int32_t main(int32_t argc, char *argv[]) +{ + char *line = NULL; + char *clistr = NULL; + char response[RES_STR_BUFF_SIZE] = {0}; + char historyFile[HIT_FILE_BUFF_SIZE]; + char *cmdstr = NULL; + const char* prompt = "opencellular# "; + int32_t index = 0; + int32_t ret = 0; + pthread_t alertThreadId; + sMsgParam msgFrameParam; + OCCLI_ARRAY_PARAM occliArray; + + /* Initialize logging */ + initlog("occli"); + + memset(&msgFrameParam, 0, sizeof(sMsgParam)); + memset (&occliArray, 0, sizeof(OCCLI_ARRAY_PARAM)); + + occliArray.option = OCCLI_CALC_SCHEMA_SIZE; + + ret = occli_frame_string(sys_schema, &occliArray); + if (ret != 0) { + logerr("init_ocmw_comm() failed."); + return FAILED; + } + + ret = occli_frame_commands(sys_schema, &occliArray); + if (ret != 0) { + logerr("init_ocmw_comm() failed."); + return FAILED; + } + + for (index= 0; index< occliArray.sizeNum; index++) { + if(!(s_allParams[index] = (char *)malloc(OCCLI_STRING_MAX_LEN))) { + return FAILED; + } + + } + + occliArray.option = OCCLI_PARSE_SCHEMA; + ret = occli_frame_string(sys_schema, &occliArray); + if (ret != 0) { + logerr("init_ocmw_comm() failed."); + return FAILED; + } + + ret = occli_frame_commands(sys_schema, &occliArray); + if (ret != 0) { + logerr("init_ocmw_comm() failed."); + return FAILED; + } + + /* Initialize Middleware IPC communication */ + ret = occli_init_comm(); + if (ret != 0) { + logerr("init_ocmw_comm() failed."); + return FAILED; + } + + /* Execute the OC command (argv[1:]) and exit */ + if (strcmp("occmd", basename(argv[0])) == 0) { + for (index= 1; index < argc; index++) { + if (occli_strjoin(&cmdstr, argv[index], " ") != 0) { + logerr("occli_strjoin error"); + break; + } + } + + ret = occli_parse_cliString(cmdstr); + if (ret != SUCCESS) { + printf("%s : Error : Invalid String\n", cmdstr); + free(cmdstr); + cmdstr = NULL; + } + + if (cmdstr != NULL) { + logdebug("cmdstr='%s'", cmdstr); + occli_send_cmd_to_ocmw(cmdstr, strlen(cmdstr)); + memset(response, 0, sizeof(response)); + occli_recv_cmd_resp_from_ocmw(response, sizeof(response)); + + printf("%s\n", response); + free(cmdstr); + } else { + printf("internal error\n"); + } + } + /* Entering interactive CLI */ + else if (strcmp("occli", basename(argv[0])) == 0) { + ret = pthread_create(&alertThreadId, NULL, + occli_alertthread_messenger_to_ocmw, NULL); + + if (ret != 0) { + return ret; + } + + /* Initialize readline */ + using_history(); + if ((snprintf(historyFile, HIT_FILE_BUFF_SIZE, "%s/%s", getenv("HOME"), + HISTORY)) < 0) { + return FAILED; + } + + read_history(historyFile); + rl_attempted_completion_function = occli_custom_completion; + + /*Printing hints at the start of opencelluar */ + occli_print_opencelluar(); + + while (1) { + line = readline(prompt); + if (line == NULL) { + break; + } + clistr = line; + + /* trim initial white spaces */ + while (isblank(*clistr)) { + ++clistr; + } + occli_trim_extra_spaces(clistr); + if (strcmp(clistr, "") == 0) { + continue; + } + + /* Quit the CLI, when command 'quit' is received */ + if (strcmp(clistr, "quit") == 0) { + free(line); + break; + } + /* Print the help manu */ + if((strstr(clistr, "help"))) { + if ((strstr(clistr, "--help"))) { + ret = occli_printHelpMenu(sys_schema, clistr); + if (ret == FAILED) { + logerr("occli_printHelpMenu failed.\n"); + } + continue; + } else { + printf("%s : Error : Incorrect request\n", clistr); + printf ("Usage : subsystem --help" + " OR subsystem.component --help\n"); + continue; + } + } + + ret = occli_parse_cliString(clistr); + if (ret != SUCCESS) { + printf("%s : Error : Invalid String\n", clistr); + continue; + } + + add_history(clistr); + + occli_send_cmd_to_ocmw(clistr, strlen(clistr)); + + memset(response, 0, sizeof(response)); + occli_recv_cmd_resp_from_ocmw(response, sizeof(response)); + + /* Print the command execution results in the CLI */ + printf("%s\n", response); + + free(line); + } + + write_history(historyFile); + } + + for (index= 0; ((s_allParams[index] != NULL) && + (index < OCCLI_MAX_CLISTRING)); index++) { + free(s_allParams[index]); + } + + for (index= 0; ((s_subSetParams[index] != NULL) && + (index < OCCLI_MAX_SUBSTRING)); index++) { + free(s_subSetParams[index]); + } + occli_deinit_comm(); + deinitlog(); + + return SUCCESS; +} diff --git a/firmware/host/occli/occli_ocmw_comm.c b/firmware/host/occli/occli_ocmw_comm.c new file mode 100644 index 0000000000..d3b97819c1 --- /dev/null +++ b/firmware/host/occli/occli_ocmw_comm.c @@ -0,0 +1,192 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* stdlib includes */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* OC includes */ +#include +#include + +static int32_t s_sockFd = 0; +static int32_t s_alertSockFd = 0; +static struct sockaddr_in s_siServer, s_alertServer; +static char s_displayStr[OCCLI_SNPRINTF_MAX_LEN]; + +/************************************************************************** + * Function Name : occli_init_comm + * Description : This Function used to initialize the communication + * between middleware code + * Input(s) : + * Output(s) : + ***************************************************************************/ +int32_t occli_init_comm(void) +{ + int32_t ret = 0; + int32_t inetAtonRet = 0; + struct timeval timeValObj; + + timeValObj.tv_sec = OCCLI_TIMEOUT_PERIOD; + timeValObj.tv_usec = 0; + + /* Create socket */ + s_sockFd = socket(OCMW_SOCK_DOMAIN, OCMW_SOCK_TYPE, OCMW_SOCK_PROTOCOL); + if (s_sockFd < 0) { + ret = -errno; + logerr("socket creation error [%d-%s]", errno, strerror(errno)); + return ret; + } + + /* Initialize socket structure */ + memset(&s_siServer, 0, sizeof(s_siServer)); + s_siServer.sin_family = OCMW_SOCK_DOMAIN; + s_siServer.sin_port = htons(OCMW_SOCK_SERVER_PORT); + inetAtonRet = inet_aton(OCMW_SOCK_SERVER_IP, &s_siServer.sin_addr); + if (inetAtonRet == 0) { + logerr("inet_aton failed"); + ret = FAILED; + return ret; + } + + if (setsockopt(s_sockFd, SOL_SOCKET, SO_RCVTIMEO, + &timeValObj, sizeof(timeValObj)) < 0) { + logerr("setsockopt failed"); + ret = FAILED; + return ret; + } + + /* For Alert Capture */ + s_alertSockFd = socket(OCMW_SOCK_ALERT_DOMAIN, OCMW_SOCK_ALERT_TYPE, + OCMW_SOCK_ALERT_PROTOCOL); + if (s_alertSockFd < 0) { + ret = -errno; + logerr("socket creation error [%d-%s]", errno, strerror(errno)); + return ret; + } + + /* Initialize socket structure */ + memset(&s_alertServer, 0, sizeof(s_alertServer)); + s_alertServer.sin_family = OCMW_SOCK_ALERT_DOMAIN; + s_alertServer.sin_port = htons(OCMW_SOCK_ALERT_SERVER_PORT); + inetAtonRet = inet_aton(OCMW_SOCK_ALERT_SERVER_IP, &s_alertServer.sin_addr); + if (inetAtonRet == 0) { + logerr("inet_aton failed"); + ret = FAILED; + return ret; + } + + /* Bind host address to the socket */ + ret = bind(s_alertSockFd, (struct sockaddr*) &s_alertServer, + sizeof(s_alertServer)); + if (ret < 0) { + ret = -errno; + logerr("bind error [%d-%s]", errno, strerror(errno)); + return ret; + } + + return SUCCESS; +} + +/************************************************************************** + * Function Name : occli_deinit_comm + * Description : This Function used to deinitialize the communication + * betwwen middleware code + * Input(s) : + * Output(s) : + ***************************************************************************/ +int8_t occli_deinit_comm(void) +{ + /* Close the IPC socket */ + close(s_sockFd); + s_sockFd = 0; + return SUCCESS; +} + +/************************************************************************** + * Function Name : occli_send_cmd_to_ocmw + * Description : This Function used to send command to middleware + * Input(s) : cmd, cmdlen + * Output(s) : + ***************************************************************************/ +int32_t occli_send_cmd_to_ocmw(const char *cmd, int32_t cmdlen) +{ + char errstr[OCMW_SOCKET_ERROR_SIZE]; + int32_t ret = 0; + int32_t strLen = sizeof(s_siServer); + + strncpy(s_displayStr, cmd, cmdlen); + /* Send the CLI command string to OCMW over UDP socket */ + ret = sendto(s_sockFd, cmd, cmdlen, 0, + (const struct sockaddr *) &s_siServer, strLen); + if (ret < 0) { + strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE); + logerr("Error: 'sendto' [%d-%s]", errno, errstr); + printf("%s : Error : Socket error", s_displayStr); + } + return ret; +} + +/************************************************************************** + * Function Name : occli_recv_cmd_resp_from_ocmw + * Description : This Function used to receive message from middlware + * Input(s) : + * Output(s) : resp, resplen + ***************************************************************************/ +int32_t occli_recv_cmd_resp_from_ocmw(char *resp, int32_t resplen) +{ + char errstr[OCMW_SOCKET_ERROR_SIZE]; + int32_t ret = 0; + int32_t strLen = sizeof(s_siServer); + + /* Receive the CLI command execution response string from OCMW over UDP + socket */ + ret = recvfrom(s_sockFd, resp, resplen, 0, + (struct sockaddr*) &s_siServer, (socklen_t*) &strLen); + if (ret < 0) { + strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE); + logerr("Error: 'recvfrom' [%d-%s]", ret, errstr); + printf("%s : Error : Timeout from Middleware", s_displayStr); + } + return ret; +} + +/************************************************************************** + * Function Name : occli_recv_alertmsg_from_ocmw + * Description : This Function used to receive alert message from + * middleware + * Input(s) : + * Output(s) : resp, resplen + ***************************************************************************/ +int32_t occli_recv_alertmsg_from_ocmw(char *resp, int32_t resplen) +{ + char errstr[OCMW_SOCKET_ERROR_SIZE]; + int32_t ret = 0; + int32_t strLen = sizeof(s_alertServer); + + /* Receive the Alert Message string from OCMW over UDP socket */ + ret = recvfrom(s_alertSockFd, resp, resplen, 0, + (struct sockaddr*) &s_alertServer, (socklen_t*) &strLen); + if (ret < 0) { + strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE); + logerr("Error: 'recvfrom' [%d-%s]", ret, errstr); + printf("Error: 'recvfrom' [%d-%s]", ret, errstr); + } + return ret; +} diff --git a/firmware/host/ocmw/ocmw_clicmd.c b/firmware/host/ocmw/ocmw_clicmd.c new file mode 100644 index 0000000000..f0b04134bb --- /dev/null +++ b/firmware/host/ocmw/ocmw_clicmd.c @@ -0,0 +1,1216 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* stdlib includes */ +#include +#include +#include +#include +#include +#include +#include +/* OC includes */ +#include +#include +#include +#include +#include + +#define INVALID_SYNTAX "Error : Invalid syntax" +#define INSUFFICIENT_PARAM "Error : Insufficient parameters" + +extern int8_t obcTestingmoduleData[MAX_PARM_COUNT]; +extern int8_t dataOutBufFromEc[MAX_PARM_COUNT]; +extern int8_t eepromStatusFlag; +extern int64_t recvdParamVal; +extern int8_t eepromStatusFlag; +extern int8_t eepromStatusFlag; +extern int32_t eepromFlag; +extern uint8_t ocwarePostArrayIndex; +debugI2CData I2CInfo; +debugMDIOData MDIOInfo; + +struct matchString { + const char *key; + ocmw_token_t token; +} ocmwTokenTable[] = { + { "set", SET_STR }, + { "get", GET_STR }, + { "reset", RESET_STR }, + { "enable", ENABLE_STR }, + { "disable", DISABLE_STR }, + {"active", ACTIVE_STR }, + { "echo", ECHO_STR }, + { "disconnect_nw", DISCONNECT_STR }, + { "connect_nw", CONNECT_STR }, + { "send", SEND_STR }, + { "dial", DIAL_STR }, + { "answer", ANSWER_STR }, + { "hangup", HANGUP_STR }, + { "en_loopBk", ELOOPBK_STR }, + { "dis_loopBk", DLOOPBK_STR }, + { "en_pktGen", EPKTGEN_STR }, + { "dis_pktGen", DPKTGEN_STR }, + { NULL, MAX_STR }, +}; + +struct matchSetGet { + const char *key; + ocmw_setGet token; +} ocmwSetGetTable[] = { + { "hci.led.fw", HCI_STR }, + { "debug", DEBUG_STR }, + {"system.comp_all.post.results", RESULT_STR }, + {"system.comp_all.post.enable", ENABLE_SET_STR }, + { NULL, GETSETMAX }, +}; +/************************************************************************** + * Function Name : ocmw_tokenize_class + * Description : This Function used to extract the class from the param + * string + * Input(s) : str, option + * Output(s) : param + ***************************************************************************/ +static int32_t ocmw_tokenize_class(char *str, char *param, int32_t option) +{ + char *token; + int32_t count = 0; + + token = strtok(str, " ."); + if (token == NULL) + return -1; + + while (token) { + if (count == 2) { + strncpy(param, token, PARAMSTR_NUMBER_LEN); + break; + } + token = strtok(NULL, " ."); + count++; + + if(option == 1){ + strncpy(param, token, PARAMSTR_NUMBER_LEN); + break; + } + } + return SUCCESS; +} + +/************************************************************************** + * Function Name : ocmw_tokenize + * Description : This Function used to extract the CLI string + * Input(s) : cmdstr + * Output(s) : strTokenCount, strTokenArray + ***************************************************************************/ +static int32_t ocmw_tokenize(const char *cmdstr, + int32_t *strTokenCount, char ***strTokenArray) +{ + char *str = NULL; + char *saveptr = NULL; + char *paramStr = NULL; + char *token = NULL; + char **localStrTokenArray = NULL; + char **temp = NULL; + const char *delim = " "; + int32_t localStrTokenCount = 0; + int32_t index = 0; + + /* Split the actiontype from the cmdstr */ + paramStr = strrchr(cmdstr, '.'); + *paramStr = ' '; + + for (index = 1, str = (char*) cmdstr;; index++, str = NULL) { + token = strtok_r(str, delim, &saveptr); + if (token == NULL) { + break; + } + + localStrTokenCount++; + temp = localStrTokenArray; + localStrTokenArray = realloc(localStrTokenArray, + sizeof(char *) * localStrTokenCount); + if (localStrTokenArray == NULL) { + logerr("realloc failed"); + /* Free the original block of memory before realloc */ + if (temp != NULL) { + free(temp); + } + return FAILED; + } + localStrTokenArray[localStrTokenCount - 1] = token; + } + + *strTokenCount = localStrTokenCount; + *strTokenArray = localStrTokenArray; + return SUCCESS; +} + +/************************************************************************** + * Function Name : ocmw_check_numeric_number + * Description : This Function used to validate the mobile number + * Input(s) : numstring + * Output(s) : + ***************************************************************************/ +int32_t ocmw_check_numeric_number(char *numstring) +{ + int32_t index = 0; + int32_t len = strlen(numstring); + + while (index < len) { + if ((*(numstring + index) < '0') || + (*(numstring + index) > '9')) { + return FAILED; + } + index++; + } + return SUCCESS; +} +#if 0 +/************************************************************************** + * Function Name : ocmw_string_parse + * Description : This Function used to parse the param string + * Input(s) : string + * Output(s) : outStr + ***************************************************************************/ +int8_t ocmw_string_parse(char *string, char *outStr) +{ + char *token; + char string1[CHAR_SIZE_12] = { 0 }; + char string2[CHAR_SIZE_12] = { 0 }; + + token = strtok(string, " ."); + if (token == NULL) { + return FAILED; + } + + strncpy(string1, token, CHAR_SIZE_12); + token = strtok(NULL, " ."); + if (token == NULL) { + return FAILED; + } + strncpy(string2, token, CHAR_SIZE_12); + + if ((snprintf(outStr, CHAR_SIZE_32, "%s.%s", string1, string2)) < 0) { + return FAILED; + } + return SUCCESS; +} +#endif +/************************************************************************** + * Function Name : ocmw_handle_set_config + * Description : This Function used to handle the set config commands + * Input(s) : strTokenArray + * Output(s) : response + ***************************************************************************/ +static int32_t ocmw_handle_set_config(char* strTokenArray[], char *response) +{ + char *paramStr; + void *paramvalue; + int32_t ret = 0; + char tempParamStr[PARAM_STR_MAX_BUFF_SIZE] = {0}; + + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + paramStr = strTokenArray[0]; + paramvalue = strTokenArray[2]; + strcpy(tempParamStr, strTokenArray[0]); + + ret = ocmw_msgproc_send_msg(&strTokenArray[0], OCMP_AXN_TYPE_SET, + OCMP_MSG_TYPE_CONFIG, (int8_t *) paramStr, paramvalue); + + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s = %s : %s", strTokenArray[0], + strTokenArray[1], strTokenArray[2], + (ret != 0) ? "Failed" : "Success")) < 0) { + return FAILED; + } + + return ret; +} + +/************************************************************************** + * Function Name : ocmw_handle_show_config + * Description : This Function used to handle the show config commands + * Input(s) : strTokenArray + * Output(s) : response + ***************************************************************************/ +static int32_t ocmw_handle_show_config(char* strTokenArray[], char *response) +{ + char *paramStr; + char tempParamStr[PARAM_STR_MAX_BUFF_SIZE] = {0}; + int32_t paramVal = 0; + int32_t ret = 0; + + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + paramStr = strTokenArray[0]; + strcpy(tempParamStr, strTokenArray[0]); + + + ret = ocmw_msgproc_send_msg(&strTokenArray[0], OCMP_AXN_TYPE_GET, + OCMP_MSG_TYPE_CONFIG, (int8_t *) paramStr, ¶mVal); + + if (ret != 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s : Failed", + tempParamStr, strTokenArray[1])) < 0) { + return FAILED; + } + } else { + if (eepromFlag > 0){ + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s = %s", + tempParamStr, strTokenArray[1], dataOutBufFromEc)) < 0) { + return FAILED; + } + } else { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s = %" PRId64, + (int8_t *)tempParamStr, strTokenArray[1], recvdParamVal)) <0) { + return FAILED; + } + } + } + return ret; +} + +/************************************************************************** + * Function Name : ocmw_handle_show_status + * Description : This Function used to handle the status commands + * Input(s) : strTokenArray + * Output(s) : response + ***************************************************************************/ +static int32_t ocmw_handle_show_status(char* strTokenArray[], char *response) +{ + char *paramStr; + int32_t ret = 0; + int32_t value = 0; + char tempParamStr[PARAM_STR_MAX_BUFF_SIZE] = {0}; + + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + paramStr = strTokenArray[0]; + strcpy(tempParamStr, strTokenArray[0]); + + + ret = ocmw_msgproc_send_msg(&strTokenArray[0], OCMP_AXN_TYPE_GET, + OCMP_MSG_TYPE_STATUS, (int8_t *) paramStr, (void*) &value); + + if (ret != 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s : Failed", + tempParamStr, strTokenArray[1])) < 0) { + return FAILED; + } + } else if (eepromFlag > 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s = %s", + tempParamStr, strTokenArray[1], dataOutBufFromEc)) < 0) { + return FAILED; + } + } else { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s = %" PRId64, + tempParamStr, strTokenArray[1], recvdParamVal)) < 0) { + return FAILED; + } + } + + return ret; +} + +/************************************************************************** + * Function Name : ocmw_handle_debug_command_function + * Description : This Function used to handle the debug commands + * Input(s) : strTokenArray, action + * Output(s) : response + ***************************************************************************/ +static int32_t ocmw_handle_debug_command_function(char* strTokenArray[], + char *response) +{ + char paramStr[PARAM_STR_BUFF_SIZE] = {0}; + char displayStr[PARAM_STR_BUFF_SIZE] = {0}; + void *paramvalue = NULL; + int32_t value = 0; + int32_t ret = 0; + + debugGPIOData GPIOInfo; + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + if((strncmp("debug", strTokenArray[0], + strlen("debug")) == 0) && + (strncmp(strTokenArray[1], "set", strlen("set")) + == 0)) { + /* Registers debug option */ + if((strncmp("debug.I2C", strTokenArray[0], + strlen("debug.I2C")) == 0) && + (strncmp(strTokenArray[1], "set", strlen("set")) + == 0)) { + I2CInfo.slaveAddress = atoi(strTokenArray[2]); + I2CInfo.numOfBytes = atoi(strTokenArray[3]); + I2CInfo.regAddress = atoi(strTokenArray[4]); + I2CInfo.regValue = atoi(strTokenArray[5]); + paramvalue = (void*) &I2CInfo; + sprintf(displayStr, "%s (slave address :%s noOfBytes :%s" + " Register Address :%s) %s= %s", strTokenArray[0], + strTokenArray[2], strTokenArray[3], + strTokenArray[4], strTokenArray[1], strTokenArray[5]); + } else if ((strncmp("debug.ethernet", strTokenArray[0], + strlen("debug.ethernet")) == 0)) { + MDIOInfo.regAddress = atoi(strTokenArray[2]); + MDIOInfo.regValue = atoi(strTokenArray[3]); + paramvalue = (void*) &MDIOInfo; + sprintf(displayStr, "%s (Register Address :%s) %s = %s", + strTokenArray[0], strTokenArray[2], + strTokenArray[1], strTokenArray[3]); + } else { + GPIOInfo.pin = atoi(strTokenArray[2]); + GPIOInfo.value = atoi(strTokenArray[3]); + paramvalue = (void*) &GPIOInfo; + sprintf(displayStr, "%s (Pin No :%s) %s = %s", + strTokenArray[0], strTokenArray[2], + strTokenArray[1], strTokenArray[3]); + } + } else if((strncmp("debug", strTokenArray[0], + strlen("debug")) == 0) && + (strncmp(strTokenArray[1], "get", strlen("get")) + == 0)) { + /* Registers debug option */ + if((strncmp("debug.I2C", strTokenArray[0], + strlen("debug.I2C")) == 0) && + (strncmp(strTokenArray[1], "get", strlen("get")) + == 0)) { + I2CInfo.slaveAddress = atoi(strTokenArray[2]); + I2CInfo.numOfBytes = atoi(strTokenArray[3]); + I2CInfo.regAddress = atoi(strTokenArray[4]); + paramvalue = (void*) &I2CInfo; + sprintf(displayStr, "%s (slave address :%s noOfBytes :%s" + " Register Address :%s) %s", strTokenArray[0], + strTokenArray[2], strTokenArray[3], + strTokenArray[4], strTokenArray[1]); + } else if ((strncmp("debug.ethernet", strTokenArray[0], + strlen("debug.ethernet")) == 0)) { + MDIOInfo.regAddress = atoi(strTokenArray[2]); + paramvalue = (void*) &MDIOInfo; + sprintf(displayStr, "%s (Register Address :%s) %s", + strTokenArray[0], strTokenArray[2], + strTokenArray[1]); + } else { + GPIOInfo.pin = atoi(strTokenArray[2]); + paramvalue = (void*) &GPIOInfo; + sprintf(displayStr, "%s (Pin No :%s) %s", + strTokenArray[0], strTokenArray[2], + strTokenArray[1]); + } + } else { + paramvalue = (void*) &value; + } + if ((snprintf(paramStr, PARAM_STR_BUFF_SIZE, "%s.%s", + strTokenArray[1],strTokenArray[0])) < 0) { + return FAILED; + } + ret = ocmw_msgproc_send_msg(&strTokenArray[0], 0, + OCMP_MSG_TYPE_COMMAND, (int8_t *) paramStr, paramvalue); + + if (ret != SUCCESS) { + snprintf(response, RES_STR_BUFF_SIZE, "%s : Failed", displayStr); + } else { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s %s", + strTokenArray[0], dataOutBufFromEc)) < 0) { + return FAILED; + } + } + return ret; +} + +/************************************************************************** + * Function Name : ocmw_handle_testmod_command_function + * Description : This Function used to handle the test modules commands + * Input(s) : strTokenArray, action + * Output(s) : response + ***************************************************************************/ +static int32_t ocmw_handle_testmod_command_function(char* strTokenArray[], + char *response) +{ + char paramStr[PARAM_STR_BUFF_SIZE] = {0}; + char msgstr[PARAM_STR_BUFF_SIZE] = {0}; + void *paramvalue = NULL; + int32_t value = 0; + int32_t len = 0; + int32_t ret = 0; + char tempParamStr[PARAM_STR_MAX_BUFF_SIZE] = {0}; + + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + + if ((strncmp(strTokenArray[1], "send", strlen("send"))) == + 0) { + if (strlen(strTokenArray[2]) > OCMW_MAX_IMEI_SIZE) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s " + "(number = %s, msg = %s) : Error : Number " + "Invalid", strTokenArray[0], strTokenArray[1], + strTokenArray[2], strTokenArray[3])) < 0) { + return FAILED; + } + return FAILED; + } + if (ocmw_check_numeric_number(strTokenArray[2]) != SUCCESS) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s " + "(number = %s, msg = %s) : Error : Number " + "Invalid", strTokenArray[0], strTokenArray[1], + strTokenArray[2], strTokenArray[3])) < 0) { + return FAILED; + } + return FAILED; + } + len = strlen(strTokenArray[3]); + len = + (len < OCMW_MAX_MSG_SIZE) ? len : OCMW_MAX_MSG_SIZE - 1; + if ((snprintf(msgstr, PARAM_STR_BUFF_SIZE, "%s", + strTokenArray[2])) + < 0) { + return FAILED; + } + if ((snprintf(&msgstr[TESTMOD_MAX_LEN], PARAM_STR_BUFF_SIZE, "%s", + strTokenArray[3])) < 0) { + return FAILED; + } + paramvalue = (void *) msgstr; + } else if (strncmp(strTokenArray[1], "dial", strlen("dial")) == + 0) { + if (strlen(strTokenArray[2]) > OCMW_MAX_IMEI_SIZE) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s " + "(number = %s) : Error : Number " + "Invalid", strTokenArray[0], strTokenArray[1], strTokenArray[2])) < 0) { + return FAILED; + } + return FAILED; + } + if (ocmw_check_numeric_number(strTokenArray[2]) != SUCCESS) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s " + "(number = %s) : Error : Number " + "Invalid", strTokenArray[0], strTokenArray[1], strTokenArray[2])) < 0) { + return FAILED; + } + return FAILED; + } + paramvalue = (void*) (strTokenArray[2]); + } else { + paramvalue = (void*) &value; + } + strcpy(tempParamStr,strTokenArray[0]); + if ((snprintf(paramStr, PARAM_STR_BUFF_SIZE, "%s.%s", + strTokenArray[1], strTokenArray[0])) < 0) { + return FAILED; + } + ret = ocmw_msgproc_send_msg(&strTokenArray[0], 0, + OCMP_MSG_TYPE_COMMAND, (int8_t *) paramStr,paramvalue); + if (strncmp(strTokenArray[1], "get", strlen("get")) == 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s = %s", + tempParamStr, strTokenArray[1], dataOutBufFromEc)) < 0) { + return FAILED; + } + } else if (strncmp(strTokenArray[1], "send", strlen("send")) == 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s (number = %s msg = %s)" + " : %s", strTokenArray[0], strTokenArray[1], strTokenArray[2], + strTokenArray[3], (ret != SUCCESS) ? "Failed" : "Success")) < 0) { + return FAILED; + } + } else if (strncmp(strTokenArray[1], "dial", strlen("dial")) == 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s (number = %s) :" + " %s", strTokenArray[0], strTokenArray[1], strTokenArray[2], + (ret != SUCCESS) ? "Failed" : "Success")) < 0) { + return FAILED; + } + } else { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s : %s", strTokenArray[0], + strTokenArray[1], (ret != SUCCESS) ? "Failed" : "Success")) < + 0) { + return FAILED; + } + } + return ret; +} +/************************************************************************** + + * Function Name : ocmw_handle_ethernet_command_function + * Description : This Function used to handle the loopBack and packent + * genrator commands + * Input(s) : strTokenArray, action + * Output(s) : response + ***************************************************************************/ +static int8_t ocmw_handle_ethernet_command_function(char* strTokenArray[], + char *response) +{ + char paramStr[PARAM_STR_BUFF_SIZE] = { 0 }; + void *paramvalue = NULL; + + int32_t value = 0; + int32_t ret = 0; + char tempParamStr[PARAM_STR_MAX_BUFF_SIZE] = {0}; + + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + value = atoi(strTokenArray[2]); + + if (((value > 2) || (value < 0)) && + (strstr(strTokenArray[1],"loopBk"))) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s " + "(number = %s) : Error : Number Invalid", + strTokenArray[0], strTokenArray[1], strTokenArray[2])) < 0) { + + return FAILED; + } + return FAILED; + } + + paramvalue = (void*) &value; + strcpy(tempParamStr,strTokenArray[0]); + if ((snprintf(paramStr, PARAM_STR_BUFF_SIZE, "%s.%s", + strTokenArray[1],strTokenArray[0])) < 0) { + return FAILED; + } + ret = ocmw_msgproc_send_msg(&strTokenArray[0], 0, + OCMP_MSG_TYPE_COMMAND, (int8_t *) paramStr, paramvalue); + if (strncmp(strTokenArray[1], "dis_pktGen", strlen("dis_pktGen")) == 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s : %s", + strTokenArray[0], strTokenArray[1], (ret != 0) ? "Failed" : + "Success")) < 0) { + return FAILED; + } + } else { + /* processing enable_pktGen */ + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s %s : %s", + strTokenArray[0], strTokenArray[1], strTokenArray[2], + (ret != 0) ? "Failed" : "Success")) < 0) { + return FAILED; + } + } + return ret; +} +/************************************************************************** + * Function Name : ocmw_handle_hci_led_set_command_function + * Description : This Function used to handle the test modules commands + * Input(s) : strTokenArray, action + * Output(s) : response + ***************************************************************************/ +static int32_t ocmw_handle_hci_led_set_command_function(char* strTokenArray[], + char *response) +{ + char paramStr[PARAM_STR_BUFF_SIZE] = { 0 }; + void *paramvalue = NULL; + int32_t value = 0; + int32_t ret = 0; + char tempParamStr[PARAM_STR_MAX_BUFF_SIZE] = {0}; + + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + value = atoi(strTokenArray[2]); + paramvalue = (void*) &value; + strcpy(tempParamStr,strTokenArray[0]); + if ((snprintf(paramStr, PARAM_STR_BUFF_SIZE, "%s.%s", + strTokenArray[1],strTokenArray[0])) < 0) { + return FAILED; + } + ret = ocmw_msgproc_send_msg(&strTokenArray[0], 0, + OCMP_MSG_TYPE_COMMAND, (int8_t *) paramStr, paramvalue); + if (strncmp(strTokenArray[1], "get", strlen("get")) + == 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s = %s", + tempParamStr, strTokenArray[1],dataOutBufFromEc)) < 0) { + return FAILED; + } + } else { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s %s : %s", + strTokenArray[0], strTokenArray[1], strTokenArray[2], + (ret != 0) ? "Failed" : "Success")) < 0) { + return FAILED; + } + } + return ret; +} + +/************************************************************************** + * Function Name : ocmw_handle_command_function + * Description : This Function used to handle the command messages + * Input(s) : strTokenArray, action + * Output(s) : response + ***************************************************************************/ +static int32_t ocmw_handle_command_function(char* strTokenArray[], + char *response) +{ + char paramStr[PARAM_STR_BUFF_SIZE]; + int32_t ret = 0; + int32_t paramVal = 0; + char tempParamStr[PARAM_STR_MAX_BUFF_SIZE] = {0}; + + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + strcpy(tempParamStr, strTokenArray[0]); + + if ((snprintf(paramStr, PARAM_STR_BUFF_SIZE, "%s.%s", strTokenArray[1], + strTokenArray[0])) < 0) { + return FAILED; + } + + ret = ocmw_msgproc_send_msg(&strTokenArray[0], 0, + OCMP_MSG_TYPE_COMMAND, (int8_t *) paramStr, ¶mVal); + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s.%s : %s", + strTokenArray[0], strTokenArray[1], + (ret != 0) ? "Failed" : "Success")) < 0) { + return FAILED; + } + + return ret; +} + +/************************************************************************** + * Function Name : ocmw_handle_post_command + * Description : This Function used to handle the post commands + * Input(s) : strTokenArray + * Output(s) : response + ***************************************************************************/ +static int32_t ocmw_handle_post_command(char* strTokenArray[], char *response) +{ + char paramStr[PARAM_STR_BUFF_SIZE], tmp[TEMP_STR_BUFF_SIZE]; + char subSys[PARAM_STR_BUFF_SIZE]; + int32_t ret = 0; + int32_t index = 0; + int32_t paramVal = 0; + int32_t count = 0; + ocwarePostResults postResult; + ocwarePostReplyCode reply; + + if (strTokenArray == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + + strcpy(subSys,postResult.results[0].subsysName); + if (strcmp("set", strTokenArray[1]) == 0) { + if ((snprintf(paramStr, PARAM_STR_BUFF_SIZE, "%s.%s", + strTokenArray[0], strTokenArray[1])) < 0) { + return FAILED; + } + ret = ocmw_msgproc_send_msg(&strTokenArray[0], OCMP_AXN_TYPE_SET, + OCMP_MSG_TYPE_POST, (int8_t *) paramStr,¶mVal); + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s : %s", paramStr, + (ret != 0) ? "Failed" : "Success")) < + 0) { + return FAILED; + } + } else if (strcmp("get", strTokenArray[1]) == 0) { + if ((snprintf(paramStr, PARAM_STR_BUFF_SIZE, "%s.%s", strTokenArray[0], + strTokenArray[1])) < 0) { + return FAILED; + } + ret = ocmw_msgproc_send_msg(&strTokenArray[0], OCMP_AXN_TYPE_GET, + OCMP_MSG_TYPE_POST, (int8_t *) paramStr, ¶mVal); + if (ret != 0) { + if ((snprintf(response, RES_STR_BUFF_SIZE, "%s : Failed", paramStr)) + < 0) { + return FAILED; + } + } + postResult.count = ocwarePostArrayIndex; + + ret = ocmw_retrieve_post_results(&postResult); + if (ret < 0) { + logerr("%s error", paramStr); + return FAILED; + } + + strncpy(response, + "-------------------------------------------------------------------------------\n", + RES_STR_BUFF_SIZE); + if ((snprintf(tmp, TEMP_STR_BUFF_SIZE, "%-16s%-40s%-20s\n", + "Subsystem", "Device Name", "POST Status")) < 0) { + return FAILED; + } + + strncat(response, tmp, TEMP_STR_BUFF_SIZE); + if ((snprintf(tmp, TEMP_STR_BUFF_SIZE, + "-------------------------------------------------------------------------------\n")) + < 0) { + return FAILED; + } + strncat(response, tmp, TEMP_STR_BUFF_SIZE); + for (index = 0; index < postResult.count; index++) { + reply.msgtype = OCMP_MSG_TYPE_POST; + reply.replycode = postResult.results[index].status; + + ret = ocmw_retrieve_reply_code_desc(&reply); + if (ret < 0) { + strncpy(reply.desc, "", PARAM_STR_BUFF_SIZE); + } + if (strcmp(subSys,postResult.results[index].subsysName) != 0) { + strcpy(subSys,postResult.results[index].subsysName); + count = 0; + } + + if (count > 0) { + strcpy(postResult.results[index].subsysName, " "); + if ((snprintf(tmp, TEMP_STR_BUFF_SIZE, "%-16s%-40s%-20s\n", + postResult.results[index].subsysName, + postResult.results[index].deviceName, + reply.desc)) < 0) { + return FAILED; + } + strncat(response, tmp, TEMP_STR_BUFF_SIZE); + } else { + strcpy(subSys,postResult.results[index].subsysName); + postResult.results[index].subsysName[0] = + toupper(postResult.results[index].subsysName[0]); + if ((snprintf(tmp, TEMP_STR_BUFF_SIZE, "%-16s\n", + postResult.results[index].subsysName)) < 0) { + return FAILED; + } + strncat(response, tmp, TEMP_STR_BUFF_SIZE); + strcpy(postResult.results[index].subsysName, " "); + if ((snprintf(tmp, TEMP_STR_BUFF_SIZE, "%-16s%-40s%-20s\n", + postResult.results[index].subsysName, + postResult.results[index].deviceName, + reply.desc)) < 0) { + return FAILED; + } + strncat(response, tmp, TEMP_STR_BUFF_SIZE); + count++; + } + } + + if ((snprintf(tmp, TEMP_STR_BUFF_SIZE, + "-------------------------------------------------------------------------------\n")) + < 0) { + return FAILED; + } + + strncat(response, tmp, TEMP_STR_BUFF_SIZE); + + } else { + if ((snprintf(response, RES_STR_BUFF_SIZE, + "%s.%s : Error : Unknown parameter ", strTokenArray[0], strTokenArray[1])) < 0) { + return FAILED; + } + return FAILED; + } + return ret; +} +/************************************************************************** + * Function Name : ocmw_free_pointer + * Description : This is an inline function to free memory + * Input(s) : strTokenArray + * Output(s) : strTokenArray + ***************************************************************************/ +inline void ocmw_free_pointer(char **strTokenArray) { + if (strTokenArray) { + free(strTokenArray); + } + return; +} +/************************************************************************** + * Function Name : ocmw_match_set_get_string + * Description : This Function used to handle the cli set get + * Input(s) : str + * Output(s) : + ***************************************************************************/ +static ocmw_token_t ocmw_match_set_get_string(char *str) +{ + struct matchSetGet *index = ocmwSetGetTable; + for(; index->key != NULL && + strncmp(index->key, str, strlen(index->key)) != 0; ++index); + return index->token; +} +/************************************************************************** + * Function Name : ocmw_match_string + * Description : This Function used to handle the cli commands + * Input(s) : str + * Output(s) : + ***************************************************************************/ +static ocmw_token_t ocmw_match_string(char *str) +{ + struct matchString *index = ocmwTokenTable; + for(; index->key != NULL && + strncmp(index->key, str, strlen(index->key)) != 0; ++index); + return index->token; +} +/************************************************************************** + * Function Name : ocmw_frame_errorString + * Description : This Function used to handle the cli commands error + * Input(s) : cmdStr, errorString + * Output(s) : response + ***************************************************************************/ +int32_t ocmw_frame_errorString(const char *cmdStr, char *errorString, + char *response) +{ + if (errorString == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + if (snprintf(response, RES_STR_BUFF_SIZE, "%s : %s", + cmdStr, errorString)) { + logerr("%s(): Sprintf error", __func__); + return FAILED; + } + strcat(response, "\nPlease refer help menu:\n\"" + " --help or . --help\""); + return SUCCESS; +} +/************************************************************************** + * Function Name : ocmw_clicmd_handler + * Description : This Function used to handle the cli commands + * Input(s) : cmdstr + * Output(s) : response + ***************************************************************************/ +int32_t ocmw_clicmd_handler(const char *cmdStr, char *response) +{ + char **strTokenArray = NULL; + char class[PARAMSTR_NUMBER_LEN] = {0}; + char paramStr[PARAM_STR_BUFF_SIZE] = {0}; + int32_t strTokenCount = 0; + int32_t ret = 0; + + if (cmdStr == NULL || response == NULL) { + logerr("%s(): NULL pointer error", __func__); + return FAILED; + } + + if (strcmp(cmdStr, "") == 0) + return FAILED; + + ret = ocmw_tokenize(cmdStr, &strTokenCount, &strTokenArray); + if (ret < 0) { + logerr("Error: command string ocmw_tokenize failed"); + if ((snprintf(response, RES_STR_BUFF_SIZE, + "%s : Internal error occured in parsing CLI parameters", + cmdStr)) < 0) { + return FAILED; + } + ocmw_free_pointer(strTokenArray); + return FAILED; + } else { + if(strTokenCount > 1) { + strncpy(paramStr, strTokenArray[0], strlen(strTokenArray[0])); + /* Process the command */ + switch(ocmw_match_string(strTokenArray[1])) { + case SET_STR: + switch(ocmw_match_set_get_string(strTokenArray[0])) { + case HCI_STR: + if (strTokenCount == 3) { + ret = ocmw_handle_hci_led_set_command_function( + strTokenArray, response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 3 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + case DEBUG_STR: + if (strncmp("debug.I2C", strTokenArray[0], + strlen("debug.I2C")) == 0) { + if (strTokenCount == 6) { + ret = ocmw_handle_debug_command_function( + strTokenArray, response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 6 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + } else { + if (strTokenCount == 4) { + ret = ocmw_handle_debug_command_function( + strTokenArray, response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 4 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + } + break; + case ENABLE_SET_STR: + if (strTokenCount == 2) { + ret = ocmw_handle_post_command(strTokenArray, response); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 2 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + default: + if (strTokenCount == 3) { + ocmw_tokenize_class(paramStr, class, 2); + if (strcmp("config", class) == 0) { + ret = ocmw_handle_set_config(&strTokenArray[0], + response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + if ((snprintf(response, + RES_STR_BUFF_SIZE, "[Error]: " + "Incorrect %s request '%s'", + strTokenArray[0],strTokenArray[1])) < 0) { + return FAILED; + } + ocmw_free_pointer(strTokenArray); + return FAILED; + } + } else { + ret = (strTokenCount < 3 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + } + break; + case GET_STR: + switch(ocmw_match_set_get_string(strTokenArray[0])) { + case RESULT_STR: + if (strTokenCount == 2) { + ret = ocmw_handle_post_command(strTokenArray, response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 2 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + case DEBUG_STR: + if (strncmp("debug.I2C", strTokenArray[0], + strlen("debug.I2C")) == 0) { + if (strTokenCount == 5) { + ret = ocmw_handle_debug_command_function( + strTokenArray, response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 5 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + } else { + if (strTokenCount == 3) { + ret = ocmw_handle_debug_command_function( + strTokenArray, response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 3 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + } + break; + default : + if (strTokenCount == 2) { + ocmw_tokenize_class(paramStr, class, 2); + if (strcmp("config", class) == 0) { + ret = ocmw_handle_show_config(&strTokenArray[0], + response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else if (strcmp("status", class) == 0) { + ret = ocmw_handle_show_status(&strTokenArray[0], + response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else if (strcmp("alerts", class) == 0) { + /* SCHEMA change :: Alert is not implimented */ + /* ret = ocmw_handle_show_alerts(&strTokenArray[0], response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS;*/ + } else { + if ((snprintf(response, + RES_STR_BUFF_SIZE, "[Error]: " + "Incorrect %s request '%s'", + strTokenArray[0], strTokenArray[1])) < 0) { + return FAILED; + } + ocmw_free_pointer(strTokenArray); + return FAILED; + } + } else { + ret = (strTokenCount < 2 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + } + case RESET_STR: + case ENABLE_STR: + case DISABLE_STR: + case ACTIVE_STR: + case ECHO_STR: + if (strTokenCount == 2) { + ret = ocmw_handle_command_function(strTokenArray, response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 2 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + case DISCONNECT_STR: + case CONNECT_STR: + case ANSWER_STR: + case HANGUP_STR: + if (strTokenCount == 2) { + ret = ocmw_handle_testmod_command_function(strTokenArray, + response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 2 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + case SEND_STR: + if (strTokenCount == 4) { + ret = ocmw_handle_testmod_command_function(strTokenArray, + response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 4 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + case DIAL_STR: + if (strTokenCount == 3) { + ret = ocmw_handle_testmod_command_function(strTokenArray, + response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 3 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + case ELOOPBK_STR: + case DLOOPBK_STR: + case EPKTGEN_STR: + if (strTokenCount == 3) { + ret = ocmw_handle_ethernet_command_function(strTokenArray, + response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 3 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + case DPKTGEN_STR: + if (strTokenCount == 2) { + ret = ocmw_handle_ethernet_command_function(strTokenArray, + response); + ocmw_free_pointer(strTokenArray); + return (ret != 0) ? FAILED : SUCCESS; + } else { + ret = (strTokenCount < 2 ? + ocmw_frame_errorString(cmdStr, + INSUFFICIENT_PARAM, response) : + ocmw_frame_errorString(cmdStr, + INVALID_SYNTAX, response)); + ocmw_free_pointer(strTokenArray); + return FAILED; + } + break; + default: + break; + } + } else { + if ((snprintf(response, RES_STR_BUFF_SIZE, + "%s : Error : Invalid parameters \n Please refer help menu" + ":\n\" --help or " + ". --help\"", cmdStr)) < 0) { + return FAILED; + } + ocmw_free_pointer(strTokenArray); + return FAILED; + } + } + ocmw_free_pointer(strTokenArray); + return ret; +} diff --git a/firmware/host/ocmw/ocmw_core.c b/firmware/host/ocmw/ocmw_core.c new file mode 100644 index 0000000000..e650c5e5a2 --- /dev/null +++ b/firmware/host/ocmw/ocmw_core.c @@ -0,0 +1,818 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* OC includes */ +#include +#include +#include +#include +#include +#include +#include +#include + +static int32_t loopCountPost = 0; +extern debugI2CData I2CInfo; +extern debugMDIOData MDIOInfo; +extern uint8_t mcuMsgBuf[OCMP_MSG_SIZE]; +extern ocmwSchemaSendBuf *ecSendBufBkp; +int32_t responseCount = 0; +static int8_t s_paramInfoBackup[MAX_PARM_COUNT]; +static int32_t s_semTimeOut; +static int32_t s_totalSubsystem = 0; +extern const Component sys_schema[]; +subSystemInfo systemInfo; + +extern ocwarePostResultData ocwarePostArray[TEMP_STR_BUFF_SIZE]; +extern uint8_t ocwarePostArrayIndex; +ocwarePostReplyCode ocmwReplyCode[] = { + /* Message Type, reply code, Description */ + {OCMP_MSG_TYPE_POST, POST_DEV_NOSTATUS , "POST DEV NOSTATUS"}, + {OCMP_MSG_TYPE_POST, POST_DEV_MISSING, "DEV MISSING"}, + {OCMP_MSG_TYPE_POST, POST_DEV_ID_MISMATCH, "DEV ID MISMATCH"}, + {OCMP_MSG_TYPE_POST, POST_DEV_FOUND, "DEV FOUND"}, + {OCMP_MSG_TYPE_POST, POST_DEV_CFG_DONE, "CFG DONE"}, + {OCMP_MSG_TYPE_POST, POST_DEV_NO_CFG_REQ, "NO CFG REQUIRED"}, + {OCMP_MSG_TYPE_POST, POST_DEV_CFG_FAIL, "CFG FAILED"}, + {OCMP_MSG_TYPE_POST, POST_DEV_FAULTY, "FAULT"}, + {OCMP_MSG_TYPE_POST, POST_DEV_CRITICAL_FAULT, "CRITICAL FAULT"}, + {OCMP_MSG_TYPE_POST, POST_DEV_NO_DRIVER_EXIST, "NO DRIVER EXIST"} +}; +/****************************************************************************** + * Function Name : ocmw_free_global_pointer + * Description : This Function used to free the memory allocated for + * global variable + * Input(s) : ptr + * Output(s) : +******************************************************************************/ +inline void ocmw_free_global_pointer(void **ptr) +{ + if(*ptr != NULL) { + free(*ptr); + *ptr = NULL; + } + return; +} +/****************************************************************************** + * Function Name : ocmw_retrieve_post_results_count + * Description : This Function used to count the post structure size + * Input(s) : postResult + * Output(s) : + ******************************************************************************/ +char ocmw_retrieve_post_results_count (ocwarePostResults *postResult) +{ + postResult->count = + sizeof(ocwarePostArray)/sizeof(ocwarePostArray[0]); + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_retrieve_post_results + * Description : This Function used to get the post results + * Input(s) : postResult + * Output(s) : + ******************************************************************************/ +char ocmw_retrieve_post_results (ocwarePostResults *postResult) +{ + memcpy(postResult->results, ocwarePostArray, + postResult->count * sizeof(ocwarePostResultData)); + memset(ocwarePostArray,0,sizeof(ocwarePostResultData)); + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_retrieve_reply_code_desc + * Description : This Function used to get the reply code based the post + result data + * Input(s) : replyCode + * Output(s) : + ******************************************************************************/ +char ocmw_retrieve_reply_code_desc (ocwarePostReplyCode *replyCode) +{ + int32_t postSize = 0; + int32_t sysIndex = 0; + + postSize = sizeof(ocmwReplyCode)/sizeof(ocmwReplyCode[0]); + + for (sysIndex = 0; sysIndex < postSize; sysIndex++) { + if ((ocmwReplyCode[sysIndex].msgtype == replyCode->msgtype) && + (ocmwReplyCode[sysIndex].replycode == replyCode->replycode)) { + memset(replyCode->desc, 0, OCMW_POST_DESC_SIZE); + strncpy(replyCode->desc, ocmwReplyCode[sysIndex].desc, + strlen(ocmwReplyCode[sysIndex].desc)); + } + } + + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_update_post_status + * Description : This Function used to update the post results + * Input(s) : subsystem, devsn, status + * Output(s) : + ******************************************************************************/ +char ocmw_update_post_status(uint8_t subsystem, uint8_t devsn, + uint8_t status) +{ + int32_t sysIndex = 0; + for (sysIndex = 0; sysIndex < ocwarePostArrayIndex; sysIndex++) { + if ((ocwarePostArray[sysIndex].subsystem == subsystem) && + (ocwarePostArray[sysIndex].devsn == devsn)) { + ocwarePostArray[sysIndex].status = status; + } + } + + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_init + * Description : This Function used to initialize the mware + * Input(s) : + * Output(s) : + ******************************************************************************/ +int32_t ocmw_init() +{ +#ifdef INTERFACE_ETHERNET + pthread_t ethMsgPaserThreadId; +#else + pthread_t uartMsgPaserThreadId; +#endif + int32_t ret = 0; + ret = sem_init(&semecMsgParser, 0, 0); + if (ret != 0) { + logerr("sem_init(): semecMsgParser failed."); + return ret; + } + + ret = ocwdg_init(); + if (ret != 0) { + logerr("ocwdg_init() failed."); + return ret; + } + + ret = sem_init(&semCliReturn, 0, 0); + if (ret != 0) { + logerr("sem_init(): semCliReturn failed."); + return ret; + } + + ret = sem_init(&semCommandPost, 0, 0); + if (ret != 0) { + logerr("sem_init(): semCommandPost failed."); + return ret; + } else { +#ifdef INTERFACE_ETHERNET + /* Create the msg parser thread to parse + * the msg coming from ethernet ec to ap + */ + ret = pthread_create(ðMsgPaserThreadId, NULL, + ocmw_thread_ethmsgparser, NULL); + if (ret != 0) { + return ret; + } +#else + /* Create the msg parser thread to parse + * the msg coming from uart ec to ap + */ + ret = pthread_create(&uartMsgPaserThreadId, NULL, + ocmw_thread_uartmsgparser, NULL); + if (ret != 0) { + logerr("pthread_create() failed."); + } +#endif /* INTERFACE_ETHERNET */ + } + return ret; +} + +/************************************************************************** + * Function Name : ocmw_tokenize_class_str + * Description : This Function used to extract the Subsystem,componentID, Messagetype, + * parameter and Subcomponent from the param string + * Input(s) : str + * Output(s) : msgFrame + ***************************************************************************/ +static int32_t ocmw_tokenize_class_str( const int8_t *str, + strMsgFrame *msgFrame, uint8_t msgtype) +{ + char *token; + int32_t count = 0; + char *tempstr = (char *)malloc(PARAM_STR_MAX_BUFF_SIZE); + + if(str == NULL) + return FAILED; + + memset(tempstr,0,PARAM_STR_MAX_BUFF_SIZE); + memcpy(tempstr, str,PARAM_STR_MAX_BUFF_SIZE); + memset(msgFrame,0,sizeof(strMsgFrame)); + + token = strtok(tempstr, " ."); + + if (token == NULL) + return FAILED; + + if (msgtype == OCMP_MSG_TYPE_COMMAND) { + if ((strcmp(token,"set") != 0) && + ((strcmp(token,"get") != 0))) { + strcpy(msgFrame->parameter, token); + while (token) { + if (count == 1) { + strcpy(msgFrame->subsystem, token); + } else if (count == 2) { + strcpy(msgFrame->component, token); + } + token = strtok(NULL, " ."); + count ++; + if (token == NULL) + break; + } + if (count == 2) { + strcpy(msgFrame->component, "comp_all"); + } + } else { + while (token) { + if (count == 1) { + strcpy(msgFrame->subsystem, token); + } else if (count == 2) { + strcpy(msgFrame->component, token); + } else if (count == 3) { + strcpy(msgFrame->subcomponent, token); + } else if (count == 0) { + strcpy(msgFrame->parameter, token); + } + token = strtok(NULL, " ."); + count ++; + if (token == NULL) + break; + } + if (count == 2) { + strcpy(msgFrame->component, "comp_all"); + } + + } + } else { + strcpy(msgFrame->subsystem, token); + while (token) { + if (count == 1) { + strcpy(msgFrame->component, token); + } else if (count == 2) { + strcpy(msgFrame->msgtype, token); + } else if (count == 3) { + strcpy(msgFrame->subcomponent, token); + } else if(count == 4) { + strcpy(msgFrame->parameter, token); + } + token = strtok(NULL, " ."); + count++; + } + if (count < 5) { + strcpy(msgFrame->parameter, msgFrame->subcomponent); + } + + if (strncmp (msgFrame->component, "post", strlen("post")) == 0) { + strcpy(msgFrame->component, "post"); + strcpy(msgFrame->msgtype, "post"); + strcpy(msgFrame->parameter, msgFrame->subcomponent); + } + } + + free(tempstr); + + return SUCCESS; +} +/****************************************************************************** + * Function Name : ocmw_fill_payload_data_for_commands + * Description : Packetize the msg payload for commands + * Input(s) :strTokenArray, msgFrame, ecMsgFrame, paramVal + * Output(s) : + ******************************************************************************/ +void ocmw_fill_payload_data_for_commands(char * strTokenArray[], + strMsgFrame *msgFrame, OCMPMessageFrame *ecMsgFrame, void* paramVal) +{ + if (msgFrame == NULL) { + return; + } + // Handling sending data for test module + if (strncmp("testmodule", msgFrame->subsystem, + strlen(msgFrame->subsystem)) == 0 ) { + if ((strncmp(strTokenArray[1], "send", strlen("send")) == 0) || + (strncmp(strTokenArray[1], "dial", strlen("dial")) == 0)) { + memcpy(&ecMsgFrame->message.info[0], paramVal, + MAX_PARM_COUNT); + } else { + memset(ecMsgFrame->message.info, 0, MAX_PARM_COUNT); + } + } + // Handling ethernet packet genrator command + if (strncmp("ethernet", msgFrame->subsystem, + strlen(msgFrame->subsystem)) == 0 ) { + if(strstr(strTokenArray[1], "loopBk")) { + memcpy(&ecMsgFrame->message.info[0], paramVal, sizeof(uint8_t)); + } else if ((strncmp(strTokenArray[1], "en_pktGen", + strlen("en_pktGen")) == 0)) { + memcpy(&ecMsgFrame->message.info[0], + (uint16_t *)paramVal, sizeof(uint16_t)); + } + } +} +/****************************************************************************** + * Function Name : ocmw_msg_packetize_and_send + * Description : Packetize the msg frame before sending data to ec + * Input(s) :actionType, msgType, paramStr, interface, paramVal + * Output(s) : + ******************************************************************************/ +int32_t ocmw_msg_packetize_and_send(char * strTokenArray[], uint8_t action, + uint8_t msgType, const int8_t * paramStr, uint8_t interface, void* paramVal) +{ + int32_t ret = 0; + int32_t paramValue = 0; + int32_t dataSize = 0; + int32_t pos = 0; + int32_t paramValLen = 0; + int32_t paramValFlag = 0; + const int8_t *tempStr = paramStr; + strMsgFrame msgFramestruct; + OCMPMessageFrame ecMsgFrame; + OCMPHeader ecMsgHeader; + OCMPMessage ecCoreMsg; + + static int32_t loopCountSend = 0; + ocmwSchemaSendBuf ecSendBuf; + + paramValLen = strlen((char *)paramVal); + if (!((msgType == OCMP_MSG_TYPE_COMMAND) && + ((strncmp(strTokenArray[1], "get", strlen("get")) == 0) || + (strncmp(strTokenArray[1], "set", strlen("get")) == 0)))) { + if (paramValLen == 1 || paramValLen <= 5) { + logdebug ("Paramvalue is of integer type : %d\n", atoi( paramVal)); + } + else { + paramValFlag = 1; + logdebug ("Paramvalue is of string type : %s \n", (char *)paramVal); + } + } else { + paramValFlag = 1; + logdebug ("Paramvalue is of string type : %s \n", (char *)paramVal); + } + + if (paramStr == NULL) { + logdebug(" Paramstr is NULL \n"); + return ret = FAILED; + } else { + + ocmw_tokenize_class_str(tempStr,&msgFramestruct,msgType); + if (msgType == OCMP_MSG_TYPE_COMMAND) { + ret = ocmw_parse_command_msgframe(sys_schema, &msgFramestruct, + action, &ecSendBuf); + } else if (msgType == OCMP_MSG_TYPE_POST) { + strcpy((char*)s_paramInfoBackup,msgFramestruct.parameter); + ret = ocmw_parse_post_msgframe(sys_schema, &msgFramestruct, + action, &ecSendBuf); + } else { + ret = ocmw_parse_msgframe(sys_schema, &msgFramestruct, action, + &ecSendBuf); + } + if (ret < 0) { + return ret; + } + } + + /* Frame the header packet for sending data to ec */ + ecMsgHeader.ocmpFrameLen = 0; + ecMsgHeader.ocmpInterface = interface; + ecMsgHeader.ocmpSeqNumber = 0; + ecMsgHeader.ocmpSof = OCMP_MSG_SOF; + ecMsgHeader.ocmpTimestamp = 0; + + /* Frame the Core packet for sending data to ec */ + ecCoreMsg.action = ecSendBuf.actionType; + ecCoreMsg.msgtype = ecSendBuf.msgType; + ecCoreMsg.componentID = ecSendBuf.componentId; + ecCoreMsg.parameters = ecSendBuf.paramId; + ecCoreMsg.subsystem = ecSendBuf.subsystem; + + /* Construct the final packet */ + ecMsgFrame.header = ecMsgHeader; + ecMsgFrame.message = ecCoreMsg; + + /* Populate the Core packet payload */ + ecMsgFrame.message.info = (int8_t *) malloc( + sizeof(int8_t) * MAX_PARM_COUNT); + if (ecMsgFrame.message.info == NULL) { + logdebug("\n Memory allocation failed \n"); + return ret = FAILED; + } + memset(ecMsgFrame.message.info, 0, MAX_PARM_COUNT); + if ((msgType == OCMP_MSG_TYPE_POST) && + (strncmp(strTokenArray[1], "set", strlen("set"))== 0)) { + logdebug("OCMP_MSG_TYPE_POST:ENABLE:%s()\n", __func__); + } + if(strncmp(msgFramestruct.subsystem,"debug",strlen("debug")) == 0) { + if (strncmp(msgFramestruct.component,"I2C", + strlen("I2C")) == 0) { + if((strncmp(strTokenArray[1], "get", strlen("get")) == 0)) { + dataSize = 3 * sizeof (int8_t); + } else { + dataSize = sizeof(debugI2CData); + } + } else if (strncmp(msgFramestruct.component,"ethernet", + strlen("ethernet")) == 0) { + if((strncmp(strTokenArray[1], "get", strlen("get")) == 0)) { + dataSize = sizeof (uint16_t); + } else { + dataSize = sizeof(debugMDIOData); + } + } else { + if((strncmp(strTokenArray[1], "get", strlen("get")) == 0)) { + dataSize = sizeof (int8_t); + } else { + dataSize = sizeof(debugGPIOData); + } + } + paramValLen = dataSize; + } else { + dataSize = ecSendBuf.paramSize; + } + if((strncmp(strTokenArray[1], "set", strlen("set")) == 0) && + (msgType != OCMP_MSG_TYPE_POST)) { + pos = ecSendBuf.paramPos; + if (paramValFlag == 0) { + paramValue = atoi( paramVal); + memcpy(&ecMsgFrame.message.info[pos], ¶mValue, dataSize); + } else { + if (strncmp(msgFramestruct.component,"I2C", + strlen("I2C")) == 0) { + ecMsgFrame.message.info[pos] = I2CInfo.slaveAddress; + ecMsgFrame.message.info[pos + 1] = + I2CInfo.numOfBytes; + ecMsgFrame.message.info[pos + 2] = + I2CInfo.regAddress; + if (I2CInfo.numOfBytes == 1) { + ecMsgFrame.message.info[pos + 3] = + (uint8_t)I2CInfo.regValue; + } else { + ecMsgFrame.message.info[pos + 4] = + (uint8_t)(I2CInfo.regValue & 0xff); + ecMsgFrame.message.info[pos + 3] = + (uint8_t) + ((I2CInfo.regValue & 0xff00) >> 8); + } + } else if (strncmp(msgFramestruct.component,"ethernet", + strlen("ethernet")) == 0) { + ecMsgFrame.message.info[pos] = (uint8_t) + (MDIOInfo.regAddress & 0xff); + ecMsgFrame.message.info[pos + 1] = (uint8_t) + ((MDIOInfo.regAddress & 0xff00) >> 8); + ecMsgFrame.message.info[pos + 2] = + (uint8_t)(MDIOInfo.regValue & 0xff); + ecMsgFrame.message.info[pos + 3] = + (uint8_t) + ((MDIOInfo.regValue & 0xff00) >> 8); + + } else { + memcpy(&ecMsgFrame.message.info[pos], (char *) paramVal, + paramValLen); + } + } + } + if((strncmp(strTokenArray[1], "get", strlen("get")) == 0) && + (ecMsgFrame.message.subsystem == DEBUG_SUBSYSTEM_NBR)) { + pos = ecSendBuf.paramPos; + memcpy(&ecMsgFrame.message.info[pos], (char *) paramVal, + paramValLen); + + } + //Fill payload data for commands + ocmw_fill_payload_data_for_commands(&strTokenArray[0], &msgFramestruct, + &ecMsgFrame, paramVal); + + if (!((msgType == OCMP_MSG_TYPE_POST) && + (strncmp(strTokenArray[1], "get", strlen("get")) == 0))) { + ocmw_send_msg(ecMsgFrame, interface); + } + + /* Wait on the POST msgtype semaphore */ + if ((msgType == OCMP_MSG_TYPE_POST) && + ((strncmp(strTokenArray[1], "get", strlen("get")) == 0))) { + ocmw_frame_subsystem_from_schema(sys_schema, &systemInfo); + s_totalSubsystem = systemInfo.totalNum; + ocmw_frame_postTable_from_schema(sys_schema); + loopCountSend = systemInfo.Info[0].number; + loopCountPost = systemInfo.Info[0].number; + + while(loopCountSend < s_totalSubsystem) { + memset(&(ecMsgFrame.message.info[0]), + loopCountSend, 1); + /* Send the message to ec */ + ocmw_send_msg(ecMsgFrame, interface); + loopCountSend++; + + /* Waiting on the lock to be released by receiving thread */ + ret = ocmw_sem_wait(&semCommandPost, OCMW_TIMED_WAIT_INDEX); + if (ret != 0) { + perror("sem_wait"); + } + + /* + * Logic to check if firmware has sent post data currently we + * expect only actiontype mismatch other errors can be taken care + * as required + */ + if (loopCountSend != loopCountPost) { + logerr("POST: Error : Actiontype mismatch in message from FW"); + free(ecMsgFrame.message.info); + return FAILED; + } + } + loopCountPost = systemInfo.Info[0].number; + loopCountSend = systemInfo.Info[0].number; + } + + free(ecMsgFrame.message.info); + + /* Semaphore wait function call */ + ret = ocmw_sem_wait(&semCliReturn, OCMW_TIMED_WAIT_INDEX); + if (ret == FAILED) { + logdebug("Message is not received from EC: releasing the lock \n"); + return ret; + } + + if (responseCount == 0) { + ret = FAILED; + } else { + ret = 0; + responseCount = 0; + } + logdebug(" \n Semaphore released : %s() \n", __func__); + + return ret; +} + +/****************************************************************************** + * Function Name : ocmw_thread_uartmsgparser + * Description : Thread to parse the data coming from EC to AP + * through uart communication + * Input(s) : pthreadData + * Output(s) : + ******************************************************************************/ +void * ocmw_thread_uartmsgparser(void *pthreadData) +{ + logdebug("Uart task created \n"); + while (1) { + /* Waiting on the semecMsgParser to be released by uart */ + sem_wait(&semecMsgParser); + ocmw_ec_msgparser(); + } +} + +/****************************************************************************** + * Function Name : ocmw_thread_ethmsgparser + * Description : Thread to parse the data coming from EC to AP + * through ethernet communication + * Input(s) : pthreadData + * Output(s) : + ******************************************************************************/ +void * ocmw_thread_ethmsgparser(void *pthreadData) +{ + int8_t ethRecvBuf[OCMP_MSG_SIZE] = {0}; + + logdebug("Ethernet task created \n"); + while (1) { + memset(ethRecvBuf, 0, sizeof(ethRecvBuf)); + ocmw_recv_eth_msgfrom_ec(ethRecvBuf, sizeof(ethRecvBuf),OCMW_EC_DEV); + ocmw_ec_msgparser(); + } +} + +/****************************************************************************** + * Function Name : ocmw_ec_msgparser + * Description : parse the data coming from EC to AP + * Input(s) : + * Output(s) : + ******************************************************************************/ +void ocmw_ec_msgparser(void) +{ + uint8_t msgType = 0; + uint8_t actionType = 0; + uint8_t subsystemPost = 0; + uint8_t devsn = 0; + uint8_t status = 0; + uint8_t indexCount = 0; + uint16_t paramInfo = 0; + int32_t ret = 0; + int32_t sendPktNonpayloadSize = 0; + sMsgParam dmsgFrameParam; + OCMPMessageFrame ecReceivedMsg; + + sendPktNonpayloadSize = (sizeof(OCMPMessage) - sizeof(void *) + + sizeof(OCMPHeader)); + + ecReceivedMsg.message.info = (void *) malloc( + sizeof(char) * MAX_PARM_COUNT); + if (ecReceivedMsg.message.info == NULL) { + logerr("Memory allocation failed for " + "ecReceivedMsg.message.info \n"); + + return; + } + + /* parse the data packet */ + memcpy((void *) &ecReceivedMsg, (void *) mcuMsgBuf, sendPktNonpayloadSize); + memcpy(ecReceivedMsg.message.info, &mcuMsgBuf[sendPktNonpayloadSize], + MAX_PARM_COUNT); + + msgType = ecReceivedMsg.message.msgtype; + actionType = ecReceivedMsg.message.action; + paramInfo = ecReceivedMsg.message.parameters; + + /* + * TODO:Temporary fix for handling alerts + */ + if (msgType == OCMP_MSG_TYPE_ALERT) { + free(ecReceivedMsg.message.info); + return; + } + + printf("Received from ec :\n"); + for (indexCount = 0; indexCount < OCMP_MSG_SIZE; indexCount++) { + printf("0x%x ", mcuMsgBuf[indexCount]); + } + printf("\n"); + + /* In case of timeout, return from the thread + * without processing the data to avoid sync issue. + */ + if (s_semTimeOut) { + s_semTimeOut = 0; + ocmw_free_global_pointer((void**)&ecSendBufBkp); + return; + } + + if ((msgType == OCMP_MSG_TYPE_POST) && + strcmp((char*)s_paramInfoBackup,"set") == 0) { + if (actionType == OCMP_AXN_TYPE_REPLY) { + responseCount++; + } + /* Release the lock on which cli is waiting */ + ocmw_free_global_pointer((void**)&ecSendBufBkp); + sem_post(&semCliReturn); + return; + } + + /* Release the lock on the POST msgtype semaphore */ + if (msgType == OCMP_MSG_TYPE_POST) { + if (actionType != OCMP_AXN_TYPE_REPLY) { + ocmw_free_global_pointer((void**)&ecSendBufBkp); + ret = sem_post(&semCommandPost); + if (ret != 0) { + perror("sem_wait"); + } + return; + } + + for (; loopCountPost < s_totalSubsystem;) { + /* Waiting on the lock to be released by receiving thread */ + for (indexCount = 0; indexCount < paramInfo; indexCount++) { + subsystemPost = ecReceivedMsg.message.info[indexCount + * POST_MAIN_PAYLOAD_SIZE + + POST_MAIN_PAYLOAD_SUBSYSTEM_OFFSET]; + devsn = ecReceivedMsg.message.info[indexCount + * POST_MAIN_PAYLOAD_SIZE + + POST_MAIN_PAYLOAD_DEVSN_OFFSET]; + status = ecReceivedMsg.message.info[indexCount + * POST_MAIN_PAYLOAD_SIZE + + POST_MAIN_PAYLOAD_STATUS_OFFSET]; + ret = ocmw_update_post_status(subsystemPost, devsn, status); + } + + loopCountPost++; + + ret = sem_post(&semCommandPost); + if (ret != 0) { + perror("sem_wait"); + } + if (loopCountPost < s_totalSubsystem) { + /* Do Nothing */ + } else { + /* Release the lock on which watchdog thread is waiting */ + responseCount++; + ocmw_free_global_pointer((void**)&ecSendBufBkp); + sem_post(&semCliReturn); + } + return; + } + } + + memset(&dmsgFrameParam, 0, sizeof(sMsgParam)); + ocmw_deserialization_msgframe(sys_schema, &dmsgFrameParam, &ecReceivedMsg); + /* Released the lock so that cli is released from the lock */ + if (ecReceivedMsg.message.info) { + free(ecReceivedMsg.message.info); + } + sem_post(&semCliReturn); +} + +/****************************************************************************** + * Function Name : ocmw_send_msg + * Description : Send the message from ap to ec via uart/usb/ethernet. + * Input(s) : ecMsgFrame, interface + * Output(s) : + ******************************************************************************/ +int32_t ocmw_send_msg(OCMPMessageFrame ecMsgFrame, uint8_t interface) +{ + int32_t ret = 0; + int32_t sentDev = OCMW_EC_DEV; +#ifdef INTERFACE_STUB_EC + int8_t ethRecvBuf[OCMP_MSG_SIZE]; +#endif + switch (interface) { + case OCMP_COMM_IFACE_UART: + case OCMP_COMM_IFACE_USB: + /* Send the packetize data to ec through uart*/ + ret = ocmw_send_uart_msg_to_ec((uint8_t *) &ecMsgFrame, + OCMP_MSG_SIZE); + break; + + case OCMP_COMM_IFACE_ETHERNET: + sentDev = OCMW_EC_DEV; +#ifdef INTERFACE_STUB_EC + sentDev = OCMW_EC_STUB_DEV; +#else + sentDev = OCMW_EC_DEV; +#endif + /* Send the packetize data to ec through ethernet*/ + ret = ocmw_send_eth_msgto_ec((int8_t *) &ecMsgFrame, + OCMP_MSG_SIZE, sentDev); +#ifdef INTERFACE_STUB_EC + memset(ethRecvBuf, 0, sizeof(ethRecvBuf)); + ocmw_recv_eth_msgfrom_ec(ethRecvBuf, sizeof(ethRecvBuf), OCMW_EC_STUB_DEV); + ocmw_ec_msgparser(); +#endif + break; + + case OCMP_COMM_IFACE_SBD: + break; + default: + break; + } + + if (ret != 0) { + logerr("ocmw_send_msg() failed \n"); + } + return ret; +} + +/****************************************************************************** + * Function Name : ocmw_sem_wait + * Description : semaphore wait function to wait either for infinite time + * or for timeout period. + * Input(s) : semId, semWaitType + * Output(s) : + ******************************************************************************/ +int32_t ocmw_sem_wait(sem_t *semId, int32_t semWaitType) +{ + int32_t ret = 0; + struct timespec timeSpecObj; + + if (semId == NULL) { + logerr("Invalid semId \n"); + ret = FAILED; + return ret; + } + + if (semWaitType == OCMW_BUSY_WAIT_INDEX) { + /* Waiting on the lock to be released by receiving thread */ + ret = ocmw_sem_wait_nointr(semId); + if (ret != 0) { + perror("sem_wait"); + } + } else if (semWaitType == OCMW_TIMED_WAIT_INDEX) { + ret = clock_gettime(CLOCK_REALTIME, &timeSpecObj); + if (ret != 0) { + perror("clock_gettime"); + } + timeSpecObj.tv_sec += OCMW_SEM_WAIT_TIME; + timeSpecObj.tv_nsec += 0; + + ret = ocmw_sem_timedwait_nointr(semId, &timeSpecObj); + if (ret != 0) { + if (errno == ETIMEDOUT) { + logdebug("sem_timedwait() timed out\n"); + } else { + perror("sem_timedwait"); + } + logdebug("Message is not received from EC: releasing the lock \n"); + s_semTimeOut = 1; + } + } else { + printf("Invalid param \n"); + } + return ret; +} diff --git a/firmware/host/ocmw/ocmw_eth_comm.c b/firmware/host/ocmw/ocmw_eth_comm.c new file mode 100644 index 0000000000..2dd8e75286 --- /dev/null +++ b/firmware/host/ocmw/ocmw_eth_comm.c @@ -0,0 +1,236 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* stdlib includes */ +#include +#include + +/* OC includes */ +#include +#include +#include +#include + +#define OCMW_ERR_STR_LEN 80 +#define OCWARE_STUB_TIMEOUT_PERIOD 12 + +extern uint8_t mcuMsgBuf[OCMP_MSG_SIZE]; + +static int32_t comSockfd = 0, stub_sockfd = 0; +static struct sockaddr_in sicomServer, stub_server; + +/************************************************************************** + * Function Name : ocmw_init_eth_comm + * Description : This Function used to initialize the ethernet + * communication + * Input(s) : + * Output(s) : + ***************************************************************************/ +int32_t ocmw_init_eth_comm(int32_t sentDev) +{ + int32_t rc = 0; + int32_t inetAton = 0; + printf("Ethernet init start \n"); + struct timeval timeValObj; + timeValObj.tv_sec = OCWARE_STUB_TIMEOUT_PERIOD; + timeValObj.tv_usec = 0; + if (sentDev == OCMW_EC_DEV){ + /* Create socket */ + comSockfd = socket(OCMW_ETH_SOCK_DOMAIN, OCMW_ETH_SOCK_TYPE, + OCMW_ETH_SOCK_PROTOCOL); + if (comSockfd < 0) { + rc = -errno; + logerr("socket creation error [%d-%s]", errno, strerror(errno)); + } + + /* Initialize socket structure */ + memset(&sicomServer, 0, sizeof(sicomServer)); + sicomServer.sin_family = OCMW_ETH_SOCK_DOMAIN; + sicomServer.sin_port = htons(OCMW_ETH_SOCK_SERVER_PORT); + inetAton = inet_aton(OCMW_ETH_SOCK_SERVER_IP, &sicomServer.sin_addr); + if (inetAton == 0) { + printf("inet_aton failed"); + rc = -1; + } + + rc = connect(comSockfd, (struct sockaddr *) &sicomServer, + sizeof(sicomServer)); + if (rc != 0) { + perror("socket connect failed:"); + } + + if (rc != 0) { + ocmw_deinit_eth_comm(OCMW_EC_DEV); + } else { + printf("Ehernet init finished \n"); + } + } else { + /* Create socket */ + stub_sockfd = socket(OCMW_SOCK_STUB_DOMAIN, OCMW_SOCK_STUB_TYPE, + OCMW_SOCK_STUB_PROTOCOL); + if (stub_sockfd < 0) { + rc = -errno; + logerr("socket creation error [%d-%s]", errno, strerror(errno)); + } + + /* Initialize socket structure */ + memset(&stub_server, 0, sizeof(stub_server)); + stub_server.sin_family = OCMW_SOCK_STUB_DOMAIN; + stub_server.sin_port = htons(OCMW_SOCK_STUB_SERVER_PORT); + stub_server.sin_addr.s_addr = inet_addr(OCMW_SOCK_SERVER_IP); + inetAton = inet_aton(OCMW_SOCK_STUB_SERVER_IP, &stub_server.sin_addr); + if (inetAton == 0) { + printf("inet_aton failed"); + rc = -1; + } + + if (setsockopt(stub_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeValObj, + sizeof(timeValObj)) < 0) { + logerr("setsockopt failed"); + rc = -1; + return rc; + } + + if (rc != 0) { + ocmw_deinit_eth_comm(OCMW_EC_STUB_DEV); + } else { + printf("Ehernet init finished \n"); + } + } + return rc; +} + +/************************************************************************** + * Function Name : ocmw_deinit_eth_comm + * Description : This Function used to uninitialize the ethernet + * communication + * Input(s) : + * Output(s) : + ***************************************************************************/ +int32_t ocmw_deinit_eth_comm( int sentDev) +{ + if (sentDev == OCMW_EC_DEV){ + close(comSockfd); + comSockfd = 0; /* Close the IPC socket */ + } else { + close(stub_sockfd); + stub_sockfd = 0; /* Close the IPC socket */ + } + return 0; +} + +/************************************************************************** + * Function Name : ocmw_send_eth_msgto_ec + * Description : This Function used to send the message to ec + * Input(s) : cmd, cmdlen + * Output(s) : + ***************************************************************************/ +int32_t ocmw_send_eth_msgto_ec(const int8_t *cmd, int32_t cmdlen, int sentDev) +{ + const int32_t errstrLen = OCMW_ERR_STR_LEN; + char errstr[errstrLen]; + uint8_t buf[OCMP_MSG_SIZE]; + int32_t rc = 0; + int32_t loopCount = 0; + int32_t sendPktNonpayloadSize = 0; + OCMPMessageFrame *ecMsgFrame; + + if (cmd == NULL) { + logerr("Error: Memory allocation problem"); + return -1; + } + if (cmdlen > OCMP_MSG_SIZE) { + logerr("Error: msgstr size is more than %d bytes", OCMP_MSG_SIZE); + return -EMSGSIZE; + } + + ecMsgFrame = (OCMPMessageFrame *) cmd; + sendPktNonpayloadSize = (sizeof(OCMPMessage) - sizeof(void *) + + sizeof(OCMPHeader)); + + /* create message frame */ + memset(buf, 0, sizeof(buf)); + memcpy(buf, ecMsgFrame, sendPktNonpayloadSize); + memcpy(&buf[sendPktNonpayloadSize], ((ecMsgFrame->message).info), + MAX_PARM_COUNT); +#ifndef MSG_LOG + printf(" \n send_msg_to_ec \n"); + for (loopCount = 0; loopCount < OCMP_MSG_SIZE; loopCount++) { + printf("0x%x ", buf[loopCount] & 0x00ff); + } + printf("\n"); +#endif /* MSG_LOG */ + + if (sentDev == OCMW_EC_DEV){ + rc = send(comSockfd, buf, OCMP_MSG_SIZE, 0); + if (rc < 0) { + strerror_r(errno, errstr, errstrLen); + logerr("Error: 'send' [%d-%s]", errno, errstr); + } + } else { + rc = sendto(stub_sockfd, buf, OCMP_MSG_SIZE, 0, + (struct sockaddr *) &stub_server, sizeof(stub_server) ); + if (rc < 0) { + strerror_r(errno, errstr, errstrLen); + logerr("Error: 'send' [%d-%s]", errno, errstr); + } + } + return rc; +} + +/************************************************************************** + * Function Name : ocmw_recv_eth_msgfrom_ec + * Description : This Function used to receive the ec message + * Input(s) : + * Output(s) : resp, resplen + ***************************************************************************/ +int32_t ocmw_recv_eth_msgfrom_ec(int8_t *resp, int32_t resplen, int sentDev) +{ +#if defined(INTERFACE_STUB_EC) || defined(INTERFACE_ETHERNET) + const int32_t errstrLen = OCMW_ERR_STR_LEN; + char errstr[errstrLen]; +#endif + int32_t rc = 0; + int32_t loopCount = 0; +#ifdef INTERFACE_STUB_EC + int32_t dataLen = sizeof(stub_server); +#endif + + /* + * Receive the CLI command execution response string from OCMW over + * UDP socket + */ +#ifdef INTERFACE_ETHERNET + rc = recv(comSockfd, resp, resplen, 0); + if (rc < 0) { + strerror_r(rc, errstr, errstrLen); + logerr("Error: 'recv' [%d-%s]", rc, errstr); + } +#endif +#ifdef INTERFACE_STUB_EC + rc = recvfrom(stub_sockfd, resp, OCMP_MSG_SIZE, 0, + (struct sockaddr *) &stub_server, + (socklen_t*)&dataLen); + if (rc < 0) { + strerror_r(rc, errstr, errstrLen); + logerr("Error: 'recv' [%d-%s]", rc, errstr); + printf("\n Error: Recv from in OCWARE_STUB"); + } +#endif + + /* Store the ethernet msg into global buffer */ + memcpy(mcuMsgBuf, resp, resplen); + + printf("Message received from ec via ethernet :\n"); + for (loopCount = 0; loopCount < resplen; loopCount++) { + printf("0x%x ", (0xff) & resp[loopCount]); + } + printf("\n"); + return rc; +} diff --git a/firmware/host/ocmw/ocmw_helper.c b/firmware/host/ocmw/ocmw_helper.c new file mode 100644 index 0000000000..e37429b477 --- /dev/null +++ b/firmware/host/ocmw/ocmw_helper.c @@ -0,0 +1,156 @@ +/** + + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* OC includes */ +#include +#include +#include +#include +#include +#include + +#define SIZE_INT sizeof (int32_t) + +int8_t eepromStatusFlag = 0; + +/****************************************************************************** + * Function Name : ocmw_sem_wait_nointr + * Description : static inline function for avoiding interruption caused + * to sem_wait() library call + * Input(s) : sem + * Output(s) : + ******************************************************************************/ +inline int32_t ocmw_sem_wait_nointr(sem_t *sem) +{ + while (sem_wait(sem)) + if (errno == EINTR) + errno = 0; + else + return -1; + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_sem_timedwait_nointr + * Description : static inline function for avoiding interruption caused + * to sem_timedwait() library call + * Input(s) : sem, timeout + * Output(s) : + ******************************************************************************/ +inline int32_t ocmw_sem_timedwait_nointr(sem_t *sem, + const struct timespec *timeout) +{ + while (sem_timedwait(sem, timeout)) + if (errno == EINTR) + errno = 0; + else + return -1; + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_dataparsing_from_db + * Description : This Function used to parase the data from db + * Input(s) : paramIndex, paramSizebuf + * Output(s) : dataSize, pos + ******************************************************************************/ +void ocmw_dataparsing_from_db(int32_t paramIndex, int32_t *paramSizebuf, + int32_t *dataSize, int32_t *pos) +{ + int32_t count; + int32_t paramIdPresence; + int32_t loc; + + count = 0; + paramIdPresence = 0; + loc = 0; + + if ((paramSizebuf == NULL) || (dataSize == NULL) || (pos == NULL)) { + return; + } + + *dataSize = 0; + *pos = 0; + + for (count = 0; count < MAX_PARM_COUNT; count++) { + paramIdPresence = (paramIndex) / ((int) pow(2, count)); + if (paramIdPresence == 1) { + break; + } + + else { + loc = loc + paramSizebuf[count]; + } + } + + *dataSize = paramSizebuf[count]; + *pos = loc; +} + +/****************************************************************************** + * Function Name : ocmw_dataparsing_from_ec + * Description : This Function used to parse the uart message from ec + * Input(s) : input, bufParamStruct + * Output(s) : + ******************************************************************************/ +void ocmw_dataparsing_from_ec(ocmwSendRecvBuf *input, + bufParam * bufParamStruct) +{ + int32_t count = 0; + int32_t paramIdPresence = 0; + int32_t pos = 0; + int32_t paramidSize = 0; + int32_t index = 0; + + if ((input == NULL) || (bufParamStruct == NULL)) { + printf("Memory address is invalid : %s()\n", __func__); + return; + } + + int16_t paramInfo = input->paramInfo; + int32_t numOfele = input->numOfele; + int8_t *pbuf = input->pbuf; + int32_t *paramSizebuf = input->paramSizebuf; + + for (count = 0; count < numOfele; count++) { + bufParamStruct[count].paramindex = (paramInfo & ((int32_t) pow(2, + count + index))); + + paramIdPresence = bufParamStruct[count].paramindex / pow(2, + count + index); + + if (paramIdPresence == 0) { + paramidSize = 0; + } else { + paramidSize = paramSizebuf[count]; + } + + switch (paramidSize) { + case VOID: + bufParamStruct[count].paramval = 0; + break; + case CHAR: + bufParamStruct[count].paramval = *((int8_t *) &pbuf[pos]); + break; + + case SHORT: + bufParamStruct[count].paramval = *((int16_t *) &pbuf[pos]); + break; + + case INT: + bufParamStruct[count].paramval = *((int32_t *) &pbuf[pos]); + break; + + default: + return; + break; + } + } +} diff --git a/firmware/host/ocmw/ocmw_main.c b/firmware/host/ocmw/ocmw_main.c new file mode 100644 index 0000000000..09b2eb5778 --- /dev/null +++ b/firmware/host/ocmw/ocmw_main.c @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* stdlib includes */ +#include +#include +#include +#include +#include +#include + +/* OC includes */ +#include +#include +#include +#include +#include + +uint8_t mcuMsgBuf[OCMP_MSG_SIZE]; + +/************************************************************************** + * Function Name : main + * Description : + * Input(s) : argc, argv + * Output(s) : + ***************************************************************************/ +int32_t main(int32_t argc, char **argv) +{ + char cmdstr[CMD_STR_BUFF_SIZE] = {0}; + char response[RES_STR_BUFF_SIZE] = {0}; + int32_t ret = 0; + + /* Initialize logging */ + initlog("ocmw"); + + ret = ocmw_init_occli_comm(); + if (ret != 0) { + logerr("init_occli_comm() failed."); + return FAILED; + } + + /* Initialize UART for EC communication */ + ret = ocmw_init_ec_comm(&ocmw_ec_uart_msg_hndlr); + if (ret != 0) { + logerr("ocmw_init_ec_comm() failed."); + return FAILED; + } + +#ifdef INTERFACE_ETHERNET + ret = ocmw_init_eth_comm(OCMW_EC_DEV); + if(ret != 0) { + printf ("ocmw_init_eth_comm() failed \n"); + return FAILED; + } +#endif /* INTERFACE_ETHERNET */ + +#ifdef INTERFACE_STUB_EC + ret = ocmw_init_eth_comm(OCMW_EC_STUB_DEV); + if(ret != 0) { + printf ("init_eth_comm() failed \n"); + return FAILED; + } +#endif /* INTERFACE_ETHERNET */ + + ret = ocmw_init(); + if (ret != 0) { + logerr("ocmw_init() failed."); + return FAILED; + } + + while (1) { + memset(cmdstr, 0, sizeof(cmdstr)); + memset(response, 0, sizeof(response)); + + ret = ocmw_recv_clicmd_from_occli(cmdstr, sizeof(cmdstr)); + if (ret == FAILED) + continue; /* retry on error */ + + ocmw_clicmd_handler(cmdstr, response); + ocmw_send_clicmd_resp_to_occli(response, strlen(response)); + } + + ocmw_deinit_occli_comm(); + ocmw_deinit_occli_alert_comm(); + ocmw_deinit_ec_comm(); + deinitlog(); + return SUCCESS; +} diff --git a/firmware/host/ocmw/ocmw_msgproc.c b/firmware/host/ocmw/ocmw_msgproc.c new file mode 100755 index 0000000000..69980f8b2a --- /dev/null +++ b/firmware/host/ocmw/ocmw_msgproc.c @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#include +#include +#include + +#include +#include "ocmw_core.h" +#include "ocmw_msgproc.h" +#include "ocmp_frame.h" + +/************************************************************************** + * Function Name : ocmw_msgproc_send_msg + * Description : This Function configures the header + * Input(s) : strTokenArray, action, msgtype, paramstr + * Output(s) : paramvalue + ***************************************************************************/ +int ocmw_msgproc_send_msg(char * strTokenArray[], uint8_t action, + int8_t msgtype, const int8_t* paramstr, void *paramvalue) +{ + int32_t ret = 0; + uint8_t interface = 0; +#if defined(INTERFACE_STUB_EC) || defined(INTERFACE_ETHERNET) + interface = OCMP_COMM_IFACE_ETHERNET; +#elif INTERFACE_USB + interface = OCMP_COMM_IFACE_USB; +#else + interface = OCMP_COMM_IFACE_UART; +#endif /* INTERFACE_ETHERNET */ + ret = ocmw_msg_packetize_and_send(&strTokenArray[0], action, msgtype, + paramstr, interface, paramvalue); + if (ret != 0) { + logerr("ocmw_msg_packetize_and_send failed \n"); + } + return ret; +} + diff --git a/firmware/host/ocmw/ocmw_occli_comm.c b/firmware/host/ocmw/ocmw_occli_comm.c new file mode 100644 index 0000000000..c2f943b4e9 --- /dev/null +++ b/firmware/host/ocmw/ocmw_occli_comm.c @@ -0,0 +1,185 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* stdlib includes */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* OC includes */ +#include +#include +#include + +static int32_t s_ssockFd = 0; +static struct sockaddr_in s_siServer, s_siClient; + +static int32_t s_ssockfdAlert = 0; +static struct sockaddr_in s_siServerAlert; + +/************************************************************************** + * Function Name : ocmw_init_occli_comm + * Description : This Function used to initialize the cli communication + * Input(s) : + * Output(s) : + ***************************************************************************/ +int32_t ocmw_init_occli_comm() +{ + int32_t ret = 0; + + /* Create socket */ + s_ssockFd = socket(OCMW_SOCK_DOMAIN, OCMW_SOCK_TYPE, OCMW_SOCK_PROTOCOL); + if (s_ssockFd < 0) { + ret = -errno; + logerr("socket creation error [%d-%s]", errno, strerror(errno)); + return ret; + } + + /* Initialize socket structure */ + memset(&s_siServer, 0, sizeof(s_siServer)); + s_siServer.sin_family = OCMW_SOCK_DOMAIN; + s_siServer.sin_addr.s_addr = INADDR_ANY; + s_siServer.sin_port = htons(OCMW_SOCK_SERVER_PORT); + + /* Bind host address to the socket */ + ret = bind(s_ssockFd, (struct sockaddr*) &s_siServer, sizeof(s_siServer)); + if (ret < 0) { + ret = -errno; + logerr("bind error [%d-%s]", errno, strerror(errno)); + return ret; + } + + if (ret != 0) { + ocmw_deinit_occli_comm(); + return ret; + } + + /***** Alert related socket init *****/ + /* Create socket */ + s_ssockfdAlert = socket(OCMW_SOCK_DOMAIN, OCMW_SOCK_TYPE, + OCMW_SOCK_PROTOCOL); + if (s_ssockfdAlert < 0) { + ret = -errno; + logerr("socket creation error [%d-%s]", errno, strerror(errno)); + return ret; + } + + if (ret != 0) { + ocmw_deinit_occli_alert_comm(); + } else { + /* Initialize socket structure */ + memset(&s_siServerAlert, 0, sizeof(s_siServerAlert)); + s_siServerAlert.sin_family = OCMW_SOCK_DOMAIN; + s_siServerAlert.sin_addr.s_addr = INADDR_ANY; + s_siServerAlert.sin_port = htons(OCMW_SOCK_SERVER_ALERT_PORT); + } + return ret; +} + +/************************************************************************** + * Function Name : ocmw_deinit_occli_comm + * Description : This Function used to deinitialize the cli communication + * Input(s) : + * Output(s) : + ***************************************************************************/ +int32_t ocmw_deinit_occli_comm(void) +{ + close(s_ssockFd); + s_ssockFd = 0; /* Close the IPC socket */ + return SUCCESS; +} + +/************************************************************************** + * Function Name : ocmw_deinit_occli_alert_comm + * Description : This Function used deinitialize the alert communication + * Input(s) : + * Output(s) : + ***************************************************************************/ +int32_t ocmw_deinit_occli_alert_comm(void) +{ + close(s_ssockfdAlert); + s_ssockfdAlert = 0; /* Close the IPC socket */ + return SUCCESS; +} + +/************************************************************************** + * Function Name : ocmw_send_clicmd_resp_to_occli + * Description : This Function used to send command response to cli + * Input(s) : buf, buflen + * Output(s) : + ***************************************************************************/ +int32_t ocmw_send_clicmd_resp_to_occli(const char* buf, int32_t buflen) +{ + char errstr[OCMW_SOCKET_ERROR_SIZE]; + int32_t ret = 0; + int32_t destLen = sizeof(s_siClient); + + /* Send the message buffer over IPC */ + ret = sendto(s_ssockFd, buf, buflen, 0, + (const struct sockaddr *) &s_siClient, destLen); + if (ret == -1) { + strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE); + logerr("Error: 'sendto' [%d-%s]", errno, errstr); + } + return ret; /* error or number of bytes sent */ +} + +/************************************************************************** + * Function Name : ocmw_recv_clicmd_from_occli + * Description : This Function used to recv the command from cli + * Input(s) : buflen + * Output(s) : buf + ***************************************************************************/ +int32_t ocmw_recv_clicmd_from_occli(char* buf, int32_t buflen) +{ + char errstr[OCMW_SOCKET_ERROR_SIZE]; + int32_t ret = 0; + int32_t destLen = sizeof(s_siClient); + + /* Receive oc messages from other processes */ + ret = recvfrom(s_ssockFd, buf, buflen, 0, + (struct sockaddr*) &s_siClient, (socklen_t*) &destLen); + if (ret <= 0) { + strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE); + logerr("Error: 'recvfrom' [%d-%s]", errno, errstr); + ret = -1; + } + return ret; /* error or number of bytes received */ +} + +/************************************************************************** + * Function Name : ocmw_send_alert_to_occli + * Description : This Function used to send alerts to cli + * Input(s) : buf, buflen + * Output(s) : + ***************************************************************************/ +int32_t ocmw_send_alert_to_occli(const char* buf, int32_t buflen) +{ + char errstr[OCMW_SOCKET_ERROR_SIZE]; + int32_t ret = 0; + int32_t destLen = sizeof(s_siServerAlert); + + /* Send the message buffer over IPC */ + ret = sendto(s_ssockfdAlert, buf, buflen, 0, + (const struct sockaddr *) &s_siServerAlert, destLen); + if (ret == -1) { + strerror_r(errno, errstr, OCMW_SOCKET_ERROR_SIZE); + logerr("Error: 'sendto' [%d-%s]", errno, errstr); + } + return ret; /* error or number of bytes sent */ +} diff --git a/firmware/host/ocmw/ocmw_schema.c b/firmware/host/ocmw/ocmw_schema.c new file mode 100644 index 0000000000..2fbcc87dc1 --- /dev/null +++ b/firmware/host/ocmw/ocmw_schema.c @@ -0,0 +1,1104 @@ +#include +#include +#include + +int64_t recvdParamVal; +extern int32_t responseCount; +int32_t eepromFlag; +static int32_t s_typeFlag; +char dataOutBufFromEc[PARAM_STR_BUFF_SIZE] = {0}; +static char *s_paramEnumValue[OCMW_VALUE_TYPE_MFG] = {0}; +ocmwSchemaSendBuf *ecSendBufBkp; +ocwarePostResultData ocwarePostArray[TEMP_STR_BUFF_SIZE] = {{0}}; +uint8_t ocwarePostArrayIndex; +/****************************************************************************** + * Function Name : ocmw_parse_eepromdata_from_ec + * Description : parse the eeprom data coming from EC to AP + * Input(s) : ecInputData + * Output(s) : + ******************************************************************************/ +int8_t ocmw_parse_eepromdata_from_ec (ocmwSendRecvBuf ecInputData) +{ + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + if (ecInputData.msgType == OCMP_MSG_TYPE_STATUS) { + memcpy(dataOutBufFromEc, &ecInputData.pbuf[ecSendBufBkp->paramPos], + sizeof(ecInputData.pbuf)); + }else if (ecInputData.msgType == OCMP_MSG_TYPE_CONFIG) { + memcpy(dataOutBufFromEc, ecInputData.pbuf, EEPROM_CONFIG_SIZE); + } + + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_parse_testingmodule_struct_from_ec + * Description : parse the testmodule struct data coming from EC to AP + * Input(s) : ecInputData + * Output(s) : + ******************************************************************************/ +int32_t ocmw_parse_testingmodule_struct_from_ec(ocmwSendRecvBuf ecInputData) +{ + uint32_t paramVal2 = 0; + eOperatorStat paramVal = 0; + size_t size = 0; + + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + size = sizeof(dataOutBufFromEc); + + paramVal = *((uint8_t *) + &(ecInputData.pbuf[TWO_G_SIM_NET_OPTR_STATUS_OFFSET])); + paramVal2 = *((uint16_t *) ecInputData.pbuf); + switch (paramVal) { + case TWOG_SIM_STAT_UNKNOWN: + snprintf(dataOutBufFromEc, size, + "Operator code : %u Operator status : %u(STAT_UNKNOWN)", + paramVal2, paramVal); + break; + + case TWOG_SIM_STAT_AVAILABLE: + snprintf(dataOutBufFromEc, size, + "Operator code : %u Operator status : %u(STAT_AVAILABLE)", + paramVal2, paramVal); + break; + + case TWOG_SIM_STAT_CURRENT: + snprintf(dataOutBufFromEc, size, + "Operator code : %u Operator status : %u(STAT_CURRENT)", + paramVal2, paramVal); + break; + + case TWOG_SIM_STAT_FORBIDDEN: + snprintf(dataOutBufFromEc, size, + "Operator code : %u Operator status : %u(STAT_FORBIDDEN)", + paramVal2, paramVal); + break; + + default: + break; + } + + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_parse_obc_struct_from_ec + * Description : parse the obc data coming from EC to AP + * Input(s) : ecInputData + * Output(s) : + ******************************************************************************/ +int32_t ocmw_parse_obc_struct_from_ec(ocmwSendRecvBuf ecInputData) +{ + uint32_t paramVal2 = 0; + Source paramVal = 0; + size_t size = 0; + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + size = sizeof(dataOutBufFromEc); + + paramVal = (ecInputData.pbuf[ecSendBufBkp->paramPos]); + paramVal2 = *((uint16_t *) + &(ecInputData.pbuf[IRIDIUM_LASTERR_ERROR_CODE_OFFSET])); + switch (paramVal) { + case ERR_RC_INTERNAL: + snprintf(dataOutBufFromEc, size, + "Error Source : %u(ERR_RC_INTERNAL) Error Code : %u", + paramVal, paramVal2); + break; + + case ERR_SRC_CMS: + snprintf(dataOutBufFromEc, size, + "Error Source : %u(ERR_SRC_CMS) Error Code : %u", + paramVal, paramVal2); + break; + + case ERR_SRC_CME: + snprintf(dataOutBufFromEc, size, + "Error Source : %u(ERR_SRC_CME) Error Code : %u", + paramVal, paramVal2); + break; + + default: + break; + } + + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_get_paramSize + * Description : get the parameter size as per schema + * Input(s) : paramtype, msgtype, param_name + * Output(s) : + ******************************************************************************/ +int8_t ocmw_get_paramSize(const char* paramtype, int8_t msgtype, + const char* param_name) +{ + int8_t paramSize = 0; + + if (paramtype == NULL) { + printf("Invalid paramtype\n"); + return FAILED; + } + + if (!strcmp("uint16",paramtype)) { + paramSize = sizeof(uint16_t); + s_typeFlag = OCMW_VALUE_TYPE_UINT16; + } else if (!strcmp("int16",paramtype)) { + paramSize = sizeof(int16_t); + s_typeFlag = OCMW_VALUE_TYPE_INT16; + } else if (!strcmp("uint8",paramtype)) { + paramSize = sizeof(uint8_t); + s_typeFlag = OCMW_VALUE_TYPE_UINT8; + } else if (!strcmp("int8",paramtype)) { + paramSize = sizeof(int8_t); + s_typeFlag = OCMW_VALUE_TYPE_INT8; + } else if (!strcmp("uint32",paramtype)) { + paramSize = sizeof(uint32_t); + s_typeFlag = OCMW_VALUE_TYPE_UINT32; + } else if (!strcmp("uint64",paramtype)) { + paramSize = sizeof(uint64_t); + } else if (!strcmp("enum",paramtype)) { + s_typeFlag = OCMW_VALUE_TYPE_STRUCT; + paramSize = OCMW_VALUE_TYPE_ENUM; + } else { + paramSize = sizeof(int8_t); + } + + return paramSize; +} + +/****************************************************************************** + * Function Name : ocmw_frame_subsystem_from_schema + * Description : frame subsyetem as per schema + * Input(s) : schema, subSystemInfo + * Output(s) : + ******************************************************************************/ +int32_t ocmw_frame_subsystem_from_schema(const Component *subSystem, + subSystemInfo *systemInfo) +{ + int32_t index = 0; + memset(&systemInfo->totalNum,0,sizeof(0)); + while (subSystem && subSystem->name) { + systemInfo->totalNum += 1; + systemInfo->Info[index].number = index; + strncpy(systemInfo->Info[index].name, subSystem->name, + strlen(subSystem->name)); + index++; + subSystem += 1; + } + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_frame_postTable_from_schema + * Description : frame post as per schema + * Input(s) : schema, postInfo + * Output(s) : + ******************************************************************************/ +int32_t ocmw_frame_postTable_from_schema(const Component *subSystem) +{ + int32_t index = 0; + int32_t count = 0; + const Component *component = NULL; + const Component *subComponent = NULL; + uint8_t subSystemNum = 0; + char tempComp[PARAM_STR_BUFF_SIZE] = {0}; + char tempCompdev[PARAM_STR_BUFF_SIZE] = {0}; + ocwarePostArrayIndex = 0; + while (subSystem && subSystem->name) { + count = 1; + component = subSystem->components; + while (component && component->name) { + subComponent = component->components; + if ((subComponent == NULL) && + ((!(component->postDisabled)))) { + memset(tempComp, 0, strlen(tempComp)); + strncpy(tempComp,component->name,strlen(component->name)); + tempComp[0] = toupper(tempComp[0]); + strncpy((ocwarePostArray[index].subsysName), + subSystem->name, strlen(subSystem->name)); + strncpy((ocwarePostArray[index].deviceName), + tempComp, strlen(tempComp)); + ocwarePostArray[index].devsn = count++; + ocwarePostArray[index].subsystem = subSystemNum; + ocwarePostArrayIndex++; + index++; + } + while (subComponent && subComponent->name) { + if (!(subComponent->postDisabled)) { + strncpy(ocwarePostArray[index].subsysName, + subSystem->name, strlen(subSystem->name)); + memset(ocwarePostArray[index].deviceName, 0, + sizeof(ocwarePostArray[index].deviceName)); + memset(tempComp, 0, strlen(tempComp)); + memset(tempCompdev, 0, strlen(tempCompdev)); + strncpy(tempComp, component->name, strlen(component->name)); + strncpy(tempCompdev, subComponent->name, + strlen(subComponent->name)); + tempComp[0] = toupper(tempComp[0]); + tempCompdev[0] = toupper(tempCompdev[0]); + + if (!strcmp(component->name,"comp_all")) { + strcpy((ocwarePostArray[index].deviceName), + tempCompdev); + } else { + if ((snprintf(ocwarePostArray[index].deviceName, + OCMW_POST_DEVICE_SIZE, "%s %s", + tempComp, tempCompdev)) < 0) { + return FAILED; + } + } + ocwarePostArray[index].devsn = count++; + ocwarePostArray[index].subsystem = subSystemNum; + ocwarePostArrayIndex++; + index++; + } + subComponent += 1; + } + component += 1; + } + printf("\n"); + subSystem += 1; + subSystemNum++; + } + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_get_noOfElements + * Description : get the number of parameter for components + * Input(s) : param_list + * Output(s) : noOfElement, size + ******************************************************************************/ +void ocmw_get_noOfElements(const Parameter *param_list, int32_t *noOfElement, + int32_t *size) +{ + int8_t elementCount = 0; + int8_t pSize = 0; + + if (param_list == NULL) { + *noOfElement = 0; + *size = 0; + return; + } + while (param_list->name) { + if ((!strcmp("uint16", DATA_TYPE_MAP[param_list->type])) || + (!strcmp("int16", DATA_TYPE_MAP[param_list->type]))) { + pSize = pSize + sizeof(uint16_t); + } else { + pSize = pSize + sizeof(int8_t); + } + elementCount++; + param_list++; + } + *noOfElement = elementCount; + *size = pSize; +} + +/****************************************************************************** + * Function Name : ocmw_parse_command_msgframe + * Description : parse the command + * Input(s) : Schema, msgFrame, actiontype, ecSendBuf + * Output(s) : + ******************************************************************************/ +int32_t ocmw_parse_command_msgframe(const Component *compBase, + strMsgFrame *msgFrame, uint8_t actiontype, + ocmwSchemaSendBuf *ecSendBuf) +{ + const Component *component = NULL; + const Component *subSystem = compBase; + const Component *subcomponent = NULL; + const Command *comm = NULL; + const Driver *driver = NULL; + sMsgParam *sMsgFrameParam = (sMsgParam *) malloc(sizeof(sMsgParam)); + int16_t paramId = 0; + int8_t subCount = 0; + int8_t actionType = 0; + int8_t count = 0; + int8_t componentCount = 0; + int8_t paramSize = 0; + int8_t paramPos = 0; + recvdParamVal = 0; + eepromFlag = 0; + s_typeFlag = 0; + + if (subSystem == NULL) { + printf("Invalid Memory\n"); + return -1; + } + if (sMsgFrameParam == NULL) { + return -1; + } + memset(sMsgFrameParam, 0, sizeof(sMsgParam)); + if (ecSendBufBkp == NULL) { + ecSendBufBkp = + (ocmwSchemaSendBuf *) malloc(sizeof(ocmwSchemaSendBuf)); + } + if (ecSendBufBkp == NULL) { + return -1; + } + memset(ecSendBufBkp, 0, sizeof(ocmwSchemaSendBuf)); + /* Component id is starting from 1 */ + sMsgFrameParam->component = 1; + while (subSystem && subSystem->name) { + if (strncmp(subSystem->name, msgFrame->subsystem, + strlen(msgFrame->subsystem)) == 0) { + ecSendBuf->subsystem = (sMsgFrameParam->subsystem); + component = subSystem->components; + while (component && component->name) { + if (strcmp(component->name, msgFrame->component) == 0) { + ecSendBuf->componentId = sMsgFrameParam->component; + comm = component->commands; + /* + * Here we check if command is present in + * subsystem->component->command + */ + while (comm && comm->name) { + if (strncmp(comm->name, msgFrame->parameter, + strlen(msgFrame->parameter)) == 0) { + paramId = 0; + actionType = count; + subCount ++; + break; + } + count++; + comm += 1; + } + if (subCount != 0) + break; + driver = component->driver; + /* + * Here we check if command is present in + * subsystem->component->driver->command + */ + componentCount = 0; + if(driver != NULL) { + comm = driver->commands; + while (comm && comm->name) { + if (strncmp(comm->name, msgFrame->parameter, + strlen(msgFrame->parameter)) == 0) { + paramId = 0; + actionType = componentCount; + subCount ++; + break; + } + componentCount++; + comm += 1; + } + } + if (subCount != 0) + break; + /* + * Here we check if command is present in + * subsystem->component->subcomponent->driver->command + */ + count = 1; + subcomponent = component->components; + while (subcomponent && subcomponent->name) { + if (strcmp(subcomponent->name, msgFrame->subcomponent) + == 0) { + driver = subcomponent->driver; + if(driver != NULL) { + comm = driver->commands; + componentCount = 0; + while (comm && comm->name) { + if (strncmp(comm->name, msgFrame->parameter, + strlen(msgFrame->parameter)) == 0) { + /* + * Here subcomponentId = paramId + */ + paramId = count; + actionType = componentCount; + subCount ++; + /*break as we found the command */ + break; + } + comm += 1; + componentCount++; + } + break; + } + } + count++; + sMsgFrameParam->parameter += 1; + subcomponent += 1; + } + } + sMsgFrameParam->component += 1; + component += 1; + } + /* + * Break here because we are searching in only one subsystem + */ + break; + } + sMsgFrameParam->subsystem += 1; + subSystem += 1; + } + ecSendBuf->msgType = OCMP_MSG_TYPE_COMMAND; + ecSendBuf->actionType = actionType; + ecSendBuf->paramPos = paramPos; + ecSendBuf->paramId = paramId; + ecSendBuf->paramSize = paramSize; + if(msgFrame->parameter) { + memset(ecSendBuf->commandType, 0, + strlen(ecSendBuf->commandType)); + strncpy(ecSendBuf->commandType, msgFrame->parameter, + strlen(msgFrame->parameter)); + } + memcpy(ecSendBufBkp,ecSendBuf,sizeof(ocmwSchemaSendBuf)); + + free(sMsgFrameParam); + + if (subCount == 0) { + return FAILED; + } + + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_parse_post_msgframe + * Description : parse the post + * Input(s) : Schema, msgFrame, actiontype, ecSendBuf + * Output(s) : + ******************************************************************************/ +int32_t ocmw_parse_post_msgframe(const Component *compBase, + strMsgFrame *msgFrame, uint8_t actiontype, + ocmwSchemaSendBuf *ecSendBuf) +{ + const Component *component = NULL; + const Component *subSystem = compBase; + const Post *param = NULL; + const Driver *devDriver = NULL; + int16_t paramId = 0; + int8_t count = 0; + int8_t paramSize = 0; + int8_t paramPos = 0; + sMsgParam *sMsgFrameParam = (sMsgParam *) malloc(sizeof(sMsgParam)); + if (sMsgFrameParam == NULL) { + return FAILED; + } + if (ecSendBufBkp == NULL) { + ecSendBufBkp = + (ocmwSchemaSendBuf *) malloc(sizeof(ocmwSchemaSendBuf)); + } + if (ecSendBufBkp == NULL) { + return FAILED; + } + recvdParamVal = 0; + eepromFlag = 0; + s_typeFlag = 0; + if (subSystem == NULL) { + printf("Invalid Memory\n"); + return FAILED; + } + memset(sMsgFrameParam, 0, sizeof(sMsgParam)); + sMsgFrameParam->component = 1; + memset(ecSendBufBkp, 0, sizeof(ocmwSchemaSendBuf)); + while (subSystem && subSystem->name) { + if (strncmp(subSystem->name, msgFrame->subsystem, + strlen(msgFrame->subsystem)) == 0) { + ecSendBuf->subsystem = (sMsgFrameParam->subsystem); + component = subSystem->components; + while (component && component->name) { + if (strcmp(component->name, msgFrame->component) == 0) { + ecSendBuf->componentId = (sMsgFrameParam->component); + devDriver = component->driver; + ecSendBuf->msgType = OCMP_MSG_TYPE_POST; + ecSendBuf->actionType = actiontype; + param = devDriver->post; + while (param && param->name) { + if (strncmp(param->name, msgFrame->subcomponent, + strlen(msgFrame->subcomponent)) == 0) { + paramId = pow(2,count); + break; + } + count++; + param += 1; + } + break; + } + sMsgFrameParam->component += 1; + component += 1; + } + break; + } + sMsgFrameParam->subsystem += 1; + subSystem += 1; + } + ecSendBuf->paramPos = paramPos; + ecSendBuf->paramId = paramId; + ecSendBuf->paramSize = paramSize; + memcpy(ecSendBufBkp, ecSendBuf, sizeof(ocmwSchemaSendBuf)); + free(sMsgFrameParam); + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_parse_driver_from_component + * Description : parse driver as per schema + * Input(s) : msgFrame, ecSendBuf, devDriver, actiontype + * Output(s) : + ******************************************************************************/ +int32_t ocmw_parse_driver_from_component(strMsgFrame *msgFrame, + ocmwSchemaSendBuf *ecSendBuf, const Driver *devDriver, + uint8_t actiontype) +{ + const Parameter *param = NULL; + Enum_Map *value_enum = NULL; + int8_t count = 0; + int8_t index = 0; + int8_t regValue = 0; + int32_t temp = 0; + if (strncmp(msgFrame->msgtype, "config", strlen("config")) == 0) { + param = devDriver->config; + ecSendBuf->msgType = OCMP_MSG_TYPE_CONFIG; + ecSendBuf->actionType = actiontype; + while (param && param->name) { + if (strncmp(param->name, msgFrame->parameter, + strlen(msgFrame->parameter)) == 0) { + ecSendBuf->paramId = pow(2,count); + ecSendBuf->paramPos = temp + ecSendBuf->paramPos; + ecSendBuf->paramSize = ocmw_get_paramSize ( + DATA_TYPE_MAP[param->type], + OCMP_MSG_TYPE_CONFIG, param->name); + break; + } + count = count + 1; + if ((!strcmp("uint16", DATA_TYPE_MAP[param->type])) || + (!strcmp("int16", DATA_TYPE_MAP[param->type]))) { + ecSendBuf->paramPos = ecSendBuf->paramPos + sizeof(uint16_t); + } else if ((!strcmp("uint8", DATA_TYPE_MAP[param->type])) || + (!strcmp("int8", DATA_TYPE_MAP[param->type]))) { + ecSendBuf->paramPos = ecSendBuf->paramPos + sizeof(uint8_t); + } + param += 1; + } + } else if (strncmp(msgFrame->msgtype, "status", strlen("status")) == 0) { + param = devDriver->status; + ecSendBuf->msgType = OCMP_MSG_TYPE_STATUS; + ecSendBuf->actionType = actiontype; + while (param && param->name) { + if (strncmp(param->name, msgFrame->parameter, + strlen(msgFrame->parameter)) == 0) { + ecSendBuf->paramId = pow(2,count); + if ((strncmp(param->name,"registration", + strlen(msgFrame->parameter)) == 0) || + (strncmp(param->name,"gps_lock", + strlen(msgFrame->parameter)) == 0)) { + value_enum = param->values; + for (index =index; index < OCMW_VALUE_TYPE_MFG; index++) { + s_paramEnumValue[index] = (char *)malloc(BUF_SIZE); + } + while (value_enum && value_enum->name) { + regValue = value_enum->value; + strncpy((s_paramEnumValue[regValue]), value_enum->name, + ENUM_BUF_SIZE); + value_enum += 1; + } + s_typeFlag = OCMW_VALUE_TYPE_STRUCT; + } else if(strncmp(param->name, "network_operatorinfo", + strlen(msgFrame->parameter)) == 0) { + s_typeFlag = OCMW_VALUE_TYPE_NWOP_STRUCT; + } + if ((strncmp(msgFrame->subsystem, "obc", + strlen(msgFrame->subsystem)) == 0) || + (strncmp(msgFrame->subsystem, "testmodule", + strlen(msgFrame->subsystem)) == 0)) { + ecSendBuf->paramPos = 0; + } else { + ecSendBuf->paramPos = temp + ecSendBuf->paramPos; + } + if ((param->size) && + (strcmp(DATA_TYPE_MAP[param->type],"enum") != 0)) { + ecSendBuf->paramSize = param->size; + } else { + ecSendBuf->paramSize = ocmw_get_paramSize( + DATA_TYPE_MAP[param->type], + OCMP_MSG_TYPE_STATUS, param->name); + } + break; + } + count = count + 1; + if ((!strcmp("uint16", DATA_TYPE_MAP[param->type])) || + (!strcmp("int16", DATA_TYPE_MAP[param->type]))) { + ecSendBuf->paramPos = ecSendBuf->paramPos + sizeof(uint16_t); + } else if ((!strcmp("uint8", DATA_TYPE_MAP[param->type])) || + (!strcmp("int8", DATA_TYPE_MAP[param->type]))) { + ecSendBuf->paramPos = ecSendBuf->paramPos + sizeof(uint8_t); + } else if (!strcmp("string", DATA_TYPE_MAP[param->type])) { + ecSendBuf->paramPos = ecSendBuf->paramPos + + EEPROM_STATUS_MAX_SIZE; + } + param += 1; + } + } else if (strncmp(msgFrame->msgtype, "alerts", strlen("alerts")) == 0) { + param = devDriver->alerts; + } + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_parse_driver_from_subcomponent + * Description : parse driver as per schema + * Input(s) : msgFrame, ecSendBuf, subComponent, actiontype + * Output(s) : + ******************************************************************************/ +int32_t ocmw_parse_driver_from_subcomponent (strMsgFrame *msgFrame, + ocmwSchemaSendBuf *ecSendBuf, const Component *subComponent, + uint8_t actiontype) +{ + const Driver *devDriver = NULL; + const Parameter *param = NULL; + int32_t noOfElementTemp = 0; + int32_t noOfElement = 0; + int32_t temp = 0; + int32_t size = 0; + int8_t count = 0; + while (subComponent && subComponent->name) { + devDriver = subComponent->driver; + temp = temp + size; + if (strncmp(msgFrame->msgtype, "config", strlen("config")) == 0) { + param = devDriver->config; + ocmw_get_noOfElements(param,&noOfElement, &size); + } else if (strncmp(msgFrame->msgtype, "status", + strlen("status")) == 0) { + param = devDriver->status; + ocmw_get_noOfElements(param,&noOfElement, &size); + } + if (strncmp(subComponent->name, msgFrame->subcomponent, + strlen(msgFrame->subcomponent)) == 0) { + devDriver = subComponent->driver; + if (strncmp(msgFrame->msgtype, "config", strlen("config")) == 0) { + param = devDriver->config; + ecSendBuf->msgType = OCMP_MSG_TYPE_CONFIG; + ecSendBuf->actionType = actiontype; + while (param && param->name) { + if (strncmp(param->name, msgFrame->parameter, + strlen(msgFrame->parameter)) == 0) { + ecSendBuf->paramId = pow(2, + count + noOfElementTemp); + ecSendBuf->paramPos = temp + ecSendBuf->paramPos; + if (param->size) { + ecSendBuf->paramSize = param->size; + } else { + ecSendBuf->paramSize = ocmw_get_paramSize( + DATA_TYPE_MAP[param->type], + OCMP_MSG_TYPE_CONFIG, param->name); + } + break; + } + count = count + 1; + if ((!strcmp("uint16", DATA_TYPE_MAP[param->type])) || + (!strcmp("int16", DATA_TYPE_MAP[param->type]))) { + ecSendBuf->paramPos = + ecSendBuf->paramPos + sizeof(uint16_t); + } else if ((!strcmp("uint8", DATA_TYPE_MAP[param->type])) + || (!strcmp("int8", DATA_TYPE_MAP[param->type]))) { + ecSendBuf->paramPos = + ecSendBuf->paramPos + sizeof(uint8_t); + } + param += 1; + } + } else if (strncmp(msgFrame->msgtype, "status", + strlen("status")) == 0) { + param = devDriver->status; + ecSendBuf->msgType = OCMP_MSG_TYPE_STATUS; + ecSendBuf->actionType = actiontype; + while (param && param->name) { + if (strncmp(param->name, msgFrame->parameter, + strlen(msgFrame->parameter)) == 0) { + ecSendBuf->paramId = + pow(2, count + noOfElementTemp); + ecSendBuf->paramPos = temp + ecSendBuf->paramPos; + if (param->size) { + ecSendBuf->paramSize = param->size; + } else { + ecSendBuf->paramSize = ocmw_get_paramSize ( + DATA_TYPE_MAP[param->type], + OCMP_MSG_TYPE_STATUS, param->name); + } + break; + } + count = count + 1; + if ((!strcmp("uint16", DATA_TYPE_MAP[param->type])) || + (!strcmp("int16", DATA_TYPE_MAP[param->type]))) { + ecSendBuf->paramPos = + ecSendBuf->paramPos + sizeof(uint16_t); + } else if ((!strcmp("uint8", DATA_TYPE_MAP[param->type])) + || (!strcmp("int8", DATA_TYPE_MAP[param->type]))) { + ecSendBuf->paramPos = + ecSendBuf->paramPos + sizeof(uint8_t); + } else if (!strcmp("string", DATA_TYPE_MAP[param->type])) { + ecSendBuf->paramPos = ecSendBuf->paramPos + + EEPROM_STATUS_MAX_SIZE; + } + param += 1; + } + } else if (strncmp(msgFrame->msgtype, "alerts", + strlen("alerts")) == 0) { + param = devDriver->alerts; + } + break; + } + noOfElementTemp = noOfElementTemp + noOfElement; + subComponent += 1; + } + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_parse_msgframe + * Description : parse msgframe as per schema + * Input(s) : compBase, msgFrame, actiontype, ecSendBuf + * Output(s) : + ******************************************************************************/ +int32_t ocmw_parse_msgframe(const Component *compBase, strMsgFrame *msgFrame, + uint8_t actiontype,ocmwSchemaSendBuf *ecSendBuf) +{ + const Component *component = NULL; + const Component *subComponent = NULL; + const Component *subSystem = compBase; + const Driver *devDriver = NULL; + sMsgParam *sMsgFrameParam = (sMsgParam *) malloc(sizeof(sMsgParam)); + recvdParamVal = 0; + eepromFlag = 0; + s_typeFlag = 0; + + if (sMsgFrameParam == NULL) { + return FAILED; + } + memset(ecSendBuf, 0, sizeof(ocmwSchemaSendBuf)); + memset(sMsgFrameParam, 0, sizeof(sMsgParam)); + + if (ecSendBufBkp == NULL) { + ecSendBufBkp = + (ocmwSchemaSendBuf *) malloc(sizeof(ocmwSchemaSendBuf)); + } + if (ecSendBufBkp == NULL) { + return -1; + } + memset(ecSendBufBkp, 0, sizeof(ocmwSchemaSendBuf)); + if (subSystem == NULL) { + printf("Invalid Memory\n"); + return FAILED; + } + + /* Component id is starting from 1*/ + sMsgFrameParam->component = 1; + while (subSystem && subSystem->name) { + if (strncmp(subSystem->name, msgFrame->subsystem, + strlen(msgFrame->subsystem)) == 0) { + ecSendBuf->subsystem = (sMsgFrameParam->subsystem); + component = subSystem->components; + while (component && component->name) { + if (strcmp(component->name, msgFrame->component) == 0) { + ecSendBuf->componentId = sMsgFrameParam->component; + devDriver = component->driver; + if (devDriver != NULL) { + ocmw_parse_driver_from_component(msgFrame, + ecSendBuf,devDriver,actiontype); + } + subComponent = component->components; + if (subComponent != NULL){ + ocmw_parse_driver_from_subcomponent(msgFrame, + ecSendBuf,subComponent,actiontype); + } + break; + } + sMsgFrameParam->component += 1; + component += 1; + } + break; + } + printf("\n"); + sMsgFrameParam->subsystem += 1; + subSystem += 1; + } + memcpy(ecSendBufBkp, ecSendBuf, sizeof(ocmwSchemaSendBuf)); + free(sMsgFrameParam); + + return SUCCESS; +} +/****************************************************************************** + * Function Name : ocmw_parse_message_fram_from_ec + * Description : parse the msgframe data coming from EC to AP + * Input(s) : ecReceivedMsg + * Output(s) : + ******************************************************************************/ +int32_t ocmw_parse_message_fram_from_ec(OCMPMessageFrame *ecReceivedMsg) +{ + int32_t ret = 0; + int32_t index = 0; + int32_t paramVal = 0; + char regStr[BUF_SIZE] = {0}; + size_t size = 0; + + ocmwSendRecvBuf ecInputData; + switch(ecSendBufBkp->paramSize) { + case (sizeof(uint16_t)): + if (s_typeFlag == OCMW_VALUE_TYPE_UINT16) { + recvdParamVal = + *((uint16_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + } else if (s_typeFlag == OCMW_VALUE_TYPE_INT16) { + recvdParamVal = + *((int16_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + } + break; + case (sizeof(uint8_t)) : + if (s_typeFlag == OCMW_VALUE_TYPE_UINT8) { + recvdParamVal = + *((uint8_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + } else if (s_typeFlag == OCMW_VALUE_TYPE_INT8) { + recvdParamVal = + *((int8_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + } else if (s_typeFlag == OCMW_VALUE_TYPE_ENUM) { + recvdParamVal = + *((int8_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + } + break; + case (sizeof(uint32_t)): + if (s_typeFlag == OCMW_VALUE_TYPE_UINT32) { + recvdParamVal = + *((uint32_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + } else { + memset(dataOutBufFromEc, 0 , + sizeof(dataOutBufFromEc)); + memcpy(dataOutBufFromEc, ecReceivedMsg->message.info, + OCMW_VALUE_TYPE_MODEL); + eepromFlag++; + } + break; + case (sizeof(uint64_t)): + recvdParamVal = + *((uint64_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + break; + case EEPROM_CONFIG_MAX_SIZE: + case EEPROM_CONFIG_SIZE: + case EEPROM_SDR_STATUS_SIZE: + case EEPROM_STATUS_MAX_SIZE: + memset(&ecInputData, 0, sizeof(ocmwSendRecvBuf)); + ecInputData.numOfele = 0; + ecInputData.paramInfo = ecReceivedMsg->message.parameters; + ecInputData.componentId = ecReceivedMsg->message.componentID; + ecInputData.msgType = ecReceivedMsg->message.msgtype; + ecInputData.actionType = ecReceivedMsg->message.action; + ecInputData.subsystem = ecReceivedMsg->message.subsystem; + memcpy(ecInputData.pbuf, ecReceivedMsg->message.info, + MAX_PARM_COUNT); + ret = ocmw_parse_eepromdata_from_ec(ecInputData); + eepromFlag++; + break; + case OCMW_VALUE_TYPE_MFG: + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + memcpy(dataOutBufFromEc,ecReceivedMsg->message.info, + OCMW_VALUE_TYPE_MFG); + eepromFlag++; + break; + case OCMW_VALUE_TYPE_GETMODEL: + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + memcpy(dataOutBufFromEc, ecReceivedMsg->message.info, + OCMW_VALUE_TYPE_GETMODEL); + eepromFlag++; + break; + case OCMW_VALUE_TYPE_ENUM: + case OCMW_VALUE_TYPE_COMPLEX: + memset(&ecInputData, 0, sizeof(ocmwSendRecvBuf)); + ecInputData.numOfele = 0; + ecInputData.paramInfo = ecReceivedMsg->message.parameters; + ecInputData.componentId = ecReceivedMsg->message.componentID; + ecInputData.msgType = ecReceivedMsg->message.msgtype; + ecInputData.actionType = ecReceivedMsg->message.action; + ecInputData.subsystem = ecReceivedMsg->message.subsystem; + memcpy(ecInputData.pbuf, ecReceivedMsg->message.info, + MAX_PARM_COUNT); + if (s_typeFlag == OCMW_VALUE_TYPE_STRUCT) { + paramVal = *((uint8_t *) ecInputData.pbuf); + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + size = sizeof(dataOutBufFromEc); + if (s_paramEnumValue[paramVal]) { + strcpy(regStr,s_paramEnumValue[paramVal]); + snprintf(dataOutBufFromEc, size, + "%u(%s) ", paramVal,regStr); + for (index = 0; index < OCMW_VALUE_TYPE_MFG; index++) { + ocmw_free_global_pointer( + (void**)&s_paramEnumValue[index]); + } + } + }else if (s_typeFlag == OCMW_VALUE_TYPE_NWOP_STRUCT) { + ret = ocmw_parse_testingmodule_struct_from_ec(ecInputData); + } else { + ret = ocmw_parse_obc_struct_from_ec(ecInputData); + } + eepromFlag++; + break; + default: + break; + } + if (ret < 0) { + responseCount = 0; + } else { + responseCount++; + } + return SUCCESS; +} + +/****************************************************************************** + * Function Name : ocmw_deserialise_debug_gpio_value + * Description : parse the msgframe data coming from EC to AP + * Input(s) : ecReceivedMsg + * Output(s) : dataOutBufFromEc + ******************************************************************************/ +void ocmw_deserialise_debug_gpio_value(OCMPMessageFrame *ecReceivedMsg) +{ + int8_t pin = 0; + int8_t value = 0; + size_t size = 0; + + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + size = sizeof(dataOutBufFromEc); + pin = *((uint8_t *)&(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + value = *((uint8_t *)&(ecReceivedMsg->message.info[ecSendBufBkp->paramPos + + 1])); + snprintf(dataOutBufFromEc, size, "(Pin No : %d) %s = %d", pin, + ecSendBufBkp->commandType, value); + return; +} +/****************************************************************************** + * Function Name : ocmw_deserialise_debug_mdio_value + * Description : parse the msgframe data coming from EC to AP + * Input(s) : ecReceivedMsg + * Output(s) : dataOutBufFromEc + ******************************************************************************/ +void ocmw_deserialise_debug_mdio_value(OCMPMessageFrame *ecReceivedMsg) +{ + uint16_t registerAddress = 0; + uint16_t registerData = 0; + size_t size = 0; + registerAddress = *((uint16_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + registerData = *((uint16_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos + 2])); + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + size = sizeof(dataOutBufFromEc); + snprintf(dataOutBufFromEc, size, "(Register Address : %d) %s = %d", + registerAddress, ecSendBufBkp->commandType, registerData); + return; +} +/****************************************************************************** + * Function Name : ocmw_deserialise_debug_i2c_value + * Description : parse the msgframe data coming from EC to AP + * Input(s) : ecReceivedMsg + * Output(s) : dataOutBufFromEc + ******************************************************************************/ +void ocmw_deserialise_debug_i2c_value(OCMPMessageFrame *ecReceivedMsg) +{ + uint8_t slaveAddress = 0; + uint8_t noOfBytes = 0; + uint8_t registerAddress = 0; + uint16_t registerData = 0; + size_t size = 0; + + slaveAddress = *((uint8_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos])); + noOfBytes = *((uint8_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos + 1])); + registerAddress = *((uint8_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos + 2])); + + if (noOfBytes == OCMW_VALUE_TYPE_UINT8) { + registerData = *((uint8_t *) + &(ecReceivedMsg->message.info[ecSendBufBkp->paramPos + 3])); + } else { + registerData = ((uint16_t )((((uint8_t) + (ecReceivedMsg->message.info[ecSendBufBkp->paramPos + + 3]) & 0xff) << 8) | + ((uint8_t) + ((ecReceivedMsg->message.info[ecSendBufBkp->paramPos + + 4])) & 0xff))); + } + + memset(dataOutBufFromEc, 0, sizeof(dataOutBufFromEc)); + size = sizeof(dataOutBufFromEc); + snprintf(dataOutBufFromEc, size, "(slave address :%d noOfBytes :%d Register" + " Address :%d) %s = %d", slaveAddress, noOfBytes, + registerAddress, ecSendBufBkp->commandType, registerData); + + if (strcmp(ecSendBufBkp->commandType, "set") == 0) { + strcat(dataOutBufFromEc, " : Success"); + } + return; +} +/****************************************************************************** + * Function Name : ocmw_deserialization_msgframe + * Description : parse the msgframe data coming from EC to AP + * Input(s) : subSystem, ecReceivedMsg + * Output(s) : dMsgFrameParam + ******************************************************************************/ +void ocmw_deserialization_msgframe(const Component *subSystem, + sMsgParam *dMsgFrameParam, OCMPMessageFrame *ecReceivedMsg) +{ + int32_t ret = 0; + int8_t index = 0; + + if (subSystem == NULL) { + return; + } + + if (ecReceivedMsg->message.parameters != 0) { + if ((ecReceivedMsg->message.subsystem == + ecSendBufBkp->subsystem) && + (ecReceivedMsg->message.componentID == + ecSendBufBkp->componentId) && + (ecReceivedMsg->message.msgtype == + ecSendBufBkp->msgType) && + (ecReceivedMsg->message.action == + OCMP_AXN_TYPE_REPLY) && + (ecReceivedMsg->message.parameters == + ecSendBufBkp->paramId)) { + + ret = ocmw_parse_message_fram_from_ec(ecReceivedMsg); + if (ret < 0) { + printf("\nocmw_parse_message_fram_from_ec error"); + } + } + } + if (ecReceivedMsg->message.msgtype == OCMP_MSG_TYPE_COMMAND) { + if ((ecReceivedMsg->message.subsystem == + ecSendBufBkp->subsystem) && + (ecReceivedMsg->message.componentID == + ecSendBufBkp->componentId) && + (ecReceivedMsg->message.msgtype == + ecSendBufBkp->msgType) && + (ecReceivedMsg->message.action == + OCMP_AXN_TYPE_REPLY) && + (ecReceivedMsg->message.parameters == + ecSendBufBkp->paramId)) { + if ((ecReceivedMsg->message.subsystem == DEBUG_SUBSYSTEM_NBR)) { + if (ecReceivedMsg->message.componentID < DEBUG_I2C) { + ocmw_deserialise_debug_i2c_value(ecReceivedMsg); + } else if (ecReceivedMsg->message.componentID == + DEBUG_MDIO) { + ocmw_deserialise_debug_mdio_value(ecReceivedMsg); + } else { + ocmw_deserialise_debug_gpio_value(ecReceivedMsg); + } + } + responseCount++; + } + } + /* Free backup info if stored */ + for (index = 0; index < OCMW_VALUE_TYPE_MFG; index++) { + ocmw_free_global_pointer((void**)&s_paramEnumValue[index]); + } + if (ecSendBufBkp) { + ocmw_free_global_pointer((void**)&ecSendBufBkp); + } +} diff --git a/firmware/host/ocmw/ocmw_uart_comm.c b/firmware/host/ocmw/ocmw_uart_comm.c new file mode 100644 index 0000000000..445814cff9 --- /dev/null +++ b/firmware/host/ocmw/ocmw_uart_comm.c @@ -0,0 +1,312 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* stdlib includes */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* OC includes */ +#include +#include +#include + +static int32_t s_fd = 0; +struct termios s_oldtio; +static handle_msg_from_ec_t s_uart_msg_hndlr = NULL; +static void sa_handler_read(int32_t status); +static bool S_STOP_UART_RX_SERVICE = true; +static pthread_t s_uartrxthread; +static volatile bool s_waitForUartMsg = true; +extern uint8_t mcuMsgBuf[OCMP_MSG_SIZE]; + +/************************************************************************** + * Function Name : ocmw_ec_uart_msg_hndlr + * Description : This Function used to handle uart messages + * Input(s) : msgstr, msgsize + * Output(s) : + ***************************************************************************/ +void ocmw_ec_uart_msg_hndlr(const unsigned char* msgstr, int32_t msgsize) +{ + /* Process the OC message received from EC */ + if (msgsize > OCMP_MSG_SIZE) { + logerr("message size is more than %d bytes", OCMP_MSG_SIZE); + return; + } + + /* Store the uart msg into global buffer */ + memcpy(mcuMsgBuf, msgstr, msgsize); + + /* Signal the msg parser for ec uart msg */ + sem_post(&semecMsgParser); + + return; +} + +/************************************************************************** + * Function Name : ocmw_recv_uart_msg_service + * Description : This Function used to receive uart messages + * Input(s) : + * Output(s) : args + ***************************************************************************/ +static void* ocmw_recv_uart_msg_service(void* args) +{ + unsigned char msg[OCMP_MSG_SIZE] = {0}; + unsigned char buf[OCMP_MSG_SIZE] = {0}; + int32_t ret = 0; + const unsigned int msglen = OCMP_MSG_SIZE; + + while (!S_STOP_UART_RX_SERVICE) { + /* Receive UART messages from EC */ + if (s_waitForUartMsg) { + usleep(10); + continue; + } + s_waitForUartMsg = true; + + /* Read message frame from tty */ + memset(msg, 0, msglen); + memset(buf, 0, OCMP_MSG_SIZE); + ret = read(s_fd, msg, msglen); + if (ret < 0) { + logerr("Error reading from %s (%d - %s)", ECTTY, errno, + strerror(errno)); + continue; + } + if (memcmp(msg, buf, OCMP_MSG_SIZE) == 0) { + continue; /* Not a valid UART message */ + } + + /* printf("Data from EC:\n"); */ + /* hexdisp(msg, msglen); */ + if (s_uart_msg_hndlr != NULL) { + (*s_uart_msg_hndlr)(msg, msglen); + } + } + return NULL; +} + +/************************************************************************** + * Function Name : sa_handler_read + * Description : This Function used to read the handler + * Input(s) : status + * Output(s) : + ***************************************************************************/ +static void sa_handler_read(int32_t status) +{ + s_waitForUartMsg = false; + return; +} + +/************************************************************************** + * Function Name : ocmw_init_ec_comm + * Description : This Function used to initialize the ec communication + * Input(s) : msghndlr + * Output(s) : + ***************************************************************************/ +int32_t ocmw_init_ec_comm(handle_msg_from_ec_t msghndlr) +{ + char pathName[100] = {0}; + int32_t ret = 0; + struct termios newtio; + struct sigaction saio; + + memset(pathName, 0, sizeof(pathName)); +#ifdef INTERFACE_USB + ret = ocmw_find_ttyacm_port(pathName); + if (ret != 0) { + return ret; + } +#else + memcpy(pathName, (char *) ECTTY, sizeof(ECTTY)); +#endif + /* + * Open the HSUART-1 port for communicating with EC + * + * O_NOCTTY - Not an interactive console + * O_NONBLOCK - Read need not be a blocking call + */ + s_fd = open(pathName, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (s_fd == -1) { + if (s_fd == -1) { + logerr("Error opening %s (%d - %s)", ECTTY, errno, + strerror(errno)); + return -1; + } + } + + /* Install signal handler for asynchronous read */ + saio.sa_handler = sa_handler_read; + sigemptyset(&saio.sa_mask); + saio.sa_flags = SA_RESTART; + saio.sa_restorer = NULL; + sigaction(SIGIO, &saio, NULL); + + /* Allow this process to receive SIGIO */ + fcntl(s_fd, F_SETOWN, getpid()); + + /* Set file descriptor to handle asynchronous reads */ + fcntl(s_fd, F_SETFL, O_ASYNC); + + tcgetattr(s_fd, &s_oldtio); + memset(&newtio, 0, sizeof(newtio)); + cfsetispeed(&newtio, B115200); /* Baud rate = 115200 */ + cfsetospeed(&newtio, B115200); + newtio.c_cflag &= ~PARENB; /* No parity check */ + newtio.c_cflag &= ~CSTOPB; /* 1 STOP bit */ + newtio.c_cflag &= ~CSIZE; /* 8 DATA bits */ + newtio.c_cflag |= CS8; + newtio.c_cflag &= ~CRTSCTS; /* No HW flow control */ + /* Enable always. CREAD - Enable receiver. + * CLOCAL - program doesn't own the tty. */ + newtio.c_cflag |= (CLOCAL | CREAD); + newtio.c_cc[VTIME] = 10; /* Inter character TIME=t*0.1s, where t=10. */ + newtio.c_cc[VMIN] = 0; //33; /* EC message frame size = 32 bytes */ + newtio.c_iflag &= ~(IXON | IXOFF | IXANY); /* No SW flow control */ + newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + newtio.c_oflag &= ~OPOST; + tcflush(s_fd, TCIFLUSH); + tcsetattr(s_fd, TCSANOW, &newtio); + + S_STOP_UART_RX_SERVICE = false; + ret = pthread_create(&s_uartrxthread, NULL, ocmw_recv_uart_msg_service, + NULL); + if (ret != 0) { + logerr("pthread creation failed [%d-%s]", errno, strerror(errno)); + } else { + s_uart_msg_hndlr = msghndlr; + } + + if (ret != 0) { + ocmw_deinit_ec_comm(); + } + return ret; +} + +/************************************************************************** + * Function Name : ocmw_deinit_ec_comm + * Description : This Function used to deinitialize the ec communication + * Input(s) : + * Output(s) : + ***************************************************************************/ +int32_t ocmw_deinit_ec_comm(void) +{ + S_STOP_UART_RX_SERVICE = true; + tcsetattr(s_fd, TCSANOW, &s_oldtio); + if (s_fd > 0) { + close(s_fd); + s_fd = 0; + } + if (s_uart_msg_hndlr != NULL) { + s_uart_msg_hndlr = NULL; + } + return SUCCESS; +} + +/************************************************************************** + * Function Name : ocmw_send_uart_msg_to_ec + * Description : This Function used to send uart message to ec + * Input(s) : msgstr, msgsize + * Output(s) : + ***************************************************************************/ +int32_t ocmw_send_uart_msg_to_ec(const uint8_t* msgstr, int32_t msgsize) +{ + uint8_t buf[OCMP_MSG_SIZE] = {0}; + int32_t ret = 0, bufWriteCount = 0; + int32_t sendPktNonpayloadSize = 0; + int32_t loopCount = 0; + OCMPMessageFrame *ecMsgFrame; + + ecMsgFrame = (OCMPMessageFrame *) msgstr; + + sendPktNonpayloadSize = (sizeof(OCMPMessage) - sizeof(void *) + + sizeof(OCMPHeader)); + + if (msgstr == NULL) { + logerr("Error: Memory allocation problem"); + return -1; + } + + if (msgsize > OCMP_MSG_SIZE) { + logerr("Error: msgstr size is more than %d bytes", OCMP_MSG_SIZE); + return -EMSGSIZE; + } + + /* create message frame */ + memset(buf, 0, sizeof(buf)); + memcpy(buf, msgstr, sendPktNonpayloadSize); + memcpy(&buf[sendPktNonpayloadSize], ((ecMsgFrame->message).info), + MAX_PARM_COUNT); + + /* Write message frame to tty */ + bufWriteCount = write(s_fd, buf, sizeof(buf)); + if (bufWriteCount < 0) { + ret = errno; + logerr("Error writing to %s (%d - %s)", ECTTY, ret, strerror(errno)); + return -ret; + } + +#ifndef MSG_LOG + printf(" \n send_msg_to_ec \n"); + + for (loopCount = 0; loopCount < OCMP_MSG_SIZE; loopCount++) { + printf("0x%x ", buf[loopCount] & 0x00ff); + } + + printf("\n"); +#endif /* MSG_LOG */ + + return ret; +} + +/************************************************************************** + * Function Name : ocmw_find_ttyacm_port + * Description : This Function used to find the tty port + * Input(s) : + * Output(s) : pathName + ***************************************************************************/ +int32_t ocmw_find_ttyacm_port(char *pathName) +{ + FILE *fp; + int32_t nodeNum = -1; + int32_t ret = 0; + + if (pathName == NULL) { + return ret = -1; + } + + /* Open the command for reading. */ + fp = popen(ECTTY, "r"); + if (fp == NULL) { + printf("Failed to run command\n"); + return ret = -1; + } + + fscanf(fp, "%d", &nodeNum); + if (nodeNum < 0) { + /* close */ + pclose(fp); + printf(" No ttyACM port found \n"); + return ret = -1; + } else { + sprintf(pathName, "/dev/ttyACM%d", nodeNum); + printf(" ttyACM port = %s \n", pathName); + /* close */ + pclose(fp); + } + return ret; +} diff --git a/firmware/host/ocwarestub/get_params_stub.sh b/firmware/host/ocwarestub/get_params_stub.sh new file mode 100755 index 0000000000..8b6e6d9f7d --- /dev/null +++ b/firmware/host/ocwarestub/get_params_stub.sh @@ -0,0 +1,390 @@ +#!/bin/sh +if [ -z "$1" ]; then + echo "Invalid Option" + echo "Usage : ./get_params " + exit +elif [ $1 = "bms" ]; then +if [ $2 = "config" ]; then +../bin/occmd bms.ec.config.temp_sensor1.lowlimit.get +../bin/occmd bms.ec.config.temp_sensor1.highlimit.get +../bin/occmd bms.ec.config.temp_sensor1.critlimit.get +../bin/occmd bms.ec.config.current_sensor1.currlimit.get +../bin/occmd bms.ec.config.current_sensor2.currlimit.get +elif [ $2 = "status" ]; then +../bin/occmd bms.ec.status.temp_sensor1.temperature.get +../bin/occmd bms.ec.status.current_sensor1.busvoltage.get +../bin/occmd bms.ec.status.current_sensor1.shuntvoltage.get +../bin/occmd bms.ec.status.current_sensor1.current.get +../bin/occmd bms.ec.status.current_sensor1.power.get +../bin/occmd bms.ec.status.current_sensor2.busvoltage.get +../bin/occmd bms.ec.status.current_sensor2.shuntvoltage.get +../bin/occmd bms.ec.status.current_sensor2.current.get +../bin/occmd bms.ec.status.current_sensor2.power.get +else + echo "Invalid Option" +fi +elif [ $1 = "gpp" ]; then +if [ $2 = "config" ]; then +../bin/occmd gpp.ap.config.temp_sensor1.lowlimit.get +../bin/occmd gpp.ap.config.temp_sensor1.highlimit.get +../bin/occmd gpp.ap.config.temp_sensor1.critlimit.get +../bin/occmd gpp.ap.config.temp_sensor2.lowlimit.get +../bin/occmd gpp.ap.config.temp_sensor2.highlimit.get +../bin/occmd gpp.ap.config.temp_sensor2.critlimit.get +../bin/occmd gpp.ap.config.temp_sensor3.lowlimit.get +../bin/occmd gpp.ap.config.temp_sensor3.highlimit.get +../bin/occmd gpp.ap.config.temp_sensor3.critlimit.get +../bin/occmd gpp.ap.config.current_sensor1.currlimit.get +../bin/occmd gpp.msata.config.current_sensor1.currlimit.get +elif [ $2 = "status" ]; then +../bin/occmd gpp.ap.status.temp_sensor1.temperature.get +../bin/occmd gpp.ap.status.temp_sensor2.temperature.get +../bin/occmd gpp.ap.status.temp_sensor3.temperature.get +../bin/occmd gpp.ap.status.current_sensor1.busvoltage.get +../bin/occmd gpp.ap.status.current_sensor1.shuntvoltage.get +../bin/occmd gpp.ap.status.current_sensor1.current.get +../bin/occmd gpp.ap.status.current_sensor1.power.get +../bin/occmd gpp.msata.status.current_sensor1.busvoltage.get +../bin/occmd gpp.msata.status.current_sensor1.shuntvoltage.get +../bin/occmd gpp.msata.status.current_sensor1.current.get +../bin/occmd gpp.msata.status.current_sensor1.power.get +else + echo "Invalid Option" +fi +elif [ $1 = "sdr" ]; then +if [ $2 = "config" ]; then +../bin/occmd sdr.comp_all.config.current_sensor1.currlimit.get +../bin/occmd sdr.fpga.config.temp_sensor1.lowlimit.get +../bin/occmd sdr.fpga.config.temp_sensor1.highlimit.get +../bin/occmd sdr.fpga.config.temp_sensor1.critlimit.get +../bin/occmd sdr.fpga.config.current_sensor1.currlimit.get +elif [ $2 = "status" ]; then +../bin/occmd sdr.comp_all.status.current_sensor1.busvoltage.get +../bin/occmd sdr.comp_all.status.current_sensor1.shuntvoltage.get +../bin/occmd sdr.comp_all.status.current_sensor1.current.get +../bin/occmd sdr.comp_all.status.current_sensor1.power.get +../bin/occmd sdr.fpga.status.temp_sensor1.temperature.get +../bin/occmd sdr.fpga.status.current_sensor1.busvoltage.get +../bin/occmd sdr.fpga.status.current_sensor1.shuntvoltage.get +../bin/occmd sdr.fpga.status.current_sensor1.current.get +../bin/occmd sdr.fpga.status.current_sensor1.power.get +../bin/occmd sdr.comp_all.status.eeprom.dev_id.get +else + echo "Invalid Option" +fi +elif [ $1 = "rf" ]; then +if [ $2 = "config" ]; then +../bin/occmd rffe.ch1_sensor.config.temp_sensor1.lowlimit.get +../bin/occmd rffe.ch1_sensor.config.temp_sensor1.highlimit.get +../bin/occmd rffe.ch1_sensor.config.temp_sensor1.critlimit.get +../bin/occmd rffe.ch1_sensor.config.current_sensor1.currlimit.get +../bin/occmd rffe.ch2_sensor.config.temp_sensor1.lowlimit.get +../bin/occmd rffe.ch2_sensor.config.temp_sensor1.highlimit.get +../bin/occmd rffe.ch2_sensor.config.temp_sensor1.critlimit.get +../bin/occmd rffe.ch2_sensor.config.current_sensor1.currlimit.get +#../bin/occmd rffe.ch1_fe.config.rf.band get +#../bin/occmd rffe.ch1_fe.config.rf.arfcn get +../bin/occmd rffe.ch1_fe.config.tx.atten.get +../bin/occmd rffe.ch1_fe.config.rx.atten.get +#../bin/occmd rffe.ch2_fe.config.rf.band get +#../bin/occmd rffe.ch2_fe.config.rf.arfcn get +../bin/occmd rffe.ch2_fe.config.tx.atten.get +../bin/occmd rffe.ch2_fe.config.rx.atten.get +elif [ $2 = "status" ]; then +../bin/occmd rffe.ch1_sensor.status.temp_sensor1.temperature.get +../bin/occmd rffe.ch1_sensor.status.current_sensor1.busvoltage.get +../bin/occmd rffe.ch1_sensor.status.current_sensor1.shuntvoltage.get +../bin/occmd rffe.ch1_sensor.status.current_sensor1.current.get +../bin/occmd rffe.ch1_sensor.status.current_sensor1.power.get +../bin/occmd rffe.ch2_sensor.status.temp_sensor1.temperature.get +../bin/occmd rffe.ch2_sensor.status.current_sensor1.busvoltage.get +../bin/occmd rffe.ch2_sensor.status.current_sensor1.shuntvoltage.get +../bin/occmd rffe.ch2_sensor.status.current_sensor1.current.get +../bin/occmd rffe.ch2_sensor.status.current_sensor1.power.get +../bin/occmd rffe.ch1_fe.status.power.forward.get +../bin/occmd rffe.ch1_fe.status.power.reverse.get +../bin/occmd rffe.ch2_fe.status.power.forward.get +../bin/occmd rffe.ch2_fe.status.power.reverse.get +../bin/occmd rffe.comp_all.status.eeprom.dev_id.get +else + echo "Invalid Option" +fi +elif [ $1 = "power" ]; then +if [ $2 = "config" ]; then +../bin/occmd power.leadacid_sensor.config.temp_sensor1.lowlimit.get +../bin/occmd power.leadacid_sensor.config.temp_sensor1.highlimit.get +../bin/occmd power.leadacid_sensor.config.temp_sensor1.critlimit.get +../bin/occmd power.leadacid.config.battery.batteryVoltageLow.get +../bin/occmd power.leadacid.config.battery.batteryVoltageHigh.get +../bin/occmd power.leadacid.config.battery.batteryCurrentLow.get +../bin/occmd power.leadacid.config.battery.inputVoltageLow.get +../bin/occmd power.leadacid.config.battery.inputCurrentHigh.get +../bin/occmd power.leadacid.config.battery.inputCurrentLimit.get +../bin/occmd power.leadacid.config.battery.icharge.get +../bin/occmd power.leadacid.config.battery.vcharge.get +../bin/occmd power.lion.config.battery.batteryVoltageLow.get +../bin/occmd power.lion.config.battery.batteryVoltageHigh.get +../bin/occmd power.lion.config.battery.batteryCurrentLow.get +../bin/occmd power.lion.config.battery.inputVoltageLow.get +../bin/occmd power.lion.config.battery.inputCurrentHigh.get +../bin/occmd power.lion.config.battery.inputCurrentLimit.get +../bin/occmd power.lion.config.battery.icharge.get +../bin/occmd power.lion.config.battery.vcharge.get +elif [ $2 = "status" ]; then +../bin/occmd power.leadacid_sensor.status.temp_sensor1.temperature.get +../bin/occmd power.leadacid.status.battery.batteryVoltage.get +../bin/occmd power.leadacid.status.battery.batteryCurrent.get +../bin/occmd power.leadacid.status.battery.systemVoltage.get +../bin/occmd power.leadacid.status.battery.inputVoltage.get +../bin/occmd power.leadacid.status.battery.inputCurrent.get +../bin/occmd power.leadacid.status.battery.dieTemperature.get +../bin/occmd power.lion.status.battery.batteryVoltage.get +../bin/occmd power.lion.status.battery.batteryCurrent.get +../bin/occmd power.lion.status.battery.systemVoltage.get +../bin/occmd power.lion.status.battery.inputVoltage.get +../bin/occmd power.lion.status.battery.inputCurrent.get +../bin/occmd power.lion.status.battery.dieTemperature.get +../bin/occmd power.comp_all.status.powerSource.extBattAccessebility.get +../bin/occmd power.comp_all.status.powerSource.extBattAvailability.get +../bin/occmd power.comp_all.status.powerSource.intBattAccessebility.get +../bin/occmd power.comp_all.status.powerSource.intBattAvailability.get +../bin/occmd power.comp_all.status.powerSource.poeAccessebility.get +../bin/occmd power.comp_all.status.powerSource.poeAvailability.get +../bin/occmd power.comp_all.status.powerSource.solarAccessebility.get +../bin/occmd power.comp_all.status.powerSource.solarAvailability.get +else + echo "Invalid Option" +fi +elif [ $1 = "ethernet" ]; then +if [ $2 = "config" ]; then +../bin/occmd ethernet.port0.config.speed.get +../bin/occmd ethernet.port0.config.duplex.get +../bin/occmd ethernet.port0.config.powerDown.get +../bin/occmd ethernet.port0.config.enable_sleepMode.get +../bin/occmd ethernet.port0.config.enable_interrupt.get +#../bin/occmd ethernet.port0.config.switch_reset get +#../bin/occmd ethernet.port0.config.restart_autoneg get +../bin/occmd ethernet.port1.config.speed.get +../bin/occmd ethernet.port1.config.duplex.get +../bin/occmd ethernet.port1.config.powerDown.get +../bin/occmd ethernet.port1.config.enable_sleepMode.get +../bin/occmd ethernet.port1.config.enable_interrupt.get +#../bin/occmd ethernet.port1.config.switch_reset get +#../bin/occmd ethernet.port1.config.restart_autoneg get +../bin/occmd ethernet.port2.config.speed.get +../bin/occmd ethernet.port2.config.duplex.get +../bin/occmd ethernet.port2.config.powerDown.get +../bin/occmd ethernet.port2.config.enable_sleepMode.get +../bin/occmd ethernet.port3.config.enable_interrupt.get +#../bin/occmd ethernet.port2.config.switch_reset get +#../bin/occmd ethernet.port2.config.restart_autoneg get +../bin/occmd ethernet.port3.config.speed.get +../bin/occmd ethernet.port3.config.duplex.get +../bin/occmd ethernet.port3.config.powerDown.get +../bin/occmd ethernet.port3.config.enable_sleepMode.get +../bin/occmd ethernet.port3.config.enable_interrupt.get +#../bin/occmd ethernet.port3.config.switch_reset get +#../bin/occmd ethernet.port3.config.restart_autoneg get +../bin/occmd ethernet.port4.config.speed.get +../bin/occmd ethernet.port4.config.duplex.get +../bin/occmd ethernet.port4.config.powerDown.get +../bin/occmd ethernet.port4.config.enable_sleepMode.get +../bin/occmd ethernet.port4.config.enable_interrupt.get +#../bin/occmd ethernet.port4.config.switch_reset get +#../bin/occmd ethernet.port4.config.restart_autoneg get +elif [ $2 = "status" ]; then +../bin/occmd ethernet.port0.status.speed.get +../bin/occmd ethernet.port0.status.duplex.get +../bin/occmd ethernet.port0.status.sleep_mode_en.get +../bin/occmd ethernet.port0.status.autoneg_on.get +../bin/occmd ethernet.port0.status.autoneg_complete.get +../bin/occmd ethernet.port0.status.link_up.get +../bin/occmd ethernet.port1.status.speed.get +../bin/occmd ethernet.port1.status.duplex.get +../bin/occmd ethernet.port1.status.sleep_mode_en.get +../bin/occmd ethernet.port1.status.autoneg_on.get +../bin/occmd ethernet.port1.status.autoneg_complete.get +../bin/occmd ethernet.port1.status.link_up.get +../bin/occmd ethernet.port2.status.speed.get +../bin/occmd ethernet.port2.status.duplex.get +../bin/occmd ethernet.port2.status.sleep_mode_en.get +../bin/occmd ethernet.port2.status.autoneg_on.get +../bin/occmd ethernet.port2.status.autoneg_complete.get +../bin/occmd ethernet.port2.status.link_up.get +../bin/occmd ethernet.port3.status.speed.get +../bin/occmd ethernet.port3.status.duplex.get +../bin/occmd ethernet.port3.status.sleep_mode_en.get +../bin/occmd ethernet.port3.status.autoneg_on.get +../bin/occmd ethernet.port3.status.autoneg_complete.get +../bin/occmd ethernet.port3.status.link_up.get +../bin/occmd ethernet.port4.status.speed.get +../bin/occmd ethernet.port4.status.duplex.get +../bin/occmd ethernet.port4.status.sleep_mode_en.get +../bin/occmd ethernet.port4.status.autoneg_on.get +../bin/occmd ethernet.port4.status.autoneg_complete.get +../bin/occmd ethernet.port4.status.link_up.get +else + echo "Invalid Option" +fi +elif [ $1 = "sync" ]; then +if [ $2 = "config" ]; then +../bin/occmd sync.sensor.config.temp_sensor1.lowlimit.get +../bin/occmd sync.sensor.config.temp_sensor1.highlimit.get +../bin/occmd sync.sensor.config.temp_sensor1.critlimit.get +elif [ $2 = "status" ]; then +../bin/occmd sync.gps.status.gps_lock.get +../bin/occmd sync.sensor.status.temp_sensor1.temperature.get +else + echo "Invalid Option" +fi +elif [ $1 = "testmodule" ]; then +if [ $2 = "status" ]; then +../bin/occmd testmodule.2gsim.status.imei.get +../bin/occmd testmodule.2gsim.status.imsi.get +../bin/occmd testmodule.2gsim.status.mfg.get +../bin/occmd testmodule.2gsim.status.model.get +../bin/occmd testmodule.2gsim.status.rssi.get +../bin/occmd testmodule.2gsim.status.ber.get +../bin/occmd testmodule.2gsim.status.registration.get +../bin/occmd testmodule.2gsim.status.network_operatorinfo.get +../bin/occmd testmodule.2gsim.status.cellid.get +../bin/occmd testmodule.2gsim.status.bsic.get +../bin/occmd testmodule.2gsim.status.lasterror.get +else + echo "Invalid Option" +fi +elif [ $1 = "obc" ]; then +if [ $2 = "status" ]; then +../bin/occmd obc.iridium.status.imei.get +../bin/occmd obc.iridium.status.mfg.get +../bin/occmd obc.iridium.status.model.get +../bin/occmd obc.iridium.status.signal_quality.get +../bin/occmd obc.iridium.status.registration.get +../bin/occmd obc.iridium.status.numberofoutgoingmessage.get +../bin/occmd obc.iridium.status.lasterror.get +else + echo "Invalid Option" +fi +elif [ $1 = "hci" ]; then +if [ $2 = "config" ]; then +../bin/occmd hci.led.config.temp_sensor1.lowlimit.get +../bin/occmd hci.led.config.temp_sensor1.highlimit.get +../bin/occmd hci.led.config.temp_sensor1.critlimit.get +elif [ $2 = "status" ]; then +../bin/occmd hci.led.status.temp_sensor1.temperature.get +#../bin/occmd hci.led.config.ledstate get +else + echo "Invalid Option" +fi +elif [ $1 = "system" ]; then +if [ $2 = "status" ]; then +../bin/occmd system.comp_all.status.eeprom_sid.gbcboardinfo.get +../bin/occmd system.comp_all.status.eeprom_sid.ocserialinfo.get +../bin/occmd system.comp_all.config.eeprom_mac.address.get +../bin/occmd system.comp_all.echo +../bin/occmd system.comp_all.reset + +../bin/occmd testmodule.2gsim.disconnect_nw +../bin/occmd testmodule.2gsim.connect_nw +../bin/occmd testmodule.2gsim.send 9789799425 hi +../bin/occmd testmodule.2gsim.dial 9789799425 +../bin/occmd testmodule.2gsim.answer_call +../bin/occmd testmodule.2gsim.hangup_call +../bin/occmd testmodule.comp_all.reset +../bin/occmd obc.iridium.reset +../bin/occmd ethernet.port0.reset +../bin/occmd ethernet.port1.reset +../bin/occmd ethernet.port2.reset +../bin/occmd ethernet.port3.reset +../bin/occmd power.pse.reset +../bin/occmd rffe.comp_all.reset +../bin/occmd gpp.ap.reset +../bin/occmd hci.led.fw.set 1 +../bin/occmd rffe.ch1_fe.enable +../bin/occmd rffe.ch1_fe.disable +../bin/occmd rffe.ch2_fe.disable +../bin/occmd rffe.ch2_fe.enable +../bin/occmd testmodule.2gsim.enable +../bin/occmd testmodule.2gsim.disable +../bin/occmd sdr.comp_all.reset +../bin/occmd sdr.fx3.reset +../bin/occmd ethernet.port0.en_loopBk 0 +../bin/occmd ethernet.port0.en_pktGen 8374 +../bin/occmd ethernet.port0.dis_pktGen +../bin/occmd ethernet.port0.dis_loopBk 0 +../bin/occmd ethernet.port1.en_loopBk 0 +../bin/occmd ethernet.port1.en_pktGen 8374 +../bin/occmd ethernet.port1.dis_pktGen +../bin/occmd ethernet.port1.dis_loopBk 0 +../bin/occmd ethernet.port2.en_loopBk 0 +../bin/occmd ethernet.port2.en_pktGen 8374 +../bin/occmd ethernet.port2.dis_pktGen +../bin/occmd ethernet.port2.dis_loopBk 0 +../bin/occmd ethernet.port3.en_loopBk 0 +../bin/occmd ethernet.port3.en_pktGen 8374 +../bin/occmd ethernet.port3.dis_pktGen +../bin/occmd ethernet.port3.dis_loopBk 0 +../bin/occmd ethernet.port4.en_loopBk 0 +../bin/occmd ethernet.port4.en_pktGen 8374 +../bin/occmd ethernet.port4.dis_pktGen +../bin/occmd ethernet.port4.dis_loopBk 0 +else + echo "Invalid Option" +fi +elif [ $1 = "debug" ]; then +if [ $2 = "I2C" ]; then +../bin/occmd debug.I2C.bus0.get 104 2 58 +../bin/occmd debug.I2C.bus1.get 24 2 2 +../bin/occmd debug.I2C.bus2.get 29 1 0 +../bin/occmd debug.I2C.bus3.get 68 2 255 +../bin/occmd debug.I2C.bus4.get 65 2 254 +../bin/occmd debug.I2C.bus6.get 64 2 5 +../bin/occmd debug.I2C.bus7.get 69 2 5 +../bin/occmd debug.I2C.bus8.get 26 2 6 +elif [ $2 = "GPIO" ]; then +../bin/occmd debug.ec.PA.get 1 +../bin/occmd debug.ec.PB.get 1 +../bin/occmd debug.ec.PC.get 1 +../bin/occmd debug.ec.PD.get 7 +../bin/occmd debug.ec.PE.get 1 +../bin/occmd debug.ec.PF.get 1 +../bin/occmd debug.ec.PG.get 1 +../bin/occmd debug.ec.PJ.get 1 +../bin/occmd debug.ec.PK.get 1 +../bin/occmd debug.ec.PL.get 5 +../bin/occmd debug.ec.PM.get 1 +../bin/occmd debug.ec.PN.get 1 +../bin/occmd debug.ec.PP.get 3 +../bin/occmd debug.ec.PQ.get 1 +../bin/occmd debug.gbc.ioexpanderx70.get 1 +../bin/occmd debug.gbc.ioexpanderx71.get 0 +../bin/occmd debug.sdr.ioexpanderx1E.get 1 +../bin/occmd debug.fe.ioexpanderx18.get 1 +../bin/occmd debug.fe.ioexpanderx1A.get 0 +../bin/occmd debug.fe.ioexpanderx1B.get 1 +../bin/occmd debug.fe.ioexpanderx1C.get 1 +../bin/occmd debug.fe.ioexpanderx1D.get 1 +../bin/occmd debug.sync.ioexpanderx71.get 1 +elif [ $2 = "MDIO" ]; then +../bin/occmd debug.ethernet.port0.get 1 +../bin/occmd debug.ethernet.port1.get 1 +../bin/occmd debug.ethernet.port2.get 1 +../bin/occmd debug.ethernet.port3.get 1 +../bin/occmd debug.ethernet.port4.get 1 +../bin/occmd debug.ethernet.global1.get 1 +../bin/occmd debug.ethernet.global2.get 1 +../bin/occmd debug.ethernet.swport0.get 1 +../bin/occmd debug.ethernet.swport1.get 1 +../bin/occmd debug.ethernet.swport2.get 1 +../bin/occmd debug.ethernet.swport3.get 1 +../bin/occmd debug.ethernet.swport4.get 1 +../bin/occmd debug.ethernet.swport5.get 1 +../bin/occmd debug.ethernet.swport6.get 1 +else + echo "Invalid Option" +fi +else + echo "Invalid Option" +fi + +echo "Done..." diff --git a/firmware/host/ocwarestub/ocware_stub_database.c b/firmware/host/ocwarestub/ocware_stub_database.c new file mode 100755 index 0000000000..3bfc7037de --- /dev/null +++ b/firmware/host/ocwarestub/ocware_stub_database.c @@ -0,0 +1,1117 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include +#include + +static OCWareStubsizeflag s_typeFlag; +static OCWareStubDatabase s_ocwareGlobalData[MAX_NUMBER_PARAM]; +static OCWareStubPostData s_postGlobalArray[MAX_POST_DEVICE]; + +static int16_t s_defInt16Val = DEFAULT_INT16; +static int64_t s_defInt64Val = DEFAULT_INT64; +static int8_t s_defInt8Val = DEFAULT_INT8; +static int32_t s_defInt32Val = DEFAULT_INT32; +static int8_t s_defEnumVal = DEFAULT_ENUM; +static int8_t s_debugSubsystem = 0; + +int8_t debugGetCommand = STUB_FAILED; +int8_t debugSetCommand = STUB_FAILED; +int8_t PostResult = STUB_FAILED; +int8_t PostEnable = STUB_FAILED; +extern const Component sys_schema[]; +/****************************************************************************** + * Function Name : ocware_stub_set_gpioinfo + * Description : Modify the GPIO information in the DB for debug subsystem + * + * @param gStructIndex - Index of the database (by value) + * @param payload - payload field of the message from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_set_gpioinfo(int16_t gStructIndex, + char *payload) +{ + OCWareDebugGPIOinfo **GPIOInfo; + ocware_stub_ret ret = STUB_FAILED; + int8_t pos = 0; + int8_t index = 0; + + if (!(gStructIndex <= MAX_NUMBER_PARAM && payload)) { + return ret; + } + + GPIOInfo = (OCWareDebugGPIOinfo**)&s_ocwareGlobalData[gStructIndex].data; + for(index = 0; index< MAX_GPIO_COMP_NBR; index++) { + if (GPIOInfo[index]->pin_nbr == payload[pos]) { + ret = STUB_SUCCESS; + GPIOInfo[index]->value = payload[pos + 1]; + break; + } + } + + return ret; +} + +/****************************************************************************** + * Function Name : ocware_stub_set_i2cinfo + * Description : Modify the I2C information in the DB for debug subsystem + * + * @param gStructIndex - Index of the database (by value) + * @param payload - payload field of the message from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_set_i2cinfo(int16_t gStructIndex, + char *payload) +{ + OCWareDebugI2Cinfo **I2CInfo; + ocware_stub_ret ret = STUB_FAILED; + int8_t pos = 0; + int8_t index = 0; + if (!(gStructIndex <= MAX_NUMBER_PARAM && payload)) { + return ret; + } + I2CInfo = (OCWareDebugI2Cinfo **)&s_ocwareGlobalData[gStructIndex].data; + for(index = 0; index < MAX_I2C_COMP_NBR; index++) { + if (I2CInfo[index]->slaveAddress == payload[pos]) { + ret = STUB_SUCCESS; + break; + } + } + + if (ret !=STUB_SUCCESS) + return ret; + + I2CInfo[index]->slaveAddress = payload[pos]; + I2CInfo[index]->numOfBytes = payload[pos + 1]; + I2CInfo[index]->regAddress = payload[pos + 2]; + if (I2CInfo[index]->numOfBytes == 1) { + I2CInfo[index]->regValue = payload[pos + 3]; + } else { + I2CInfo[index]->regValue = ((uint8_t)payload[pos + 3] << 0x08) + + payload[pos + 4]; + payload[pos + 4] = + (uint8_t)(I2CInfo[index]->regValue & MASK_LSB); + payload[pos + 3] = + (uint8_t)((I2CInfo[index]->regValue & MASK_MSB) >> SHIFT_NIBBLE); + } + return ret; +} +/****************************************************************************** + * Function Name : ocware_stub_set_mdioinfo + * Description : Modify the MDIO information in the DB for debug subsystem + * + * @param gStructIndex - Index of the database (by value) + * @param payload - payload field of the message from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_set_mdioinfo(int16_t gStructIndex, + char *payload) +{ + OCWareDebugMDIOinfo **MDIOInfo; + ocware_stub_ret ret = STUB_FAILED; + int8_t pos = 0; + int8_t index = 0; + if (!(gStructIndex <= MAX_NUMBER_PARAM && payload)) { + return ret; + } + MDIOInfo = (OCWareDebugMDIOinfo **)&s_ocwareGlobalData[gStructIndex].data; + for(index = 0; index< MAX_MDIO_COMP_NBR; index++) { + if (MDIOInfo[index]->regAddress == payload[pos]) { + ret = STUB_SUCCESS; + break; + } + } + if (ret !=STUB_SUCCESS) + return ret; + + MDIOInfo[index]->regAddress = payload[pos]; + MDIOInfo[index]->regValue = ((uint8_t)payload[pos + 3] << 0x08) + + payload[pos + 2]; + payload[pos + 2] = + (uint8_t)(MDIOInfo[index]->regValue & MASK_LSB); + payload[pos + 3] = + (uint8_t)((MDIOInfo[index]->regValue & MASK_MSB) >> SHIFT_NIBBLE); + return ret; +} +/****************************************************************************** + * Function Name : ocware_stub_get_post_database + * Description : extract device number and status from the post database + * depending on the subsytem id + * + * @param msgFrameData - output pointer to the OCMPheader field of the message + * from MW (by reference) + * @param payload - output pointer to the payload field of the message from MW + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_post_database(OCMPMessage *msgFrameData, + char *payload) +{ + int16_t index = 0; + uint8_t pos = 0; + + for(index = 0; index < MAX_POST_DEVICE; index++) { + if ((s_postGlobalArray[index].SubsystemId + == payload[0]) && + (s_postGlobalArray[index].DeviceNumber > 0)) { + + payload[pos] = s_postGlobalArray[index].SubsystemId; + payload[pos + 1] = + s_postGlobalArray[index].DeviceNumber; + payload[pos + 2] = + s_postGlobalArray[index].Status; + pos = pos + 3; + } + } + msgFrameData->parameters = pos/3; + return STUB_SUCCESS; +} +/****************************************************************************** + * Function Name : ocware_stub_get_gpioinfo + * Description : retrieve the GPIO information in the DB for debug + * subsystem + * + * @param gStructIndex index of the database (by value) + * @param payload output pointer to the payload filed of the + * message from MW (by pointer) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_gpioinfo(int16_t gStructIndex, + char *payload) +{ + OCWareDebugGPIOinfo **GPIOInfo; + ocware_stub_ret ret = STUB_FAILED; + uint8_t pos = 0; + uint8_t index = 0; + + if (!(gStructIndex <= MAX_NUMBER_PARAM && payload)) { + return ret; + } + GPIOInfo = (OCWareDebugGPIOinfo**)&s_ocwareGlobalData[gStructIndex].data; + for(index = 0; index< MAX_GPIO_COMP_NBR; index++) { + if (GPIOInfo[index]->pin_nbr == payload[pos]) { + ret = STUB_SUCCESS; + break; + } + } + + if(ret == STUB_SUCCESS) { + payload[pos] = GPIOInfo[index]->pin_nbr; + payload[pos + 1] = GPIOInfo[index]->value; + } + return ret; +} +/****************************************************************************** + * Function Name : ocware_stub_get_i2cinfo + * Description : retrieve the I2C information in the DB for debug + * subsystem + * + * @param gStructIndex index of the database (by value) + * @param payload output pointer to the payload filed of the + * message from MW (by pointer) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_i2cinfo(int16_t gStructIndex, + char *payload) +{ + OCWareDebugI2Cinfo **I2CInfo; + ocware_stub_ret ret = STUB_FAILED; + uint8_t pos = 0; + uint8_t index = 0; + + if (!(gStructIndex <= MAX_NUMBER_PARAM && payload)) { + return ret; + } + + I2CInfo = (OCWareDebugI2Cinfo**)&s_ocwareGlobalData[gStructIndex].data; + for(index = 0; index< MAX_I2C_COMP_NBR; index++) { + if (I2CInfo[index]->slaveAddress == payload[pos]) { + ret = STUB_SUCCESS; + break; + } + } + + if(ret == STUB_SUCCESS) { + payload[pos] = I2CInfo[index]->slaveAddress; + payload[pos + 1] = I2CInfo[index]->numOfBytes; + payload[pos + 2] = I2CInfo[index]->regAddress; + if (I2CInfo[index]->numOfBytes == 1) { + payload[pos + 3] = (uint8_t)I2CInfo[index]->regValue; + } else { + payload[pos + 4] + = (uint8_t)(I2CInfo[index]->regValue & MASK_LSB); + payload[pos + 3] = (uint8_t) + ((I2CInfo[index]->regValue & MASK_MSB) >> SHIFT_NIBBLE); + } + } + return ret; +} +/****************************************************************************** + * Function Name : ocware_stub_get_mdioinfo + * Description : retrieve the MDIO information in the DB for debug + * subsystem + * + * @param gStructIndex index of the database (by value) + * @param payload output pointer to the payload filed of the + * message from MW (by pointer) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_mdioinfo(int16_t gStructIndex, + char *payload) +{ + OCWareDebugMDIOinfo **MDIOInfo; + ocware_stub_ret ret = STUB_FAILED; + uint8_t pos = 0; + uint8_t index = 0; + + if (!(gStructIndex <= MAX_NUMBER_PARAM && payload)) { + return ret; + } + + MDIOInfo = (OCWareDebugMDIOinfo**)&s_ocwareGlobalData[gStructIndex].data; + for(index = 0; index < MAX_MDIO_COMP_NBR; index++) { + if (MDIOInfo[index]->regAddress == payload[pos]) { + ret = STUB_SUCCESS; + break; + } + } + + if(ret == STUB_SUCCESS) { + payload[pos] = MDIOInfo[index]->regAddress; + payload[pos + 2] = (uint8_t) + (MDIOInfo[index]->regValue & MASK_LSB); + payload[pos + 3] = (uint8_t) + ((MDIOInfo[index]->regValue & MASK_MSB) >> SHIFT_NIBBLE); + } + return ret; +} +/****************************************************************************** + * Function Name : ocware_stub_debug_subsytem + * Description : Process the command message for debug subsytem + * + * @param gStructIndex - index to the DB (by value) + * @param payload - output pointer to the payload field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_debug_subsytem(int16_t gStructIndex, + char *payload, + int8_t flag) +{ + if (!(gStructIndex <= MAX_NUMBER_PARAM && payload)) { + return STUB_FAILED; + } + switch(s_ocwareGlobalData[gStructIndex].componentId) { + case 2: + if ( flag == OCMP_AXN_TYPE_GET) { + ocware_stub_get_i2cinfo(gStructIndex, payload); + } else { + ocware_stub_set_i2cinfo(gStructIndex, payload); + } + break; + case 8: + if ( flag == OCMP_AXN_TYPE_GET) { + ocware_stub_get_mdioinfo(gStructIndex, payload); + } else { + ocware_stub_set_mdioinfo(gStructIndex, payload); + } + break; + default: + if ( flag == OCMP_AXN_TYPE_GET) { + ocware_stub_get_gpioinfo(gStructIndex, payload); + } else { + ocware_stub_set_gpioinfo(gStructIndex, payload); + } + } + return STUB_SUCCESS; +} +/****************************************************************************** + * Function Name : ocware_stub_get_database + * Description : Function to retrieve data from the DB + * + * @param msgFrameData - Pointer to the message frame field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_database(OCMPMessage *msgFrameData) +{ + char *payload = NULL; + ocware_stub_ret ret = STUB_FAILED; + int8_t subsystem = 0; + int8_t component = 0; + int8_t msgtype = 0; + int8_t parampos = 0; + int16_t paramId = 0; + int16_t gStructIndex = 0; + + if(msgFrameData == NULL) { + return ret; + } + payload = (char*)&msgFrameData->info; + subsystem = msgFrameData->subsystem; + component = msgFrameData->componentID; + msgtype = msgFrameData->msgtype; + paramId = msgFrameData->parameters; + + for(gStructIndex = 0; gStructIndex < MAX_NUMBER_PARAM; gStructIndex++) { + if((subsystem == s_ocwareGlobalData[gStructIndex].subsystemId) && + (component == s_ocwareGlobalData[gStructIndex].componentId) && + (msgtype == s_ocwareGlobalData[gStructIndex].msgtype) && + (paramId == s_ocwareGlobalData[gStructIndex].paramId)) + { + ret = STUB_SUCCESS; + parampos = s_ocwareGlobalData[gStructIndex].paramPos; + break; + } + } + + if(ret == STUB_SUCCESS) { + if(subsystem == s_debugSubsystem) { + ret = ocware_stub_debug_subsytem(gStructIndex, payload, + OCMP_AXN_TYPE_GET); + } else { + strncpy(&payload[parampos], + (char*)s_ocwareGlobalData[gStructIndex].data, + s_ocwareGlobalData[gStructIndex].paramSize); + } + } + return ret; +} + +/****************************************************************************** + * Function Name : ocware_stub_set_database + * Description : Function to modify data in the DB + * + * @param msgFrameData - Pointer to the message frame field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_set_database(OCMPMessage *msgFrameData) +{ + char *payload = NULL; + ocware_stub_ret ret = STUB_FAILED; + int8_t subsystem = 0; + int8_t component = 0; + int8_t msgtype = 0; + int8_t parampos = 0; + int16_t paramId = 0; + int16_t gStructIndex = 0; + + if(msgFrameData == NULL) { + return ret; + } + payload = (char*)&msgFrameData->info; + subsystem = msgFrameData->subsystem; + component = msgFrameData->componentID; + msgtype = msgFrameData->msgtype; + paramId = msgFrameData->parameters; + + for(gStructIndex = 0; gStructIndex < MAX_NUMBER_PARAM; gStructIndex++) { + if( (subsystem == s_ocwareGlobalData[gStructIndex].subsystemId) && + (component == s_ocwareGlobalData[gStructIndex].componentId) && + (msgtype == s_ocwareGlobalData[gStructIndex].msgtype) && + (paramId == s_ocwareGlobalData[gStructIndex].paramId)) + { + ret = STUB_SUCCESS; + parampos = s_ocwareGlobalData[gStructIndex].paramPos; + break; + } + } + + if(ret == STUB_SUCCESS) { + if(subsystem == s_debugSubsystem) { + ret = ocware_stub_debug_subsytem(gStructIndex, payload, + OCMP_AXN_TYPE_SET); + } else { + strncpy((char*)s_ocwareGlobalData[gStructIndex].data, + &payload[parampos], + s_ocwareGlobalData[gStructIndex].paramSize); + } + } + return ret; +} + +/****************************************************************************** + * Function Name : ocware_stub_fill_init_value + * Description : Function to fill default value in the DB + * + * @param param - pointer to the parameter field in a particular subsytem and + * component (by value) + * gStructIndex - index to the DB (by value) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_fill_init_value(const Parameter *param, + uint16_t gStructIndex) +{ + const char *paramtype; + int16_t def_lasterror = 0x101; + int16_t def_netOp = 0x001; + + if(param == NULL) { + return STUB_FAILED; + } + + paramtype = DATA_TYPE_MAP[param->type]; + + if (!strcmp("lasterror",param->name)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char*)&def_lasterror); + return STUB_SUCCESS; + } else if (!strcmp("network_operatorinfo",param->name)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char*)&def_netOp); + return STUB_SUCCESS; + } + if (!strcmp("uint16",paramtype)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char *)&s_defInt16Val); + } else if (!strcmp("int16",paramtype)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char*)&s_defInt16Val); + } else if (!strcmp("uint8",paramtype)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char*)&s_defInt8Val); + } else if (!strcmp("int8",paramtype)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char*)&s_defInt8Val); + } else if (!strcmp("uint32",paramtype)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char*)&s_defInt32Val); + } else if (!strcmp("uint64",paramtype)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char *)&s_defInt64Val); + } else if (!strcmp("string",paramtype)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, DEFAULT_STRING); + } else if (!strcmp("enum",paramtype)) { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char*)&s_defEnumVal); + } else { + strcpy(s_ocwareGlobalData[gStructIndex].data, (char*)&s_defInt8Val); + } + return STUB_SUCCESS; +} +/****************************************************************************** + * Function Name : ocware_stub_get_paramSize + * Description : Return the size of the parameter + * + * @param paramtype - pointer to a particular parameter in the schema + * (by reference) + * msgtype - msgtype field of the message from MW (by value) + * param_name - pointer to the name of a parameter in the schema + * (by reference) + * @return Size of the parameter + * + ******************************************************************************/ +int8_t ocware_stub_get_paramSize(const char* paramtype, + int8_t msgtype, + const char* param_name) +{ + int8_t paramSize = 0; + + if (paramtype == NULL) { + printf("Invalid paramtype\n"); + return STUB_FAILED; + } + + if (!strcmp("uint16",paramtype)) { + paramSize = sizeof(uint16_t); + } else if (!strcmp("int16",paramtype)) { + paramSize = sizeof(int16_t); + } else if (!strcmp("uint8",paramtype)) { + paramSize = sizeof(uint8_t); + } else if (!strcmp("int8",paramtype)) { + paramSize = sizeof(int8_t); + } else if (!strcmp("uint32",paramtype)) { + paramSize = sizeof(uint32_t); + } else if (!strcmp("uint64",paramtype)) { + paramSize = sizeof(uint64_t); + } else if (!strcmp("string",paramtype)) { + if (s_typeFlag == OCSTUB_VALUE_TYPE_MFG) { + paramSize = SIZE_OF_TYPE_MFG; + } else if (s_typeFlag == OCSTUB_VALUE_TYPE_MODEL) { + paramSize = SIZE_OF_TYPE_MODEL; + } else if (s_typeFlag == OCSTUB_VALUE_TYPE_GETMODEL) { + paramSize = SIZE_OF_TYPE_GETMODEL; + } else if (s_typeFlag == OCSTUB_VALUE_TYPE_OCSERIAL_INFO) { + paramSize = SIZE_OF_TYPE_OCSERIAL_INFO; + } else if (s_typeFlag == OCSTUB_VALUE_TYPE_GBCBOARD_INFO) { + paramSize = SIZE_OF_TYPE_GBCBOARD_INFO; + } else { + if (msgtype == OCMP_MSG_TYPE_CONFIG) { + paramSize = EEPROM_CONFIG_MAX_SIZE; + } else if (msgtype == OCMP_MSG_TYPE_STATUS) { + paramSize = EEPROM_STATUS_MAX_SIZE; + } + } + } else if (!strcmp("enum",paramtype)) { + if (s_typeFlag == OCSTUB_VALUE_TYPE_REGISTRATION) { + paramSize = SIZE_OF_TYPE_REGISTRATION; /* TO DO */ + } else if (s_typeFlag == OCSTUB_VALUE_TYPE_NWOP_STRUCT) { + paramSize = SIZE_OF_NWOP_STRUCT; + } else if (s_typeFlag == OCSTUB_VALUE_TYPE_LAST_ERROR) { + paramSize = SIZE_OF_LAST_ERROR; + } else { + paramSize = OCMW_VALUE_TYPE_ENUM; + } + } else { + paramSize = sizeof(int8_t); + } + + return paramSize; +} +/****************************************************************************** + * Function Name : ocware_stub_fill_init_debug_value + * Description : Fill default values for debug subsytem + * + * @param gStructIndex - index to the DB (by value) + * flag - OCSTUB_VALUE_TYPE_GPIO_DEBUG -To modify GPIO parameters + * OCSTUB_VALUE_TYPE_I2C_DEBUG - To modify I2C parameters + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_fill_init_debug_value(int16_t gStructIndex, + OCWareStubsizeflag flag) +{ + OCWareDebugI2Cinfo I2CInfo[MAX_I2C_COMP_NBR]; + OCWareDebugGPIOinfo GPIOInfo[MAX_GPIO_COMP_NBR]; + OCWareDebugMDIOinfo MDIOInfo[MAX_MDIO_COMP_NBR]; + uint8_t index = 0; + + if(gStructIndex >= MAX_NUMBER_PARAM) { + return STUB_FAILED; + } + if ( flag == OCSTUB_VALUE_TYPE_GPIO_DEBUG) { + for(index = 0; index < MAX_GPIO_COMP_NBR; index++) { + GPIOInfo[index].pin_nbr = GPIO_PIN_NBR + index; + GPIOInfo[index].value = GPIO_VALUE; + } + memcpy(s_ocwareGlobalData[gStructIndex].data, + (char *)GPIOInfo, sizeof(GPIOInfo)*MAX_GPIO_COMP_NBR); + + } else if ( flag == OCSTUB_VALUE_TYPE_MDIO_DEBUG){ + for(index = 0; index < MAX_MDIO_COMP_NBR; index++) { + MDIOInfo[index].regAddress = I2C_REG_ADDRESS + index; + MDIOInfo[index].regValue = I2C_REG_VALUE; + } + memcpy(s_ocwareGlobalData[gStructIndex].data, + (char *)MDIOInfo, sizeof(MDIOInfo)*MAX_MDIO_COMP_NBR); + }else { + for(index = 0; index < MAX_I2C_COMP_NBR; index++) { + I2CInfo[index].slaveAddress = I2C_SLAVE_ADDRESS + index; + I2CInfo[index].numOfBytes = I2C_NUM_BYTES; + I2CInfo[index].regAddress = I2C_REG_ADDRESS; + I2CInfo[index].regValue = I2C_REG_VALUE; + } + memcpy(s_ocwareGlobalData[gStructIndex].data, + (char *)I2CInfo, sizeof(I2CInfo)*MAX_I2C_COMP_NBR); + } + + return STUB_SUCCESS; +} + +/****************************************************************************** + * Function Name : ocware_create_command_debug_database + * Description : Create entries into the DB for debug subsystem + * + * @param : subsystemNbr - subsytem number in the schema (by value) + * gStructIndex - output pointer to the index in the DB (by reference) + * subSystem - pointer to the debug subsytem in the schema + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_create_command_debug_database(int8_t subsystemNbr, + int16_t *gStructIndex, + const Component *subSystem) +{ + ocware_stub_ret ret = STUB_FAILED; + const Component *component = NULL; + const Component *subComponent = NULL; + const Driver *driver = NULL; + const Command *command = NULL; + int8_t componentNbr = 1; + int8_t count = 0; + int8_t commandCount = 0; + s_debugSubsystem = subsystemNbr; + + if((gStructIndex == NULL) || (subSystem == NULL)) { + return STUB_FAILED; + } + for(component = subSystem->components; component && component->name; + component++) { + /* component loop */ + subComponent = component->components; + count = 1; + while (subComponent && subComponent->name) { + driver = subComponent->driver; + if(driver !=NULL) { + /* No Need to read every command as + * current implementation is to have one entry + * for one subsystem + */ + s_ocwareGlobalData[*gStructIndex].subsystemId = subsystemNbr; + s_ocwareGlobalData[*gStructIndex].componentId = componentNbr; + s_ocwareGlobalData[*gStructIndex].msgtype = + OCMP_MSG_TYPE_COMMAND; + s_ocwareGlobalData[*gStructIndex].paramPos = 0; + + if (strncmp(component->name,"I2C", + strlen("I2C")) == 0) { + s_ocwareGlobalData[*gStructIndex].paramId = count; + s_ocwareGlobalData[*gStructIndex].paramSize + = sizeof(OCWareDebugI2Cinfo) * MAX_I2C_COMP_NBR; + s_ocwareGlobalData[*gStructIndex].data + = malloc(s_ocwareGlobalData[*gStructIndex].paramSize); + if (s_ocwareGlobalData[*gStructIndex].data == NULL) { + printf("Malloc failed\n"); + return STUB_FAILED; + } else { + memset(s_ocwareGlobalData[*gStructIndex].data, 0, + s_ocwareGlobalData[*gStructIndex].paramSize); + } + ret = ocware_stub_fill_init_debug_value(*gStructIndex, + OCSTUB_VALUE_TYPE_I2C_DEBUG); + } else if (strncmp(component->name,"ethernet", + strlen("ethernet")) == 0) { + s_ocwareGlobalData[*gStructIndex].paramId = count; + s_ocwareGlobalData[*gStructIndex].paramSize + = sizeof(OCWareDebugMDIOinfo) * MAX_MDIO_COMP_NBR; + s_ocwareGlobalData[*gStructIndex].data + = malloc(s_ocwareGlobalData[*gStructIndex].paramSize); + if (s_ocwareGlobalData[*gStructIndex].data == NULL) { + printf("Malloc failed\n"); + return STUB_FAILED; + } else { + memset(s_ocwareGlobalData[*gStructIndex].data, 0, + s_ocwareGlobalData[*gStructIndex].paramSize); + } + ret = ocware_stub_fill_init_debug_value(*gStructIndex, + OCSTUB_VALUE_TYPE_MDIO_DEBUG); + + } else { + /* Currently its all GPIO */ + s_ocwareGlobalData[*gStructIndex].paramId = count; + s_ocwareGlobalData[*gStructIndex].paramSize + = sizeof(OCWareDebugGPIOinfo) * MAX_GPIO_COMP_NBR; + s_ocwareGlobalData[*gStructIndex].data + = malloc(s_ocwareGlobalData[*gStructIndex].paramSize); + if (s_ocwareGlobalData[*gStructIndex].data == NULL) { + printf("Malloc failed\n"); + return STUB_FAILED; + } else { + memset(s_ocwareGlobalData[*gStructIndex].data, 0, + s_ocwareGlobalData[*gStructIndex].paramSize); + } + ret = ocware_stub_fill_init_debug_value(*gStructIndex, + OCSTUB_VALUE_TYPE_GPIO_DEBUG); + } + (*gStructIndex)++; + if((debugGetCommand == STUB_FAILED) || + (debugSetCommand == STUB_FAILED)) { + command = driver->commands; + commandCount = 0; + while(command && command->name) { + if ((strncmp(command->name, "get", strlen("get"))) == + 0) { + debugGetCommand = commandCount; + } else if ((strncmp(command->name, "set",strlen("set"))) + == 0) { + debugSetCommand = commandCount; + } + command += 1; + commandCount++; + } + } + } + subComponent += 1; + count ++; + } + componentNbr++; + } + return ret; +} +/****************************************************************************** + * Function Name : ocware_stub_create_post_database + * Description : Parse the schema and add post entries + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + *****************************************************************************/ +ocware_stub_ret ocware_stub_create_post_database() +{ + int8_t subsystemNbr = 0; + const Component *component = NULL; + const Component *subComponent = NULL; + const Component *subSystem = NULL; + int8_t count = 1; + int16_t PostIndex = 0; + + for (subSystem = sys_schema; subSystem && subSystem->name; subSystem++) { + /* Subsystem loop */ + count = 1; + for(component = subSystem->components; component && component->name; + component++) { + /* component loop */ + subComponent = component->components; + if ((subComponent == NULL) && + (component->postDisabled != POST_DISABLED)) { + s_postGlobalArray[PostIndex].SubsystemId = subsystemNbr; + s_postGlobalArray[PostIndex].DeviceNumber = count; + if(count < 10) { + s_postGlobalArray[PostIndex].Status = count - 1; + } else { + s_postGlobalArray[PostIndex].Status = 9; + } + PostIndex++; + count++; + } + /* If subcomponents exist */ + while (subComponent && subComponent->name) { + if (subComponent->postDisabled != POST_DISABLED) { + s_postGlobalArray[PostIndex].SubsystemId = subsystemNbr; + s_postGlobalArray[PostIndex].DeviceNumber = count; + if(count < 10) { + s_postGlobalArray[PostIndex].Status = count - 1; + } else { + s_postGlobalArray[PostIndex].Status = 9; + } + PostIndex++; + count++; + } + subComponent += 1; + } /* sub comp loop */ + } /* component loop */ + subsystemNbr++; + }/*subsystem loop */ + return STUB_SUCCESS; +} + +/****************************************************************************** + * Function Name : ocware_stub_init_post + * Description : Calculate the param id for post messages + * + * @param devDriver - pointer to the post driver + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + *****************************************************************************/ +ocware_stub_ret ocware_stub_init_post(const Driver *devDriver) +{ + ocware_stub_ret ret = STUB_FAILED; + const Post *post = NULL; + uint16_t count = 0; + + if(devDriver == NULL) + return ret; + + post = devDriver->post; + while (post && post->name) { + if (strncmp(post->name, "results", + strlen(post->name)) == 0) { + PostResult = pow(2, count); + } else if (strncmp(post->name, "enable", + strlen(post->name)) == 0) { + PostEnable = pow(2, count); + } else { + printf("Post init failed\n"); + return ret; + } + count++; + post++; + } + + if ((PostResult != STUB_FAILED) && + (PostEnable != STUB_FAILED)) { + ret = STUB_SUCCESS; + } else { + printf("Post init failed\n"); + } + return ret; +} + +/****************************************************************************** + * Function Name : ocware_stub_init_database + * Description : Parse the schema and add entries in the DB + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_init_database() +{ + + ocware_stub_ret ret = STUB_FAILED; + int8_t subsystemNbr = 0; + int8_t componentNbr = 0; + const Component *component = NULL; + const Component *subComponent = NULL; + const Component *subSystem = NULL; + const Driver *devDriver = NULL; + const Parameter *param = NULL; + int8_t count = 0; + int8_t configCount = 0; + int8_t statusCount = 0; + int16_t gStructIndex = 0; + int16_t paramPos = 0; + int16_t configParamPos = 0; + int16_t statusParamPos = 0; + + for (subSystem = sys_schema; subSystem && subSystem->name; subSystem++) { + /* Subsystem loop */ + componentNbr = 1; + if (strncmp(subSystem->name, "debug", + strlen(subSystem->name)) == 0) { + ocware_create_command_debug_database(subsystemNbr, + &gStructIndex, subSystem); + } + for(component = subSystem->components; component && component->name; + component++) { + /* component loop */ + devDriver = component->driver; + if (devDriver != NULL) { + if (devDriver->post != NULL) { + /* POST is currently designed to be existing in one driver */ + ret = ocware_stub_init_post(devDriver); + + if(ret != STUB_SUCCESS) + return ret; + } + /* This is for componenets w/o any sub component */ + count = 0; + paramPos = 0; + param = devDriver->config; + /* Config related parameters */ + while (param && param->name) { /*Parameter loop */ + s_ocwareGlobalData[gStructIndex].subsystemId = subsystemNbr; + s_ocwareGlobalData[gStructIndex].componentId = componentNbr; + s_ocwareGlobalData[gStructIndex].paramId + = pow(2,count); + s_ocwareGlobalData[gStructIndex].paramSize = + ocware_stub_get_paramSize ( + DATA_TYPE_MAP[param->type], + OCMP_MSG_TYPE_CONFIG, param->name); + s_ocwareGlobalData[gStructIndex].msgtype = + OCMP_MSG_TYPE_CONFIG; + s_ocwareGlobalData[gStructIndex].paramPos = paramPos; + s_ocwareGlobalData[gStructIndex].data = malloc(sizeof(char)* + s_ocwareGlobalData[gStructIndex].paramSize); + if (s_ocwareGlobalData[gStructIndex].data == NULL) { + printf("Malloc failed\n"); + return STUB_FAILED; + } else { + memset(s_ocwareGlobalData[gStructIndex].data, 0, + s_ocwareGlobalData[gStructIndex].paramSize); + } + ocware_stub_fill_init_value(param, gStructIndex); + paramPos += s_ocwareGlobalData[gStructIndex].paramSize; + gStructIndex++; + param += 1; + count = count + 1; + } + count = 0; + paramPos = 0; + param = devDriver->status; + /* Status related parameters */ + while (param && param->name) { /* Parameter loop */ + if ((strncmp(subSystem->name, "obc", + strlen(subSystem->name)) == 0) || + (strncmp(subSystem->name, "testmodule", + strlen(subSystem->name)) == 0) || + (strncmp(subSystem->name, "system", + strlen(subSystem->name)) == 0)) { + if (strncmp(param->name, "mfg", + strlen(param->name))== 0) { + s_typeFlag = OCSTUB_VALUE_TYPE_MFG; + } else if (strncmp(param->name, + "model", strlen(param->name)) == 0) { + if ((strncmp(subSystem->name, "testmodule", + strlen(subSystem->name))) == 0) { + s_typeFlag = OCSTUB_VALUE_TYPE_GETMODEL; + } else { + s_typeFlag = OCSTUB_VALUE_TYPE_MODEL; + } + } else if (strncmp(param->name, + "registration", strlen(param->name)) == 0) { + s_typeFlag = OCSTUB_VALUE_TYPE_REGISTRATION; + } else if(strncmp(param->name, "network_operatorinfo", + strlen(param->name)) == 0) { + s_typeFlag = + OCSTUB_VALUE_TYPE_NWOP_STRUCT; + } else if(strncmp(param->name, "lasterror", + strlen(param->name)) == 0) { + s_typeFlag = + OCSTUB_VALUE_TYPE_LAST_ERROR; + } else if(strncmp(param->name, "ocserialinfo", + strlen(param->name)) == 0) { + s_typeFlag = + OCSTUB_VALUE_TYPE_OCSERIAL_INFO; + } else if(strncmp(param->name, "gbcboardinfo", + strlen(param->name)) == 0) { + s_typeFlag = + OCSTUB_VALUE_TYPE_GBCBOARD_INFO; + } else { + } + } + s_ocwareGlobalData[gStructIndex].subsystemId = subsystemNbr; + s_ocwareGlobalData[gStructIndex].componentId = componentNbr; + s_ocwareGlobalData[gStructIndex].paramId = pow(2,count); + s_ocwareGlobalData[gStructIndex].paramSize = + ocware_stub_get_paramSize ( + DATA_TYPE_MAP[param->type], + OCMP_MSG_TYPE_STATUS, param->name); + s_ocwareGlobalData[gStructIndex].paramPos = paramPos; + s_ocwareGlobalData[gStructIndex].msgtype = + OCMP_MSG_TYPE_STATUS; + paramPos += s_ocwareGlobalData[gStructIndex].paramSize; + s_ocwareGlobalData[gStructIndex].data = malloc(sizeof(char)* + s_ocwareGlobalData[gStructIndex].paramSize); + if (s_ocwareGlobalData[gStructIndex].data == NULL) { + printf("Malloc failed\n"); + return STUB_FAILED; + } else { + memset(s_ocwareGlobalData[gStructIndex].data, 0, + s_ocwareGlobalData[gStructIndex].paramSize); + } + ocware_stub_fill_init_value(param, gStructIndex); + if ((strncmp(subSystem->name, "obc", + strlen(subSystem->name)) == 0) || + (strncmp(subSystem->name, "testmodule", + strlen(subSystem->name)) == 0)) { + s_ocwareGlobalData[gStructIndex].paramPos = 0; + } + gStructIndex++; + param += 1; + count = count + 1; + } + } + /* If subcomponents exist */ + configCount = 0; + configParamPos = 0; + statusCount = 0; + statusParamPos = 0; + subComponent = component->components; + + while (subComponent && subComponent->name) { + devDriver = subComponent->driver; + if(devDriver == NULL) { + subComponent += 1; + continue; + } + param = devDriver->config; + /* Config related parameters */ + while (param && param->name) { /*Parameter loop */ + s_ocwareGlobalData[gStructIndex].subsystemId = subsystemNbr; + s_ocwareGlobalData[gStructIndex].componentId = componentNbr; + s_ocwareGlobalData[gStructIndex].paramId + = pow(2,configCount); + s_ocwareGlobalData[gStructIndex].paramSize + = ocware_stub_get_paramSize ( + DATA_TYPE_MAP[param->type], + OCMP_MSG_TYPE_CONFIG, param->name); + s_ocwareGlobalData[gStructIndex].msgtype = + OCMP_MSG_TYPE_CONFIG; + s_ocwareGlobalData[gStructIndex].paramPos = configParamPos; + configParamPos += s_ocwareGlobalData[gStructIndex].paramSize; + s_ocwareGlobalData[gStructIndex].data + = malloc(s_ocwareGlobalData[gStructIndex].paramSize); + if (s_ocwareGlobalData[gStructIndex].data == NULL) { + printf("Malloc failed\n"); + return STUB_FAILED; + } else { + memset(s_ocwareGlobalData[gStructIndex].data, 0, + s_ocwareGlobalData[gStructIndex].paramSize); + } + ocware_stub_fill_init_value(param, gStructIndex); + gStructIndex++; + param += 1; + configCount += 1; + } + param = devDriver->status; + /* Status related parameters */ + while (param && param->name) { /* Parameter loop */ + s_ocwareGlobalData[gStructIndex].subsystemId = subsystemNbr; + s_ocwareGlobalData[gStructIndex].componentId = componentNbr; + s_ocwareGlobalData[gStructIndex].paramId + = pow(2,statusCount); + s_ocwareGlobalData[gStructIndex].paramSize + = ocware_stub_get_paramSize ( + DATA_TYPE_MAP[param->type], + OCMP_MSG_TYPE_STATUS, param->name); + s_ocwareGlobalData[gStructIndex].paramPos = statusParamPos; + s_ocwareGlobalData[gStructIndex].msgtype = + OCMP_MSG_TYPE_STATUS; + statusParamPos += s_ocwareGlobalData[gStructIndex].paramSize; + s_ocwareGlobalData[gStructIndex].data + = malloc(s_ocwareGlobalData[gStructIndex].paramSize); + if (s_ocwareGlobalData[gStructIndex].data == NULL) { + printf("Malloc failed\n"); + return STUB_FAILED; + } else { + memset(s_ocwareGlobalData[gStructIndex].data, 0, + s_ocwareGlobalData[gStructIndex].paramSize); + } + ocware_stub_fill_init_value(param, gStructIndex); + gStructIndex++; + param += 1; + statusCount += 1; + } + subComponent += 1; + } + componentNbr++; + } + subsystemNbr++; + } + ret = ocware_stub_create_post_database(); + return ret; +} + +/****************************************************************************** + * Function Name : ocware_stub_parse_command_message + * Description : Parse command messages from MW + * + * @param buffer - output pointer to the message from MW + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_parse_command_message(char *buffer) +{ + OCMPMessageFrame *msgFrame = (OCMPMessageFrame *)buffer; + OCMPMessage *msgFrameData = (OCMPMessage*)&msgFrame->message; + ocware_stub_ret ret = STUB_FAILED; + + if (buffer == NULL) { + return ret; + } + + /* + * The current logic is to return success for all commands other than + * the debug subsystem. For debug subsytem the commands are treated + * similar to the get/set logic used in config msg type + */ + ret = STUB_SUCCESS; + if(s_debugSubsystem == msgFrameData->subsystem) { + ocware_stub_parse_debug_actiontype(msgFrameData); + ret = ocware_stub_get_set_params(msgFrameData); + } + msgFrameData->action = OCMP_AXN_TYPE_REPLY; + return ret; +} diff --git a/firmware/host/ocwarestub/ocware_stub_eth_comm.c b/firmware/host/ocwarestub/ocware_stub_eth_comm.c new file mode 100755 index 0000000000..5ea8f5f95a --- /dev/null +++ b/firmware/host/ocwarestub/ocware_stub_eth_comm.c @@ -0,0 +1,135 @@ +#include +#include + +static int32_t s_stubSockFd; +static struct sockaddr_in s_ocmwStubServer; +/****************************************************************************** + * Function Name : ocware_stub_init_ethernet_comm + * Description : initialise the socket IPC + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_init_ethernet_comm(void) +{ + int32_t rc = 0; + int32_t inet_atom = 0; + + /* Create socket */ + s_stubSockFd = socket(OCMW_STUB_ETH_SOCK_DOMAIN, + OCMW_STUB_ETH_SOCK_TYPE, OCMW_STUB_ETH_SOCK_PROTOCOL); + if (s_stubSockFd < 0) { + printf("socket creation error [%d-%s]", errno, strerror(errno)); + return STUB_FAILED; + } + + /* Initialize socket structure */ + memset(&s_ocmwStubServer, 0, sizeof(s_ocmwStubServer)); + s_ocmwStubServer.sin_family = OCMW_STUB_ETH_SOCK_DOMAIN; + s_ocmwStubServer.sin_port = htons(OCMW_STUB_ETH_SOCK_SERVER_PORT); + s_ocmwStubServer.sin_addr.s_addr = inet_addr(OCMW_STUB_ETH_SOCK_SERVER_IP); + inet_atom = inet_aton(OCMW_STUB_ETH_SOCK_SERVER_IP, + &s_ocmwStubServer.sin_addr); + if (inet_atom == 0) { + printf("inet_aton failed"); + return STUB_FAILED; + } + memset(s_ocmwStubServer.sin_zero, '\0', sizeof(s_ocmwStubServer.sin_zero)); + + /*Bind socket with address struct*/ + rc = bind(s_stubSockFd, (struct sockaddr *) &s_ocmwStubServer, + sizeof(s_ocmwStubServer)); + if (rc != 0) { + ocware_stub_deinit_ethernet_comm(); + printf("Ehernet init failed \n"); + return STUB_FAILED; + } + + return STUB_SUCCESS; +} +/****************************************************************************** + * Function Name : ocware_stub_deinit_ethernet_comm + * Description : close the IPC socket + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_deinit_ethernet_comm() +{ + close(s_stubSockFd); + s_stubSockFd = 0; /* Close the IPC socket */ + + return STUB_SUCCESS; +} +/****************************************************************************** + * Function Name : ocware_stub_send_msgframe_middleware + * Description : send message to the MW + * + * @param bufferlen - length of the message (by value) + * @param buffer - pointer to the message to be sent to MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_send_msgframe_middleware(char **buffer, + int32_t bufferlen) +{ + int32_t rc = 0; + const int32_t errstr_len = OCWARE_STUB_ERR_STR_LEN; + char errstr[errstr_len]; + int8_t data[OC_EC_MSG_SIZE] = { 0 }; + int32_t dataLen = sizeof(s_ocmwStubServer); + + if (buffer == NULL) { + return STUB_FAILED; + } + + memcpy(data, *buffer, sizeof(data)); + + rc = sendto(s_stubSockFd, data, OC_EC_MSG_SIZE, 0, + (struct sockaddr *) &s_ocmwStubServer, + dataLen); + if (rc < 0) { + strerror_r(errno, errstr, errstr_len); + printf("Error: 'send' [%d-%s]", errno, errstr); + return STUB_FAILED; + } + + return STUB_SUCCESS; +} +/****************************************************************************** + * Function Name : ocware_stub_recv_msgfrom_middleware + * Description : Receive message from MW + * + * @param bufferlen - length of the message (by value) + * @param buffer - pointer to the location where the message from MW is to be + * stored for further processing (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_recv_msgfrom_middleware( + char **buffer, int32_t bufferlen) +{ + int32_t rc = 0; + const int32_t errstr_len = OCWARE_STUB_ERR_STR_LEN; + char errstr[errstr_len]; + int8_t data[OC_EC_MSG_SIZE] = { 0 }; + int32_t dataLen = sizeof(s_ocmwStubServer); + + if (buffer == NULL) { + return STUB_FAILED; + } + /* Receive the CLI command execution response string from OCMW over UDP socket */ + rc = recvfrom(s_stubSockFd, data, OC_EC_MSG_SIZE, + 0, (struct sockaddr *) &s_ocmwStubServer, + (socklen_t*)&dataLen); + if (rc < 0) { + strerror_r(rc, errstr, errstr_len); + logerr("Error: 'recv' [%d-%s]", rc, errstr); + return STUB_FAILED; + } + + memcpy(*buffer, data, sizeof(data)); + return STUB_SUCCESS; +} diff --git a/firmware/host/ocwarestub/ocware_stub_main_module.c b/firmware/host/ocwarestub/ocware_stub_main_module.c new file mode 100755 index 0000000000..bed773035d --- /dev/null +++ b/firmware/host/ocwarestub/ocware_stub_main_module.c @@ -0,0 +1,204 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#include + +/****************************************************************************** + * Function Name : ocware_stub_frame_newmsgframe + * Description : Frame the response packet from stub function + * + * @param buf - pointer to complete message from MW (by reference) + * @param option - success or failure (by value) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_frame_newmsgframe(char *buffer, int32_t option) +{ + int32_t ret = 0, index = 0; + OCMPMessageFrame *msgFrame = (OCMPMessageFrame *)buffer; + OCMPMessage *msgFrameData = (OCMPMessage*)&msgFrame->message; + + /* Frame the header packet for sending data to ec */ + msgFrame->header.ocmpFrameLen = 0; + msgFrame->header.ocmpInterface = OCMP_COMM_IFACE_ETHERNET; + msgFrame->header.ocmpSeqNumber = 0; + msgFrame->header.ocmpSof = OCMP_MSG_SOF; + msgFrame->header.ocmpTimestamp = 0; + + switch(msgFrameData->msgtype) { + + case OCMP_MSG_TYPE_COMMAND: + ret = ocware_stub_parse_command_message(buffer); + break; + + case OCMP_MSG_TYPE_POST: + ret = ocware_stub_parse_post_get_message(buffer); + break; + + default: + ret = ocware_stub_get_set_params(msgFrameData); + } + + if (ret == STUB_SUCCESS) { + /* Setting the action type as REPLY */ + msgFrame->message.action = OCMP_AXN_TYPE_REPLY; + printf(" \n Sending Data :\n"); + for (index = 0; index < OC_EC_MSG_SIZE; index++) { + printf("0x%x ", buffer[index] & 0xff); + } + } + return ret; +} +/****************************************************************************** + * Function Name : ocware_stub_validate_msgframe_header + * Description : validate the msgframe header + * + * @param buf - pointer to complete message from MW (by reference) + * @param msgFrameData - pointer to ocmpgeader field of the message from + * MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_validate_msgframe_header(char *buf, + OCMPMessage *msgFrameData) +{ + OCMPMessageFrame *MsgFrame = (OCMPMessageFrame *)buf; + OCMPHeader *header = (OCMPHeader *)&MsgFrame->header; + + if (header->ocmpFrameLen == 0) { + if (header->ocmpSeqNumber == 0) { + if (header->ocmpSof == OCMP_MSG_SOF) { + if (header->ocmpTimestamp == 0) { + memcpy(msgFrameData, &MsgFrame->message, + sizeof(OCMPMessage)); + return STUB_SUCCESS; + } + } + } + } + return STUB_FAILED; +} +/****************************************************************************** + * Function Name : host_ocstubmain_func + * Description : Handle all the functionality for stub + * + * @param argc - number of argunents passed (by value) + * @param argv - arguments passed when invoking stub (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +int32_t host_ocstubmain_func(int32_t argc, char *argv[]) +{ + int32_t rc = 0; + char *buffer = NULL; + int32_t loopCount = 0; + char *rootpath = NULL; + + OCMPMessageFrame *msgFrame = NULL; + rc = ocware_stub_init_ethernet_comm(); + if ( rc != STUB_SUCCESS) { + printf("\n ERROR: Init Failed - %d", __LINE__); + ocware_stub_deinit_ethernet_comm(); + return STUB_FAILED; + } + + msgFrame = (OCMPMessageFrame *) malloc(sizeof(OCMPMessageFrame)); + if (msgFrame == NULL) { + printf("\n ERROR: malloc"); + ocware_stub_deinit_ethernet_comm(); + return STUB_FAILED; + } + + buffer = (char *) malloc(OC_EC_MSG_SIZE); + if (buffer == NULL) { + printf("\n ERROR: malloc"); + ocware_stub_deinit_ethernet_comm(); + return STUB_FAILED; + } + + rootpath = (char *)malloc(100); + if (rootpath == NULL) { + printf("\n ERROR: malloc"); + ocware_stub_deinit_ethernet_comm(); + return STUB_FAILED; + } + + ocware_stub_init_database(); + + printf("\n\n OCWARE STUB APllication Started...\n"); + + while (1) { + + memset(buffer, 0, sizeof(OCMPMessageFrame)); + rc = ocware_stub_recv_msgfrom_middleware(&buffer, + sizeof(OCMPMessageFrame)); + if (rc != STUB_SUCCESS) { + printf("ocware_stub_recv_msgfrom_middleware failed: error value :" + " %d\n", rc); + return STUB_FAILED; + } + +//#ifndef OCWARE_STUB_DEBUG + printf(" \n Received Data :\n"); + for (loopCount = 0; loopCount < OC_EC_MSG_SIZE; loopCount++) { + printf("0x%x ", buffer[loopCount] & 0xff); + } +//#endif + rc = ocware_stub_validate_msgframe_header(buffer, &msgFrame->message); + if (rc != STUB_SUCCESS) { + printf("ocware_stub_validate_msgframe_header failed: error value :" + "%d\n", rc); + return STUB_FAILED; + } + rc = ocware_stub_frame_newmsgframe(buffer, rc); + if (rc != STUB_SUCCESS) { + printf("ocware_stub_frame_newmsgframe failed: error value :" + "%d\n", rc); + return STUB_FAILED; + } + + rc = ocware_stub_send_msgframe_middleware(&buffer, + sizeof(OCMPMessageFrame)); + if (rc != STUB_SUCCESS) { + printf("ocware_stub_send_msgframe_middleware failed: error value :" + "%d\n", rc); + return STUB_FAILED; + } + } + free(msgFrame); + free(buffer); + return STUB_SUCCESS; +} +/****************************************************************************** + * Function Name : main + * Description : start the stub process + * + * @param argc - number of argunents passed (by value) + * @param argv - arguments passed when invoking stub (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +#ifndef OCWARE_UNITY_TEST +int32_t main(int32_t argc, char *argv[]) +{ + int32_t ret = 0; + ret = host_ocstubmain_func(argc, argv); + return ret; +} +#else +int32_t host_ocwaremain(int32_t argc, char *argv[]) +{ + int32_t ret = 0; + ret = host_ocstubmain_func(argc, argv); + return ret; +} +#endif diff --git a/firmware/host/ocwarestub/ocware_stub_parse_message.c b/firmware/host/ocwarestub/ocware_stub_parse_message.c new file mode 100755 index 0000000000..c2efd0a3f9 --- /dev/null +++ b/firmware/host/ocwarestub/ocware_stub_parse_message.c @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include +#include +#include + +/****************************************************************************** + * Function Name : ocware_stub_parse_debug_actiontype + * Description : Convert debug actiontype into the SET/GET + * + * @param msgFrameData - output pointer to the OCMPheader field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + *******************************************************************************/ +ocware_stub_ret ocware_stub_parse_debug_actiontype(OCMPMessage *msgFrameData) +{ + ocware_stub_ret ret = STUB_SUCCESS; + + if ((debugSetCommand != STUB_FAILED) || + (debugGetCommand != STUB_FAILED)) { + + if ((msgFrameData->action) == debugGetCommand) { + msgFrameData->action = OCMP_AXN_TYPE_GET; + } else if ((msgFrameData->action) == debugSetCommand) { + msgFrameData->action = OCMP_AXN_TYPE_SET; + } else { + ret = STUB_FAILED; + } + } else { + ret = STUB_FAILED; + } + return ret; +} + +/****************************************************************************** + * Function Name : ocware_stub_handle_post_enable + * Description : Process the post enable message + * + * @param msgFrameData - output pointer to the OCMPheader field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_handle_post_enable(OCMPMessage *msgFrameData) +{ + return STUB_SUCCESS; +} + +/****************************************************************************** + * Function Name : ocware_stub_get_set_params + * Description : Function to check if GET/SET operation is to be performed + * + * @param msgFrameData - Pointer to the message frame field of the message + * from MW (by reference) + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_get_set_params(OCMPMessage *msgFrameData) +{ + ocware_stub_ret ret = STUB_FAILED; + + if (msgFrameData == NULL) { + return ret; + } + + switch (msgFrameData->action) { + case OCMP_AXN_TYPE_GET: + ret = ocware_stub_get_database(msgFrameData); + break; + + case OCMP_AXN_TYPE_SET: + ret = ocware_stub_set_database(msgFrameData); + break; + + default: + ret = STUB_FAILED; + } + return ret; + +} +/****************************************************************************** + * Function Name : ocware_stub_parse_post_get_message + * Description : Parse post messages from MW + * + * @param buffer - output pointer to the message from MW + * + * @return STUB_SUCCESS - for success + * STUB_FAILED - for failure + ******************************************************************************/ +ocware_stub_ret ocware_stub_parse_post_get_message(char *buffer) +{ + ocware_stub_ret ret = STUB_FAILED; + OCMPMessageFrame *msgFrame = NULL; + OCMPMessage *msgFrameData = NULL; + uint16_t paramId; + char *payload = NULL; + + if(buffer == NULL) { + return ret; + } + msgFrame = (OCMPMessageFrame *)buffer; + msgFrameData = (OCMPMessage*)&msgFrame->message; + payload = (char *)&msgFrameData->info; + msgFrameData->action = OCMP_AXN_TYPE_REPLY; + paramId = msgFrameData->parameters; + + if(paramId == PostResult) { + ret = ocware_stub_get_post_database(msgFrameData, payload); + } else if (paramId == PostEnable) { + ret = ocware_stub_handle_post_enable(msgFrameData); + } + return ret; +} diff --git a/firmware/host/ocwarestub/test_all_stub.sh b/firmware/host/ocwarestub/test_all_stub.sh new file mode 100755 index 0000000000..810f86fcff --- /dev/null +++ b/firmware/host/ocwarestub/test_all_stub.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +echo "##############################" +echo " GET CONFIG PARAMS - 1 " +echo "##############################" +./get_params_stub.sh bms config +./get_params_stub.sh gpp config +./get_params_stub.sh sdr config +./get_params_stub.sh rf config +./get_params_stub.sh power config +./get_params_stub.sh ethernet config +./get_params_stub.sh sync config + +echo "##############################" +echo " SET CONFIG PARAMS " +echo "##############################" +../scripts/set_config_params.sh bms +../scripts/set_config_params.sh gpp +../scripts/set_config_params.sh sdr +../scripts/set_config_params.sh rf +../scripts/set_config_params.sh power +../scripts/set_config_params.sh ethernet +../scripts/set_config_params.sh sync + +echo "##############################" +echo " GET CONFIG PARAMS - 2 " +echo "##############################" +./get_params_stub.sh bms config +./get_params_stub.sh gpp config +./get_params_stub.sh sdr config +./get_params_stub.sh rf config +./get_params_stub.sh power config +./get_params_stub.sh ethernet config +./get_params_stub.sh sync config + +echo "##############################" +echo " GET STATUS PARAMS " +echo "##############################" +./get_params_stub.sh bms status +./get_params_stub.sh gpp status +./get_params_stub.sh sdr status +./get_params_stub.sh rf status +./get_params_stub.sh power status +./get_params_stub.sh ethernet status +./get_params_stub.sh sync status +./get_params_stub.sh testmodule status +./get_params_stub.sh obc status +./get_params_stub.sh hci status +./get_params_stub.sh system status + +echo "##############################" +echo " GET DEBUG COMMANDS - 1 " +echo "##############################" +./get_params_stub.sh debug I2C +./get_params_stub.sh debug GPIO +./get_params_stub.sh debug MDIO + + +echo "##############################" +echo " SET DEBUG COMMANDS " +echo "##############################" +../scripts/set_config_params.sh debug I2C +../scripts/set_config_params.sh debug GPIO +../scripts/set_config_params.sh debug MDIO + + +echo "##############################" +echo " GET DEBUG COMMANDS - 2 " +echo "##############################" +./get_params_stub.sh debug I2C +./get_params_stub.sh debug GPIO +./get_params_stub.sh debug MDIO +echo " >>> TESTING DONE <<< " diff --git a/firmware/host/ocwdg/ocwdg_daemon.c b/firmware/host/ocwdg/ocwdg_daemon.c new file mode 100644 index 0000000000..50d2050eac --- /dev/null +++ b/firmware/host/ocwdg/ocwdg_daemon.c @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* OC includes */ +#include +#include + +#define OCWDG_NUMBER_ZERO 0 +#define OCWDG_NUMBER_ONE 1 + +extern int32_t ocmw_sem_wait_nointr(sem_t *sem); + +/****************************************************************************** + * Function Name : ocwdg_init + * Description : This Function used to initialize the watchdog semaphore + * and thread. + * Input(s) : + * Output(s) : + ******************************************************************************/ +int32_t ocwdg_init(void) +{ + pthread_t ocWdgThreadid; + int32_t ret = OCWDG_NUMBER_ZERO; + + printf("inside ocwdg_init() \n"); + ret = sem_init(&semEcWdgMsg, OCWDG_NUMBER_ZERO, OCWDG_NUMBER_ZERO); + if (ret != OCWDG_NUMBER_ZERO) { + return ret; + } else { + /* Create the msg parser thread to parse + * the msg coming from UART ec to ap + */ + ret = pthread_create(&ocWdgThreadid, NULL, ocwdg_thread_comm_with_ec, + NULL); + if (ret != OCWDG_NUMBER_ZERO) { + return ret; + } + } + return ret; +} + +/****************************************************************************** + * Function Name : ocwdg_thread_comm_with_ec + * Description : Thread to send watchdog response to ec + * through uart or ethernet communication + * Input(s) : pthreadData + * Output(s) : + ******************************************************************************/ +void * ocwdg_thread_comm_with_ec(void *pthreadData) +{ + OCMPMessageFrame ecMsgFrame; + OCMPHeader ecMsgHeader; + OCMPMessage ecCoreMsg; + int32_t ret = OCWDG_NUMBER_ZERO; + + while (OCWDG_NUMBER_ONE) { + /* Waiting on the semEcWdgMsg to be released by + * msg receiving thread from ec + */ + ret = ocmw_sem_wait_nointr(&semEcWdgMsg); + if (ret != OCWDG_NUMBER_ZERO) { + perror("ocwdg_thread_comm_with_ec: ocmw_sem_wait_nointr"); + continue; + } + + /* Frame the header packet for sending data to ec */ + ecMsgHeader.ocmpFrameLen = OCWDG_NUMBER_ZERO; +#ifdef INTERFACE_ETHERNET + ecMsgHeader.ocmpInterface = OCMP_COMM_IFACE_ETHERNET; +#else + ecMsgHeader.ocmpInterface = OCMP_COMM_IFACE_UART; +#endif /* INTERFACE_ETHERNET */ + ecMsgHeader.ocmpSeqNumber = OCWDG_NUMBER_ZERO; + ecMsgHeader.ocmpSof = OCMP_MSG_SOF; + ecMsgHeader.ocmpTimestamp = OCWDG_NUMBER_ZERO; + + /* Frame the Core packet for sending data to ec */ + ecCoreMsg.action = OCMP_AXN_TYPE_REPLY; + ecCoreMsg.msgtype = OCMP_MSG_TYPE_WATCHDOG; + ecCoreMsg.parameters = 0; + + /* Construct the final packet */ + ecMsgFrame.header = ecMsgHeader; + ecMsgFrame.message = ecCoreMsg; + + /* Populate the Core packet payload */ + ecMsgFrame.message.info = (int8_t *) malloc( + sizeof(char) * MAX_PARM_COUNT); + if (ecMsgFrame.message.info == NULL) { + printf("\n Memory allocation failed \n"); + } + memset(ecMsgFrame.message.info, OCWDG_NUMBER_ZERO, MAX_PARM_COUNT); + +#ifdef INTERFACE_ETHERNET + /* Send the packetize data to ec through ethernet*/ + ret = ocmw_send_eth_msgto_ec((int8_t *)&ecMsgFrame, (int32_t)32, + OCMW_EC_DEV); + if (ret != OCWDG_NUMBER_ZERO) { + logerr ("ocmw_send_eth_msgto_ec() failed"); + } + +#else + /* Send the packetize data to ec through uart*/ + ret = ocmw_send_uart_msg_to_ec((uint8_t *) &ecMsgFrame, + sizeof(ecMsgFrame)); + if (ret != OCWDG_NUMBER_ZERO) { + logerr("ocmw_send_uart_msg_to_ec() failed"); + } + +#endif /* INTERFACE_ETHERNET */ + printf("Watchdog reply message sent to ec \n"); + } +} diff --git a/firmware/host/ocwdg/ocwdg_daemon.conf b/firmware/host/ocwdg/ocwdg_daemon.conf new file mode 100644 index 0000000000..ebd3da86c2 --- /dev/null +++ b/firmware/host/ocwdg/ocwdg_daemon.conf @@ -0,0 +1,20 @@ +#This config is used to start the watchdog-daemon at boot time and if daemon got +#killed anyway. This file should be put in /etc/init folder after that +# run the command sudo service ocwdg_daemon restart +# Command used to check the syntax of config script : init-checkconf /etc/init/ocwdg_daemon.conf + +description "Watchdog Daemon" + +start on filesystem or runlevel [2345] +stop on runlevel [06] + + +#Replace the path with the location of watchdog-daemon +exec /home/oc/Desktop/Fb_code/ocmw --daemon + +# Restart the process if it dies with a signal +# or exit code not given by the 'normal exit' stanza. +respawn + +# Give up if restart occurs 10 times in 90 seconds. +respawn limit 10 90 diff --git a/firmware/host/scripts/autoTest/oc_pmic_i2c0_read.sh b/firmware/host/scripts/autoTest/oc_pmic_i2c0_read.sh new file mode 100755 index 0000000000..eb8569df49 --- /dev/null +++ b/firmware/host/scripts/autoTest/oc_pmic_i2c0_read.sh @@ -0,0 +1,29 @@ +modprobe i2c-i801 +#i2cdetect -l +#i2cdetect -r -y 9 +#i2cdetect -r -y 0 + +#Valid only for ubuntu-14.04.4 : Kernel-> 4.2.0-42 +bus=`i2cdetect -l | awk -F ' |-|\t' '/DesignWare/ {print $2}' | head -1` + +i2cdetect -r -y $bus + + + +# Read ‘Chip revision register’ from PMIC (0x5E) on i2c-0 +# Sleep for a second + +#PMIC(0X5E) o/p- chip revision: 0x05 +x=1 +while [ $x -le 100 ] +do + + +#i2cget -f -y 0 0x5e 0x01 b + +i2cget -f -y $bus 0x5e 0x01 b +echo "Reading Chip revision register’ from PMIC (0x5E) on i2c-0 and sleeping for 1 sec" + +sleep 1 + x=$(( $x + 1 )) +done diff --git a/firmware/host/scripts/autoTest/oc_pmic_tsensor_read.sh b/firmware/host/scripts/autoTest/oc_pmic_tsensor_read.sh new file mode 100755 index 0000000000..68445c2500 --- /dev/null +++ b/firmware/host/scripts/autoTest/oc_pmic_tsensor_read.sh @@ -0,0 +1,18 @@ +modprobe i2c-i801 +i2cdetect -l + + +x=1 +while [ $x -le 10 ] +do + +#Temperature sensor(0X4C) : o/p-> ( Device id: 0x3d : 0x81) (manufacture id: 0x3e : 0x41) + +i2cdetect -y 9 + +echo "Checking presence of ADT7481 temperature sensor and DDR3 DIMM-0 SPD memory" + +sleep 1 + + x=$(( $x + 1 )) +done diff --git a/firmware/host/scripts/autoTest/oc_smb_ddr3_read.sh b/firmware/host/scripts/autoTest/oc_smb_ddr3_read.sh new file mode 100755 index 0000000000..4b4260573f --- /dev/null +++ b/firmware/host/scripts/autoTest/oc_smb_ddr3_read.sh @@ -0,0 +1,27 @@ +modprobe i2c-i801 +i2cdetect -l +i2cdetect -r -y 9 +#i2cdetect -r -y 0 + + + +x=1 +while [ $x -le 100 ] +do + +#Read device register address from 128 to 145 from device DDR3 SPD (0x50) on i2c-9 + +y=128 + +while [ $y -le 145 ] +do +i2cget -f -y 9 0x50 $y b +y=$(( $y + 1 )) +done + +echo "Reading device register address from 128 to 145 from device DDR3 SPD (0x50) on i2c-9 and sleeping for 1 sec " + +sleep 1 + + x=$(( $x + 1 )) +done diff --git a/firmware/host/scripts/autoTest/oc_smb_tsensor_read.sh b/firmware/host/scripts/autoTest/oc_smb_tsensor_read.sh new file mode 100755 index 0000000000..c3537c07f0 --- /dev/null +++ b/firmware/host/scripts/autoTest/oc_smb_tsensor_read.sh @@ -0,0 +1,25 @@ +modprobe i2c-i801 +i2cdetect -l +i2cdetect -r -y 9 +#i2cdetect -r -y 0 + + +x=1 +while [ $x -le 100 ] +do + +#Temperature sensor(0X4C) : o/p-> ( Device id: 0x3d : 0x81) (manufacture id: 0x3e : 0x41) + +i2cget -f -y 9 0x1f 0x3d b + +echo "Reading -> Device id: 0x3d : 0x81 from temperature sensor and sleeping for 1 sec" + +sleep 1 + +i2cget -f -y 9 0x1f 0x3e b + +echo "Reading -> Manufacture id: 0x3e : 0x41 from temperature sensor and sleeping for 1 sec" + +sleep 1 + x=$(( $x + 1 )) +done diff --git a/firmware/host/scripts/get_params.sh b/firmware/host/scripts/get_params.sh new file mode 100755 index 0000000000..d50fd75410 --- /dev/null +++ b/firmware/host/scripts/get_params.sh @@ -0,0 +1,849 @@ +#!/bin/bash + +bmsParam=("bms.ec.config.temp_sensor1.lowlimit.get" + "bms.ec.config.temp_sensor1.highlimit.get" + "bms.ec.config.temp_sensor1.critlimit.get" + "bms.ec.config.current_sensor1.currlimit.get" + "bms.ec.config.current_sensor2.currlimit.get") + +defaultBms=("bms.ec.config.temp_sensor1.lowlimit.get=-20" + "bms.ec.config.temp_sensor1.highlimit.get=75" + "bms.ec.config.temp_sensor1.critlimit.get=80" + "bms.ec.config.current_sensor1.currlimit.get=1000" + "bms.ec.config.current_sensor2.currlimit.get=1000") + +setBmsVal=("bms.ec.config.temp_sensor1.lowlimit.get=-19" + "bms.ec.config.temp_sensor1.highlimit.get=76" + "bms.ec.config.temp_sensor1.critlimit.get=85" + "bms.ec.config.current_sensor1.currlimit.get=1498" + "bms.ec.config.current_sensor2.currlimit.get=1498") + +bmsStatusParam=("bms.ec.status.temp_sensor1.temperature.get" + "bms.ec.status.current_sensor1.busvoltage.get" + "bms.ec.status.current_sensor1.shuntvoltage.get" + "bms.ec.status.current_sensor1.current.get" + "bms.ec.status.current_sensor1.power.get" + "bms.ec.status.current_sensor2.busvoltage.get" + "bms.ec.status.current_sensor2.shuntvoltage.get" + "bms.ec.status.current_sensor2.current.get" + "bms.ec.status.current_sensor2.power.get") + +bmsStatusMinVal=(-20 11400 250 100 1100 2970 800 400 1200) + +bmsStatusMaxVal=(75 12600 1400 600 7500 3630 2000 800 2900) + +gppParam=("gpp.ap.config.temp_sensor1.lowlimit.get" + "gpp.ap.config.temp_sensor1.highlimit.get" + "gpp.ap.config.temp_sensor1.critlimit.get" + "gpp.ap.config.temp_sensor2.lowlimit.get" + "gpp.ap.config.temp_sensor2.highlimit.get" + "gpp.ap.config.temp_sensor2.critlimit.get" + "gpp.ap.config.temp_sensor3.lowlimit.get" + "gpp.ap.config.temp_sensor3.highlimit.get" + "gpp.ap.config.temp_sensor3.critlimit.get" + "gpp.ap.config.current_sensor1.currlimit.get" + "gpp.msata.config.current_sensor1.currlimit.get") + +defaultGpp=("gpp.ap.config.temp_sensor1.lowlimit.get=-20" + "gpp.ap.config.temp_sensor1.highlimit.get=75" + "gpp.ap.config.temp_sensor1.critlimit.get=80" + "gpp.ap.config.temp_sensor2.lowlimit.get=-20" + "gpp.ap.config.temp_sensor2.highlimit.get=75" + "gpp.ap.config.temp_sensor2.critlimit.get=80" + "gpp.ap.config.temp_sensor3.lowlimit.get=-20" + "gpp.ap.config.temp_sensor3.highlimit.get=75" + "gpp.ap.config.temp_sensor3.critlimit.get=80" + "gpp.ap.config.current_sensor1.currlimit.get=1498" + "gpp.msata.config.current_sensor1.currlimit.get=1498") + +setGppVal=("gpp.ap.config.temp_sensor1.lowlimit.get=-19" + "gpp.ap.config.temp_sensor1.highlimit.get=81" + "gpp.ap.config.temp_sensor1.critlimit.get=86" + "gpp.ap.config.temp_sensor2.lowlimit.get=-19" + "gpp.ap.config.temp_sensor2.highlimit.get=81" + "gpp.ap.config.temp_sensor2.critlimit.get=86" + "gpp.ap.config.temp_sensor3.lowlimit.get=-19" + "gpp.ap.config.temp_sensor3.highlimit.get=81" + "gpp.ap.config.temp_sensor3.critlimit.get=86" + "gpp.ap.config.current_sensor1.currlimit.get=2010" + "gpp.msata.config.current_sensor1.currlimit.get=2010") + + +gppStatusParam=("gpp.ap.status.temp_sensor1.temperature.get" + "gpp.ap.status.temp_sensor2.temperature.get" + "gpp.ap.status.temp_sensor3.temperature.get" + "gpp.ap.status.current_sensor1.busvoltage.get" + "gpp.ap.status.current_sensor1.shuntvoltage.get" + "gpp.ap.status.current_sensor1.current.get" + "gpp.ap.status.current_sensor1.power.get" + "gpp.msata.status.current_sensor1.busvoltage.get" + "gpp.msata.status.current_sensor1.shuntvoltage.get" + "gpp.msata.status.current_sensor1.current.get" + "gpp.msata.status.current_sensor1.power.get") + +gppStatusMinVal=(-20 -20 -20 11400 700 400 5000 3135 140 50 250) + +gppStatusMaxVal=(80 80 80 12600 1400 1200 8300 3465 500 300 800) + +hciParam=("hci.led.config.temp_sensor1.lowlimit.get" + "hci.led.config.temp_sensor1.highlimit.get" + "hci.led.config.temp_sensor1.critlimit.get") + +defaultHci=("hci.led.config.temp_sensor1.lowlimit.get=-20" + "hci.led.config.temp_sensor1.highlimit.get=80" + "hci.led.config.temp_sensor1.critlimit.get=85") + +setHciVal=("hci.led.config.temp_sensor1.lowlimit.get=-19" + "hci.led.config.temp_sensor1.highlimit.get=76" + "hci.led.config.temp_sensor1.critlimit.get=85") + +hciStatusParam=("hci.led.status.temp_sensor1.temperature.get") + +hciStatusMinVal=(-20) + +hciStatusMaxVal=(80) + +sdrParam=("sdr.comp_all.config.current_sensor1.currlimit.get" + "sdr.fpga.config.temp_sensor1.lowlimit.get" + "sdr.fpga.config.temp_sensor1.highlimit.get" + "sdr.fpga.config.temp_sensor1.critlimit.get" + "sdr.fpga.config.current_sensor1.currlimit.get") + +defaultSdr=("sdr.comp_all.config.current_sensor1.currlimit.get=2998" + "sdr.fpga.config.temp_sensor1.lowlimit.get=-20" + "sdr.fpga.config.temp_sensor1.highlimit.get=75" + "sdr.fpga.config.temp_sensor1.critlimit.get=85" + "sdr.fpga.config.current_sensor1.currlimit.get=500") + +setSdrVal=("sdr.comp_all.config.current_sensor1.currlimit.get=2010" + "sdr.fpga.config.temp_sensor1.lowlimit.get=-19" + "sdr.fpga.config.temp_sensor1.highlimit.get=76" + "sdr.fpga.config.temp_sensor1.critlimit.get=81" + "sdr.fpga.config.current_sensor1.currlimit.get=510") + +sdrStatusParam=("sdr.comp_all.status.current_sensor1.busvoltage.get" + "sdr.comp_all.status.current_sensor1.shuntvoltage.get" + "sdr.comp_all.status.current_sensor1.current.get" + "sdr.comp_all.status.current_sensor1.power.get" + "sdr.fpga.status.temp_sensor1.temperature.get" + "sdr.fpga.status.current_sensor1.busvoltage.get" + "sdr.fpga.status.current_sensor1.shuntvoltage.get" + "sdr.fpga.status.current_sensor1.current.get" + "sdr.fpga.status.current_sensor1.power.get") + +sdrStatusMinVal=(11400 2762 1381 15742 0 11400 60 30 342) + +sdrStatusMaxVal=(12600 4173 2087 26292 80 12600 240 120 1512) + +rfParam=("rffe.ch1_sensor.config.temp_sensor1.lowlimit.get" + "rffe.ch1_sensor.config.temp_sensor1.highlimit.get" + "rffe.ch1_sensor.config.temp_sensor1.critlimit.get" + "rffe.ch1_sensor.config.current_sensor1.currlimit.get" + "rffe.ch2_sensor.config.temp_sensor1.lowlimit.get" + "rffe.ch2_sensor.config.temp_sensor1.highlimit.get" + "rffe.ch2_sensor.config.temp_sensor1.critlimit.get" + "rffe.ch2_sensor.config.current_sensor1.currlimit.get" + "rffe.ch1_fe.config.ch1_band.band.get" + "rffe.ch1_fe.config.tx.atten.get" + "rffe.ch1_fe.config.rx.atten.get" + "rffe.ch2_fe.config.ch2_band.band.get" + "rffe.ch2_fe.config.tx.atten.get" + "rffe.ch2_fe.config.rx.atten.get") + +defaultRf=("rffe.ch1_sensor.config.temp_sensor1.lowlimit.get=-20" + "rffe.ch1_sensor.config.temp_sensor1.highlimit.get=80" + "rffe.ch1_sensor.config.temp_sensor1.critlimit.get=85" + "rffe.ch1_sensor.config.current_sensor1.currlimit.get=2000" + "rffe.ch2_sensor.config.temp_sensor1.lowlimit.get=-20" + "rffe.ch2_sensor.config.temp_sensor1.highlimit.get=80" + "rffe.ch2_sensor.config.temp_sensor1.critlimit.get=85" + "rffe.ch2_sensor.config.current_sensor1.currlimit.get=2000" + "rffe.ch1_fe.config.ch1_band.band.get=3" + "rffe.ch1_fe.config.tx.atten.get=63" + "rffe.ch1_fe.config.rx.atten.get=31" + "rffe.ch2_fe.config.ch2_band.band.get=3" + "rffe.ch2_fe.config.tx.atten.get=63" + "rffe.ch2_fe.config.rx.atten.get=31") + +setRfVal=("rffe.ch1_sensor.config.temp_sensor1.lowlimit.get=-19" + "rffe.ch1_sensor.config.temp_sensor1.highlimit.get=76" + "rffe.ch1_sensor.config.temp_sensor1.critlimit.get=81" + "rffe.ch1_sensor.config.current_sensor1.currlimiti.get=1467" + "rffe.ch2_sensor.config.temp_sensor1.lowlimit.get=-19" + "rffe.ch2_sensor.config.temp_sensor1.highlimit.get=76" + "rffe.ch2_sensor.config.temp_sensor1.critlimit.get=81" + "rffe.ch2_sensor.config.current_sensor1.currlimit.get=510" + "rffe.ch1_fe.config.ch1_band.band.get=3" + "rffe.ch1_fe.config.tx.atten.get=60" + "rffe.ch1_fe.config.rx.atten.get=20" + "rffe.ch2_fe.config.ch2_band.band.get=3" + "rffe.ch2_fe.config.tx.atten.get=60" + "rffe.ch2_fe.config.rx.atten.get=20") + +rfStatusParam=("rffe.ch1_sensor.status.temp_sensor1.temperature.get" + "rffe.ch1_sensor.status.current_sensor1.busvoltage.get" + "rffe.ch1_sensor.status.current_sensor1.shuntvoltage.get" + "rffe.ch1_sensor.status.current_sensor1.current.get" + "rffe.ch1_sensor.status.current_sensor1.power.get" + "rffe.ch2_sensor.status.temp_sensor1.temperature.get" + "rffe.ch2_sensor.status.current_sensor1.busvoltage.get" + "rffe.ch2_sensor.status.current_sensor1.shuntvoltage.get" + "rffe.ch2_sensor.status.current_sensor1.current.get" + "rffe.ch2_sensor.status.current_sensor1.power.get" + "rffe.ch1_fe.status.power.forward.get" + "rffe.ch1_fe.status.power.reverse.get" + "rffe.ch2_fe.status.power.forward.get" + "rffe.ch2_fe.status.power.reverse.get") + +rfStatusMinVal=(10 5500 2800 1400 7700 10 5500 2800 1400 7700 0 0 0 0) + +rfStatusMaxVal=(80 5900 4200 2100 12390 80 5900 4200 2100 12390 10 10 10 10) + +powerParam=("power.leadacid_sensor.config.temp_sensor1.lowlimit.get" + "power.leadacid_sensor.config.temp_sensor1.highlimit.get" + "power.leadacid_sensor.config.temp_sensor1.critlimit.get" + "power.leadacid.config.battery.batteryVoltageLow.get" + "power.leadacid.config.battery.batteryVoltageHigh.get" + "power.leadacid.config.battery.batteryCurrentLow.get" + "power.leadacid.config.battery.inputVoltageLow.get" + "power.leadacid.config.battery.inputCurrentHigh.get" + "power.leadacid.config.battery.inputCurrentLimit.get" + "power.lion.config.battery.batteryVoltageLow.get" + "power.lion.config.battery.batteryVoltageHigh.get" + "power.lion.config.battery.batteryCurrentLow.get" + "power.lion.config.battery.inputVoltageLow.get" + "power.lion.config.battery.inputCurrentHigh.get" + "power.lion.config.battery.inputCurrentLimit.get" + "power.pse.config.operatingMode.get" + "power.pse.config.detectEnable.get" + "power.pse.config.interruptMask.get" + "power.pse.config.interruptEnable.get" + "power.pse.config.enableHighpower.get") + +defaultPower=("power.leadacid_sensor.config.temp_sensor1.lowlimit.get=-20" + "power.leadacid_sensor.config.temp_sensor1.highlimit.get=75" + "power.leadacid_sensor.config.temp_sensor1.critlimit.get=80" + "power.leadacid.config.battery.batteryVoltageLow.get=12666" + "power.leadacid.config.battery.batteryVoltageHigh.get=16799" + "power.leadacid.config.battery.batteryCurrentLow.get=999" + "power.leadacid.config.battery.inputVoltageLow.get=16199" + "power.leadacid.config.battery.inputCurrentHigh.get=17499" + "power.leadacid.config.battery.inputCurrentLimit.get=16000" + "power.lion.config.battery.batteryVoltageLow.get=9499" + "power.lion.config.battery.batteryVoltageHigh.get=12599" + "power.lion.config.battery.batteryCurrentLow.get=99" + "power.lion.config.battery.inputVoltageLow.get=16199" + "power.lion.config.battery.inputCurrentHigh.get=4999" + "power.lion.config.battery.inputCurrentLimit.get=4571" + "power.pse.config.operatingMode.get=17" + "power.pse.config.detectEnable.get=17" + "power.pse.config.interruptMask.get=17" + "power.pse.config.interruptEnable.get=17" + "power.pse.config.enableHighpower.get=17") + +setPowerVal=("power.leadacid_sensor.config.temp_sensor1.lowlimit.get=-19" + "power.leadacid_sensor.config.temp_sensor1.highlimit.get=76" + "power.leadacid_sensor.config.temp_sensor1.critlimit.get=81" + "power.leadacid.config.battery.batteryVoltageLow.get=12499" + "power.leadacid.config.battery.batteryVoltageHigh.get=16499" + "power.leadacid.config.battery.batteryCurrentLow.get=899" + "power.leadacid.config.battery.inputVoltageLow.get=16209" + "power.leadacid.config.battery.inputCurrentHigh.get=17399" + "power.leadacid.config.battery.inputCurrentLimit.get=15000" + "power.lion.config.battery.batteryVoltageLow.get=9009" + "power.lion.config.battery.batteryVoltageHigh.get=12699" + "power.lion.config.battery.batteryCurrentLow.get=109" + "power.lion.config.battery.inputVoltageLow.get=16209" + "power.lion.config.battery.inputCurrentHigh.get=5009" + "power.lion.config.battery.inputCurrentLimit.get=3571" + "power.pse.config.operatingMode.get=3" + "power.pse.config.detectEnable.get=64" + "power.pse.config.interruptMask.get=195" + "power.pse.config.interruptEnable.get=128" + "power.pse.config.enableHighpower.get=17") + +ethParam=("ethernet.port0.config.speed.get" + "ethernet.port0.config.duplex.get" + "ethernet.port0.config.powerDown.get" + "ethernet.port0.config.enable_sleepMode.get" + "ethernet.port0.config.enable_interrupt.get" + "ethernet.port1.config.speed.get" + "ethernet.port1.config.duplex.get" + "ethernet.port1.config.powerDown.get" + "ethernet.port1.config.enable_sleepMode.get" + "ethernet.port1.config.enable_interrupt.get" + "ethernet.port2.config.speed.get" + "ethernet.port2.config.duplex.get" + "ethernet.port2.config.powerDown.get" + "ethernet.port2.config.enable_sleepMode.get" + "ethernet.port2.config.enable_interrupt.get" + "ethernet.port3.config.speed.get" + "ethernet.port3.config.duplex.get" + "ethernet.port3.config.powerDown.get" + "ethernet.port3.config.enable_sleepMode.get" + "ethernet.port3.config.enable_interrupt.get" + "ethernet.port4.config.speed.get" + "ethernet.port4.config.duplex.get" + "ethernet.port4.config.powerDown.get" + "ethernet.port4.config.enable_sleepMode.get" + "ethernet.port4.config.enable_interrupt.get") + +defaultEth=("ethernet.port0.config.speed.get=2" + "ethernet.port0.config.duplex.get=2" + "ethernet.port0.config.powerDown.get=0" + "ethernet.port0.config.enable_sleepMode.get=0" + "ethernet.port0.config.enable_interrupt.get=0" + "ethernet.port1.config.speed.get=2" + "ethernet.port1.config.duplex.get=2" + "ethernet.port1.config.powerDown.get=0" + "ethernet.port1.config.enable_sleepMode.get=0" + "ethernet.port1.config.enable_interrupt.get=0" + "ethernet.port2.config.speed.get=2" + "ethernet.port2.config.duplex.get=2" + "ethernet.port2.config.powerDown.get=0" + "ethernet.port2.config.enable_sleepMode.get=0" + "ethernet.port2.config.enable_interrupt.get=0" + "ethernet.port3.config.speed.get=2" + "ethernet.port3.config.duplex.get=2" + "ethernet.port3.config.powerDown.get=0" + "ethernet.port3.config.enable_sleepMode.get=0" + "ethernet.port3.config.enable_interrupt.get=0" + "ethernet.port4.config.speed.get=2" + "ethernet.port4.config.duplex.get=2" + "ethernet.port4.config.powerDown.get=0" + "ethernet.port4.config.enable_sleepMode.get=0" + "ethernet.port4.config.enable_interrupt.get=0") + +setEthVal=("ethernet.port0.config.speed.get=2" + "ethernet.port0.config.duplex.get=2" + "ethernet.port0.config.powerDown.get=0" + "ethernet.port0.config.enable_sleepMode.get=1" + "ethernet.port0.config.enable_interrupt.get=0" + "ethernet.port1.config.speed.get=1" + "ethernet.port1.config.duplex.get=0" + "ethernet.port1.config.powerDown.get=1" + "ethernet.port1.config.enable_sleepMode.get=0" + "ethernet.port1.config.enable_interrupt.get=0" + "ethernet.port2.config.speed.get=1" + "ethernet.port2.config.duplex.get=1" + "ethernet.port2.config.powerDown.get=1" + "ethernet.port2.config.enable_sleepMode.get=1" + "ethernet.port2.config.enable_interrupt.get=0" + "ethernet.port3.config.speed.get=1" + "ethernet.port3.config.duplex.get=0" + "ethernet.port3.config.powerDown.get=0" + "ethernet.port3.config.enable_sleepMode.get=1" + "ethernet.port3.config.enable_interrupt.get=0" + "ethernet.port4.config.speed.get=1" + "ethernet.port4.config.duplex.get=1" + "ethernet.port4.config.powerDown.get=1" + "ethernet.port4.config.enable_sleepMode.get=1" + "ethernet.port4.config.enable_interrupt.get=0") + +ethernetStatusParam=("ethernet.port0.status.speed.get" + "ethernet.port0.status.duplex.get" + "ethernet.port1.status.speed.get" + "ethernet.port1.status.duplex.get" + "ethernet.port2.status.speed.get" + "ethernet.port2.status.duplex.get" + "ethernet.port3.status.speed.get" + "ethernet.port3.status.duplex.get" + "ethernet.port4.status.speed.get" + "ethernet.port4.status.duplex.get") + +ethernetStatusMinVal=(1 1 1 1 1 1 1 1 1 1) + +ethernetStatusMaxVal=(1 1 1 1 1 1 1 1 1 1) + +syncParam=("sync.sensor.config.temp_sensor1.lowlimit.get" + "sync.sensor.config.temp_sensor1.highlimit.get" + "sync.sensor.config.temp_sensor1.critlimit.get") + +defaultSync=("sync.sensor.config.temp_sensor1.lowlimit.get=-20" + "sync.sensor.config.temp_sensor1.highlimit.get=80" + "sync.sensor.config.temp_sensor1.critlimit.get=85") + +setSyncVal=("sync.sensor.config.temp_sensor1.lowlimit.get=-19" + "sync.sensor.config.temp_sensor1.highlimit.get=81" + "sync.sensor.config.temp_sensor1.critlimit.get=86") + +syncStatusParam=("sync.sensor.status.temp_sensor1.temperature.get") + +syncStatusMinVal=(-20) + +syncStatusMaxVal=(80) + +debugI2CParam=("debug.I2C.bus0.get 104 2 58" + "debug.I2C.bus1.get 24 2 2" + "debug.I2C.bus2.get 29 1 0" + "debug.I2C.bus3.get 68 2 255" + "debug.I2C.bus4.get 65 2 254" + "debug.I2C.bus6.get 64 2 5" + "debug.I2C.bus7.get 69 2 5" + "debug.I2C.bus8.get 26 2 6") + + +defaultDebugI2C=("debug.I2C.bus0(slaveaddress:104noOfBytes:2RegisterAddress:58)get=9984" + "debug.I2C.bus1(slaveaddress:24noOfBytes:2RegisterAddress:2)get=1216" + "debug.I2C.bus2(slaveaddress:29noOfBytes:1RegisterAddress:0)get=115" + "debug.I2C.bus3(slaveaddress:68noOfBytes:2RegisterAddress:255)get=8800" + "debug.I2C.bus4(slaveaddress:65noOfBytes:2RegisterAddress:254)get=21577" + "debug.I2C.bus6(slaveaddress:64noOfBytes:2RegisterAddress:5)get=25600" + "debug.I2C.bus7(slaveaddress:69noOfBytes:2RegisterAddress:5)get=25600" + "debug.I2C.bus8(slaveaddress:26noOfBytes:2RegisterAddress:6)get=0") + +setDebugI2CVal=("debug.I2C.bus0(slaveaddress:104noOfBytes:2RegisterAddress:58)get=7000" + "debug.I2C.bus1(slaveaddress:24noOfBytes:2RegisterAddress:2)get=1024" + "debug.I2C.bus2(slaveaddress:29noOfBytes:1RegisterAddress:0)get=100" + "debug.I2C.bus3(slaveaddress:68noOfBytes:2RegisterAddress:255)get=8000" + "debug.I2C.bus4(slaveaddress:65noOfBytes:2RegisterAddress:254)get=21500" + "debug.I2C.bus6(slaveaddress:64noOfBytes:2RegisterAddress:5)get=25500" + "debug.I2C.bus7(slaveaddress:69noOfBytes:2RegisterAddress:5)get=25500" + "debug.I2C.bus8(slaveaddress:26noOfBytes:2RegisterAddress:6)get=4000") + +debugGpioParam=("debug.ec.PA.get 1" + "debug.ec.PB.get 1" + "debug.ec.PC.get 1" + "debug.ec.PD.get 7" + "debug.ec.PE.get 1" + "debug.ec.PF.get 1" + "debug.ec.PG.get 1" + "debug.ec.PH.get 1" + "debug.ec.PJ.get 1" + "debug.ec.PK.get 1" + "debug.ec.PL.get 5" + "debug.ec.PM.get 1" + "debug.ec.PN.get 1" + "debug.ec.PP.get 3" + "debug.ec.PQ.get 1" + "debug.gbc.ioexpanderx70.get 1" + "debug.gbc.ioexpanderx71.get 0" + "debug.sdr.ioexpanderx1E.get 1" + "debug.fe.ioexpanderx18.get 1" + "debug.fe.ioexpanderx1A.get 0" + "debug.fe.ioexpanderx1B.get 1" + "debug.fe.ioexpanderx1C.get 1" + "debug.fe.ioexpanderx1D.get 1" + "debug.sync.ioexpanderx71.get 1") + +defaultDebugGpio=("debug.ec.PA(PinNo:1)get=0" + "debug.ec.PB(PinNo:1)get=0" + "debug.ec.PC(PinNo:1)get=0" + "debug.ec.PD(PinNo:7)get=1" + "debug.ec.PE(PinNo:1)get=1" + "debug.ec.PF(PinNo:1)get=0" + "debug.ec.PG(PinNo:1)get=0" + "debug.ec.PH(PinNo:1)get=0" + "debug.ec.PJ(PinNo:1)get=0" + "debug.ec.PK(PinNo:1)get=0" + "debug.ec.PL(PinNo:5)get=0" + "debug.ec.PM(PinNo:1)get=0" + "debug.ec.PN(PinNo:1)get=0" + "debug.ec.PP(PinNo:3)get=0" + "debug.ec.PQ(PinNo:1)get=1" + "debug.gbc.ioexpanderx70(PinNo:1)get=1" + "debug.gbc.ioexpanderx71(PinNo:0)get=1" + "debug.sdr.ioexpanderx1E(PinNo:1)get=1" + "debug.fe.ioexpanderx18(PinNo:1)get=1" + "debug.fe.ioexpanderx1A(PinNo:0)get=1" + "debug.fe.ioexpanderx1B(PinNo:1)get=1" + "debug.fe.ioexpanderx1C(PinNo:1)get=1" + "debug.fe.ioexpanderx1D(PinNo:1)get=0" + "debug.sync.ioexpanderx71(PinNo:1)get=0") + +setDebugGpioVal=("debug.ec.PA(PinNo:1)get=1" + "debug.ec.PB(PinNo:1)get=1" + "debug.ec.PC(Pin No:1)get=1" + "debug.ec.PD(Pin No:7)get=0" + "debug.ec.PE(Pin No:1)get=0" + "debug.ec.PF(PinNo:1)get=1" + "debug.ec.PG(Pin No:1)get=1" + "debug.ec.PH(PinNo:1)get=1" + "debug.ec.PJ(PinNo:1)get=1" + "debug.ec.PK(PinNo:1)get=1" + "debug.ec.PL(PinNo:5)get=1" + "debug.ec.PM(PinNo:1)get=0" + "debug.ec.PN(PinNo:1)get=0" + "debug.ec.PP(PinNo:3)get=0" + "debug.ec.PQ(PinNo:1)get=0" + "debug.gbc.ioexpanderx70(PinNo:1)get=0" + "debug.gbc.ioexpanderx71(PinNo:0)get=0" + "debug.sdr.ioexpanderx1E(PinNo:1)get=0" + "debug.fe.ioexpanderx18(PinNo:1)get=0" + "debug.fe.ioexpanderx1A(PinNo:0)get=0" + "debug.fe.ioexpanderx1B(PinNo:1)get=0" + "debug.fe.ioexpanderx1C(PinNo:1)get=0" + "debug.fe.ioexpanderx1D(PinNo:1)get=1" + "debug.sync.ioexpanderx71(PinNo:1)get=1") + +debugMdioParam=("debug.ethernet.port0.get 18" + "debug.ethernet.global1.get 4" + "debug.ethernet.global2.get 1" + "debug.ethernet.swport0.get 1") + +defaultDebugMdio=("debug.ethernet.port0(RegisterAddress:18)get=9216" + "debug.ethernet.global1(RegisterAddress:4)get=1" + "debug.ethernet.global2(RegisterAddress:1)get=0" + "debug.ethernet.swport0(RegisterAddress:1)get=3") + +setDebugMdioVal=("debug.ethernet.port0(RegisterAddress:18)get=1024" + "debug.ethernet.global1(RegisterAddress:4)get=128" + "debug.ethernet.global2(RegisterAddress:1)get=31" + "debug.ethernet.swport0(RegisterAddress:1)get=1") + +function compareValue() { + local -n paramArray=$1 + local -n valueArray=$2 + i=0 + for index in "${paramArray[@]}" + do + val=${valueArray[$i]} + value=$(../bin/occmd $index) + valueStr=$value + printf -v value '%s' $value + if [ "$value" = "$val" ]; then + echo "${paramArray[$i]} Passed" + echo "$valueStr" + else + echo "${paramArray[$i]} FAILED" + if [[ "$value" =~ "Failed" ]]; then + echo "Failed from TIVA" + else + echo "Value Mismatch" + echo "$valueStr" + fi + fi + ((i++)) + done +} + +function errorPrint() { + + if [[ "$1" =~ "Failed" ]]; then + echo "Failed from TIVA" + else + echo "Value not in range: Max=$2 Min=$3 value=$4" + fi +} + +function compareStatusValue() { + local -n paramStatusArray=$1 + local -n minArray=$2 + local -n maxArray=$3 + i=0 + for index in "${paramStatusArray[@]}" + do + minVal=${minArray[$i]} + maxVal=${maxArray[$i]} + value=$(../bin/occmd $index) + valueStr=$value + printf -v value '%s' $value + IFS='=' read -ra token <<< "$value" + statusVal=${token[1]} + if [[ ("$value" =~ "ethernet") ]]; then + if [[ ($statusVal -eq $maxVal) ]]; then + echo "$valueStr Passed" + else + echo "$valueStr Failed" + errorPrint $value $maxVal $minVal $statusVal + fi + elif [[ ($statusVal -le $maxVal) ]]; then + if [[ ($statusVal -ge $minVal) ]]; then + echo "$valueStr Passed" + else + echo "$valueStr Failed" + errorPrint $value $maxVal $minVal $statusVal + fi + else + echo "$valueStr Failed" + errorPrint $value $maxVal $minVal $statusVal + fi + ((i++)) + done +} + +if [ -z "$1" ]; then + echo "Invalid Option" + echo "Usage : ./get_params " + exit +elif [ $1 = "bms" ]; then +if [ $2 = "config" ]; then +if [ $3 = "default" ]; then + compareValue bmsParam defaultBms +elif [ $3 = "verify" ]; then + compareValue bmsParam setBmsVal +else + echo "Invalid Option" +fi +elif [ $2 = "status" ]; then + compareStatusValue bmsStatusParam bmsStatusMinVal bmsStatusMaxVal +else + echo "Invalid Option" +fi +elif [ $1 = "gpp" ]; then +if [ $2 = "config" ]; then +if [ $3 = "default" ]; then + compareValue gppParam defaultGpp +elif [ $3 = "verify" ]; then + compareValue gppParam setGppVal +else + echo "Invalid Option" +fi +elif [ $2 = "status" ]; then + compareStatusValue gppStatusParam gppStatusMinVal gppStatusMaxVal +else + echo "Invalid Option" +fi +elif [ $1 = "sdr" ]; then +if [ $2 = "config" ]; then +if [ $3 = "default" ]; then + compareValue sdrParam defaultSdr +elif [ $3 = "verify" ]; then + compareValue sdrParam setSdrVal +else + echo "Invalid Option" +fi +elif [ $2 = "status" ]; then + compareStatusValue sdrStatusParam sdrStatusMinVal sdrStatusMaxVal +../bin/occmd sdr.comp_all.status.eeprom.dev_id.get +else + echo "Invalid Option" +fi +elif [ $1 = "rf" ]; then +if [ $2 = "config" ]; then +if [ $3 = "default" ]; then + compareValue rfParam defaultRf +elif [ $3 = "verify" ]; then + compareValue rfParam setRfVal +else + echo "Invalid Option" +fi +elif [ $2 = "status" ]; then + compareStatusValue rfStatusParam rfStatusMinVal rfStatusMaxVal +../bin/occmd rffe.comp_all.status.eeprom.dev_id.get +else + echo "Invalid Option" +fi +elif [ $1 = "power" ]; then +if [ $2 = "config" ]; then +if [ $3 = "default" ]; then + compareValue powerParam defaultPower +elif [ $3 = "verify" ]; then + compareValue powerParam setPowerVal +else + echo "Invalid Option" +fi +elif [ $2 = "status" ]; then +../bin/occmd power.leadacid_sensor.status.temp_sensor1.temperature.get +../bin/occmd power.leadacid.status.battery.batteryVoltage.get +../bin/occmd power.leadacid.status.battery.batteryCurrent.get +../bin/occmd power.leadacid.status.battery.systemVoltage.get +../bin/occmd power.leadacid.status.battery.inputVoltage.get +../bin/occmd power.leadacid.status.battery.inputCurrent.get +../bin/occmd power.leadacid.status.battery.dieTemperature.get +../bin/occmd power.lion.status.battery.batteryVoltage.get +../bin/occmd power.lion.status.battery.batteryCurrent.get +../bin/occmd power.lion.status.battery.systemVoltage.get +../bin/occmd power.lion.status.battery.inputVoltage.get +../bin/occmd power.lion.status.battery.inputCurrent.get +../bin/occmd power.lion.status.battery.dieTemperature.get +../bin/occmd power.pse.status.detection.get +../bin/occmd power.pse.status.class.get +../bin/occmd power.pse.status.powerGood.get +# Commented as of now as PD Driver doesnt have enum values defined +#../bin/occmd power.pd.status.class.get +#../bin/occmd power.pd.status.powerGoodState.get +../bin/occmd power.comp_all.status.powerSource.extBattAccessebility.get +../bin/occmd power.comp_all.status.powerSource.extBattAvailability.get +../bin/occmd power.comp_all.status.powerSource.intBattAccessebility.get +../bin/occmd power.comp_all.status.powerSource.intBattAvailability.get +../bin/occmd power.comp_all.status.powerSource.poeAccessebility.get +../bin/occmd power.comp_all.status.powerSource.poeAvailability.get +../bin/occmd power.comp_all.status.powerSource.solarAccessebility.get +../bin/occmd power.comp_all.status.powerSource.solarAvailability.get +else + echo "Invalid Option" +fi +elif [ $1 = "ethernet" ]; then +if [ $2 = "config" ]; then +if [ $3 = "default" ]; then + compareValue ethParam defaultEth +elif [ $3 = "verify" ]; then + compareValue ethParam setEthVal +else + echo "Invalid Option" +fi +elif [ $2 = "status" ]; then + compareStatusValue ethernetStatusParam ethernetStatusMinVal ethernetStatusMaxVal + +../bin/occmd ethernet.port0.status.sleep_mode_en.get +../bin/occmd ethernet.port0.status.autoneg_on.get +../bin/occmd ethernet.port0.status.autoneg_complete.get +../bin/occmd ethernet.port0.status.link_up.get +../bin/occmd ethernet.port1.status.sleep_mode_en.get +../bin/occmd ethernet.port1.status.autoneg_on.get +../bin/occmd ethernet.port1.status.autoneg_complete.get +../bin/occmd ethernet.port1.status.link_up.get +../bin/occmd ethernet.port2.status.sleep_mode_en.get +../bin/occmd ethernet.port2.status.autoneg_on.get +../bin/occmd ethernet.port2.status.autoneg_complete.get +../bin/occmd ethernet.port2.status.link_up.get +../bin/occmd ethernet.port3.status.sleep_mode_en.get +../bin/occmd ethernet.port3.status.autoneg_on.get +../bin/occmd ethernet.port3.status.autoneg_complete.get +../bin/occmd ethernet.port3.status.link_up.get +../bin/occmd ethernet.port4.status.sleep_mode_en.get +../bin/occmd ethernet.port4.status.autoneg_on.get +../bin/occmd ethernet.port4.status.autoneg_complete.get +../bin/occmd ethernet.port4.status.link_up.get +else + echo "Invalid Option" +fi +elif [ $1 = "sync" ]; then +if [ $2 = "config" ]; then +if [ $3 = "default" ]; then + compareValue syncParam defaultSync +elif [ $3 = "verify" ]; then + compareValue syncParam setSyncVal +else + echo "Invalid Option" +fi +elif [ $2 = "status" ]; then + compareStatusValue syncStatusParam syncStatusMinVal syncStatusMaxVal +../bin/occmd sync.gps.status.gps_lock.get +else + echo "Invalid Option" +fi +elif [ $1 = "testmodule" ]; then +if [ $2 = "status" ]; then +../bin/occmd testmodule.2gsim.status.imei.get +../bin/occmd testmodule.2gsim.status.imsi.get +../bin/occmd testmodule.2gsim.status.mfg.get +../bin/occmd testmodule.2gsim.status.model.get +../bin/occmd testmodule.2gsim.status.rssi.get +../bin/occmd testmodule.2gsim.status.ber.get +../bin/occmd testmodule.2gsim.status.registration.get +../bin/occmd testmodule.2gsim.status.network_operatorinfo.get +../bin/occmd testmodule.2gsim.status.cellid.get +../bin/occmd testmodule.2gsim.status.bsic.get +../bin/occmd testmodule.2gsim.status.lasterror.get +else + echo "Invalid Option" +fi +elif [ $1 = "obc" ]; then +if [ $2 = "status" ]; then +../bin/occmd obc.iridium.status.imei.get +../bin/occmd obc.iridium.status.mfg.get +../bin/occmd obc.iridium.status.model.get +../bin/occmd obc.iridium.status.signal_quality.get +../bin/occmd obc.iridium.status.registration.get +../bin/occmd obc.iridium.status.numberofoutgoingmessage.get +../bin/occmd obc.iridium.status.lasterror.get +else + echo "Invalid Option" +fi +elif [ $1 = "hci" ]; then +if [ $2 = "config" ]; then +if [ $3 = "default" ]; then + compareValue hciParam defaultHci +elif [ $3 = "verify" ]; then + compareValue hciParam setHciVal +else + echo "Invalid Option" +fi +elif [ $2 = "status" ]; then + compareStatusValue hciStatusParam hciStatusMinVal hciStatusMaxVal +else + echo "Invalid Option" +fi +elif [ $1 = "system" ]; then +if [ $2 = "status" ]; then +../bin/occmd system.comp_all.status.eeprom_sid.gbcboardinfo.get +../bin/occmd system.comp_all.status.eeprom_sid.ocserialinfo.get +../bin/occmd system.comp_all.config.eeprom_mac.address.get +elif [ $2 = "post" ]; then +../bin/occmd system.comp_all.post.results.get +../bin/occmd system.comp_all.post.enable.set +else + echo "Invalid Option" +fi +elif [ $1 = "debug" ]; then +if [ $2 = "I2C" ]; then +if [ $3 = "default" ]; then + compareValue debugI2CParam defaultDebugI2C +elif [ $3 = "verify" ]; then + compareValue debugI2CParam setDebugI2CVal +else + echo "Invalid Option" +fi +elif [ $2 = "GPIO" ]; then +if [ $3 = "default" ]; then + compareValue debugGpioParam defaultDebugGpio +elif [ $3 = "verify" ]; then + compareValue debugGpioParam setDebugGpioVal +else + echo "Invalid Option" +fi +elif [ $2 = "MDIO" ]; then +if [ $3 = "default" ]; then + compareValue debugMdioParam defaultDebugMdio +elif [ $3 = "verify" ]; then + compareValue debugMdioParam setDebugMdioVal +else + echo "Invalid Option" +fi +else + echo "Invalid Option" +fi +elif [ $1 = "command" ]; then +../bin/occmd system.comp_all.echo +../bin/occmd ethernet.port0.reset +../bin/occmd ethernet.port1.reset +../bin/occmd ethernet.port2.reset +../bin/occmd ethernet.port3.reset +../bin/occmd ethernet.port4.reset +#../bin/occmd power.pse.reset +../bin/occmd rffe.comp_all.reset +../bin/occmd hci.led.fw.set 1 +../bin/occmd rffe.ch1_fe.enable +../bin/occmd rffe.ch1_fe.disable +../bin/occmd rffe.ch2_fe.disable +../bin/occmd rffe.ch2_fe.enable +../bin/occmd testmodule.2gsim.enable +../bin/occmd testmodule.2gsim.disable +../bin/occmd testmodule.2gsim.disconnect_nw +../bin/occmd testmodule.2gsim.connect_nw +../bin/occmd testmodule.2gsim.send 9789799425 hi +../bin/occmd testmodule.2gsim.dial 9789799425 +../bin/occmd testmodule.2gsim.answer +../bin/occmd testmodule.2gsim.hangup +../bin/occmd testmodule.comp_all.reset +../bin/occmd sdr.comp_all.reset +../bin/occmd sdr.fx3.reset +../bin/occmd obc.iridium.reset +../bin/occmd sync.comp_all.reset +../bin/occmd ethernet.port0.en_loopBk 0 +../bin/occmd ethernet.port0.en_pktGen 8374 +../bin/occmd ethernet.port0.dis_pktGen +../bin/occmd ethernet.port0.dis_loopBk 0 +../bin/occmd ethernet.port1.en_loopBk 0 +../bin/occmd ethernet.port1.en_pktGen 8374 +../bin/occmd ethernet.port1.dis_pktGen +../bin/occmd ethernet.port1.dis_loopBk 0 +../bin/occmd ethernet.port2.en_loopBk 0 +../bin/occmd ethernet.port2.en_pktGen 8374 +../bin/occmd ethernet.port2.dis_pktGen +../bin/occmd ethernet.port2.dis_loopBk 0 +../bin/occmd ethernet.port3.en_loopBk 0 +../bin/occmd ethernet.port3.en_pktGen 8374 +../bin/occmd ethernet.port3.dis_pktGen +../bin/occmd ethernet.port3.dis_loopBk 0 +../bin/occmd ethernet.port4.en_loopBk 0 +../bin/occmd ethernet.port4.en_pktGen 8374 +../bin/occmd ethernet.port4.dis_pktGen +../bin/occmd ethernet.port4.dis_loopBk 0 +else + echo "Invalid Option" +fi +echo "Done..." + diff --git a/firmware/host/scripts/set_config_params.sh b/firmware/host/scripts/set_config_params.sh new file mode 100755 index 0000000000..b68d62ab01 --- /dev/null +++ b/firmware/host/scripts/set_config_params.sh @@ -0,0 +1,198 @@ +#!/bin/sh +if [ -z "$1" ]; then + echo "Invalid Option" + echo "Usage : ./set_config_params " + exit +elif [ $1 = "post" ]; then +../bin/occmd system.comp_all.post.test.enable.set +elif [ $1 = "bms" ]; then +../bin/occmd bms.ec.config.temp_sensor1.lowlimit.set -19 +../bin/occmd bms.ec.config.temp_sensor1.highlimit.set 76 +../bin/occmd bms.ec.config.temp_sensor1.critlimit.set 85 +../bin/occmd bms.ec.config.current_sensor1.currlimit.set 1500 +../bin/occmd bms.ec.config.current_sensor2.currlimit.set 1500 +elif [ $1 = "gpp" ]; then +../bin/occmd gpp.ap.config.temp_sensor1.lowlimit.set -19 +../bin/occmd gpp.ap.config.temp_sensor1.highlimit.set 81 +../bin/occmd gpp.ap.config.temp_sensor1.critlimit.set 86 +../bin/occmd gpp.ap.config.temp_sensor2.lowlimit.set -19 +../bin/occmd gpp.ap.config.temp_sensor2.highlimit.set 81 +../bin/occmd gpp.ap.config.temp_sensor2.critlimit.set 86 +../bin/occmd gpp.ap.config.current_sensor1.currlimit.set 2010 +../bin/occmd gpp.ap.config.temp_sensor3.lowlimit.set -19 +../bin/occmd gpp.ap.config.temp_sensor3.highlimit.set 81 +../bin/occmd gpp.ap.config.temp_sensor3.critlimit.set 86 +../bin/occmd gpp.msata.config.current_sensor1.currlimit.set 2010 +elif [ $1 = "sdr" ]; then +../bin/occmd sdr.comp_all.config.current_sensor1.currlimit.set 2010 +../bin/occmd sdr.fpga.config.temp_sensor1.lowlimit.set -19 +../bin/occmd sdr.fpga.config.temp_sensor1.highlimit.set 76 +../bin/occmd sdr.fpga.config.temp_sensor1.critlimit.set 81 +../bin/occmd sdr.fpga.config.current_sensor1.currlimit.set 510 +elif [ $1 = "rf" ]; then +../bin/occmd rffe.ch1_sensor.config.temp_sensor1.lowlimit.set -19 +../bin/occmd rffe.ch1_sensor.config.temp_sensor1.highlimit.set 76 +../bin/occmd rffe.ch1_sensor.config.temp_sensor1.critlimit.set 81 +../bin/occmd rffe.ch1_sensor.config.current_sensor1.currlimit.set 1500 +../bin/occmd rffe.ch2_sensor.config.temp_sensor1.lowlimit.set -19 +../bin/occmd rffe.ch2_sensor.config.temp_sensor1.highlimit.set 76 +../bin/occmd rffe.ch2_sensor.config.temp_sensor1.critlimit.set 81 +../bin/occmd rffe.ch2_sensor.config.current_sensor1.currlimit.set 510 +../bin/occmd rffe.ch1_fe.config.ch1_band.band.set 3 +../bin/occmd rffe.ch1_fe.config.tx.atten.set 60 +../bin/occmd rffe.ch1_fe.config.rx.atten.set 20 +../bin/occmd rffe.ch2_fe.config.tx.atten.set 60 +../bin/occmd rffe.ch2_fe.config.rx.atten.set 20 +../bin/occmd rffe.ch2_fe.config.ch2_band.band.set 3 + +elif [ $1 = "power" ]; then +../bin/occmd power.leadacid_sensor.config.temp_sensor1.lowlimit.set -19 +../bin/occmd power.leadacid_sensor.config.temp_sensor1.highlimit.set 76 +../bin/occmd power.leadacid_sensor.config.temp_sensor1.critlimit.set 81 +../bin/occmd power.leadacid.config.battery.batteryVoltageLow.set 12500 +../bin/occmd power.leadacid.config.battery.batteryVoltageHigh.set 16500 +../bin/occmd power.leadacid.config.battery.batteryCurrentLow.set 900 +../bin/occmd power.leadacid.config.battery.inputVoltageLow.set 16210 +../bin/occmd power.leadacid.config.battery.inputCurrentHigh.set 17400 +../bin/occmd power.leadacid.config.battery.inputCurrentLimit.set 15000 +#../bin/occmd power.leadacid.config.battery.maxcurr_chargesetting.set 10000 +../bin/occmd power.leadacid.config.battery.vcharge.set 10660 +../bin/occmd power.leadacid.config.battery.icharge.set 12000 +../bin/occmd power.lion.config.battery.batteryVoltageLow.set 9010 +../bin/occmd power.lion.config.battery.batteryVoltageHigh.set 12700 +../bin/occmd power.lion.config.battery.batteryCurrentLow.set 110 +../bin/occmd power.lion.config.battery.inputVoltageLow.set 16210 +../bin/occmd power.lion.config.battery.inputCurrentHigh.set 5010 +../bin/occmd power.lion.config.battery.inputCurrentLimit.set 3580 +../bin/occmd power.lion.config.battery.vcharge.set 10660 +../bin/occmd power.lion.config.battery.icharge.set 12000 +../bin/occmd power.pse.config.operatingMode.set 3 +../bin/occmd power.pse.config.detectEnable.set 64 +../bin/occmd power.pse.config.interruptMask.set 195 +../bin/occmd power.pse.config.interruptEnable.set 128 +../bin/occmd power.pse.config.enableHighpower.set 17 +elif [ $1 = "ethernet" ]; then +../bin/occmd ethernet.port0.config.speed.set 0 +../bin/occmd ethernet.port0.config.duplex.set 2 +../bin/occmd ethernet.port0.config.powerDown.set 0 +../bin/occmd ethernet.port0.config.enable_sleepMode.set 1 +../bin/occmd ethernet.port0.config.enable_interrupt.set 10 +../bin/occmd ethernet.port1.config.speed.set 1 +../bin/occmd ethernet.port1.config.duplex.set 0 +../bin/occmd ethernet.port1.config.powerDown.set 1 +../bin/occmd ethernet.port1.config.enable_sleepMode.set 0 +../bin/occmd ethernet.port1.config.enable_interrupt.set 1 +../bin/occmd ethernet.port2.config.speed.set 1 +../bin/occmd ethernet.port2.config.duplex.set 1 +../bin/occmd ethernet.port2.config.powerDown.set 1 +../bin/occmd ethernet.port2.config.enable_sleepMode.set 1 +../bin/occmd ethernet.port2.config.enable_interrupt.set 0 +../bin/occmd ethernet.port3.config.speed.set 1 +../bin/occmd ethernet.port3.config.duplex.set 0 +../bin/occmd ethernet.port3.config.powerDown.set 0 +../bin/occmd ethernet.port3.config.enable_sleepMode.set 1 +../bin/occmd ethernet.port3.config.enable_interrupt.set 1 +../bin/occmd ethernet.port4.config.speed.set 1 +../bin/occmd ethernet.port4.config.duplex.set 1 +../bin/occmd ethernet.port4.config.powerDown.set 1 +../bin/occmd ethernet.port4.config.enable_sleepMode.set 1 +../bin/occmd ethernet.port4.config.enable_interrupt.set 1 +elif [ $1 = "sync" ]; then +../bin/occmd sync.sensor.config.temp_sensor1.lowlimit.set -19 +../bin/occmd sync.sensor.config.temp_sensor1.highlimit.set 81 +../bin/occmd sync.sensor.config.temp_sensor1.critlimit.set 86 +elif [ $1 = "hci" ]; then +../bin/occmd hci.led.config.temp_sensor1.lowlimit.set -19 +../bin/occmd hci.led.config.temp_sensor1.highlimit.set 76 +../bin/occmd hci.led.config.temp_sensor1.critlimit.set 85 +elif [ $1 = "debug" ]; then +if [ $2 = "I2C" ]; then +if [ $3 = "stub" ]; then +../bin/occmd debug.I2C.bus0.set 1 1 1 1 +../bin/occmd debug.I2C.bus1.set 1 1 1 1024 +../bin/occmd debug.I2C.bus2.set 1 1 1 2 +../bin/occmd debug.I2C.bus3.set 1 1 1 1025 +../bin/occmd debug.I2C.bus4.set 1 1 1 3 +../bin/occmd debug.I2C.bus6.set 1 1 1 4 +../bin/occmd debug.I2C.bus7.set 1 1 1 1027 +../bin/occmd debug.I2C.bus8.set 1 1 1 5 +elif [ $3 = "FW" ]; then +../bin/occmd debug.I2C.bus0.set 104 2 58 7000 +../bin/occmd debug.I2C.bus1.set 24 2 2 1024 +../bin/occmd debug.I2C.bus2.set 29 1 0 100 +../bin/occmd debug.I2C.bus3.set 68 2 255 8000 +../bin/occmd debug.I2C.bus4.set 65 2 254 21500 +../bin/occmd debug.I2C.bus6.set 64 2 5 25500 +../bin/occmd debug.I2C.bus7.set 69 2 5 25500 +../bin/occmd debug.I2C.bus8.set 26 2 6 4000 +else +echo "Invalid Option" +fi +elif [ $2 = "GPIO" ]; then +if [ $3 = "stub" ]; then +../bin/occmd debug.ec.PA.set 1 1 +../bin/occmd debug.ec.PB.set 1 1 +../bin/occmd debug.ec.PC.set 1 1 +../bin/occmd debug.ec.PD.set 1 0 +../bin/occmd debug.ec.PE.set 1 0 +../bin/occmd debug.ec.PF.set 1 1 +../bin/occmd debug.ec.PG.set 1 1 +../bin/occmd debug.ec.PJ.set 1 1 +../bin/occmd debug.ec.PK.set 1 1 +../bin/occmd debug.ec.PL.set 1 1 +../bin/occmd debug.ec.PM.set 1 0 +../bin/occmd debug.ec.PN.set 1 0 +../bin/occmd debug.ec.PP.set 1 0 +../bin/occmd debug.ec.PQ.set 1 0 + +../bin/occmd debug.gbc.ioexpanderx70.set 1 0 +../bin/occmd debug.gbc.ioexpanderx71.set 1 0 +../bin/occmd debug.sdr.ioexpanderx1E.set 1 0 +../bin/occmd debug.fe.ioexpanderx18.set 1 0 +../bin/occmd debug.fe.ioexpanderx1A.set 1 1 +../bin/occmd debug.fe.ioexpanderx1B.set 1 0 +../bin/occmd debug.fe.ioexpanderx1C.set 1 0 +../bin/occmd debug.fe.ioexpanderx1D.set 1 1 +../bin/occmd debug.sync.ioexpanderx71.set 1 1 +elif [ $3 = "FW" ]; then +../bin/occmd debug.ec.PA.set 1 1 +../bin/occmd debug.ec.PB.set 1 1 +../bin/occmd debug.ec.PC.set 1 1 +../bin/occmd debug.ec.PD.set 7 0 +../bin/occmd debug.ec.PE.set 1 0 +../bin/occmd debug.ec.PF.set 1 1 +../bin/occmd debug.ec.PG.set 1 1 +../bin/occmd debug.ec.PH.set 1 1 +../bin/occmd debug.ec.PJ.set 1 1 +../bin/occmd debug.ec.PK.set 1 1 +../bin/occmd debug.ec.PL.set 5 1 +../bin/occmd debug.ec.PM.set 1 0 +../bin/occmd debug.ec.PN.set 1 0 +../bin/occmd debug.ec.PP.set 3 0 +../bin/occmd debug.ec.PQ.set 1 0 + +../bin/occmd debug.gbc.ioexpanderx70.set 1 0 +../bin/occmd debug.gbc.ioexpanderx71.set 0 0 +../bin/occmd debug.sdr.ioexpanderx1E.set 1 0 +../bin/occmd debug.fe.ioexpanderx18.set 1 0 +../bin/occmd debug.fe.ioexpanderx1A.set 0 1 +../bin/occmd debug.fe.ioexpanderx1B.set 1 0 +../bin/occmd debug.fe.ioexpanderx1C.set 1 0 +../bin/occmd debug.fe.ioexpanderx1D.set 1 1 +../bin/occmd debug.sync.ioexpanderx71.set 1 1 +else +echo "Invalid Option" +fi +elif [ $2 = "MDIO" ]; then +../bin/occmd debug.ethernet.port0.set 18 1024 +../bin/occmd debug.ethernet.global1.set 4 128 +../bin/occmd debug.ethernet.global2.set 1 31 +../bin/occmd debug.ethernet.swport0.set 1 1 +else +echo "Invalid Option" +fi + +else + echo "Invalid Option" +fi +echo "Done..." diff --git a/firmware/host/scripts/test_all.sh b/firmware/host/scripts/test_all.sh new file mode 100755 index 0000000000..4bf5f76791 --- /dev/null +++ b/firmware/host/scripts/test_all.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +echo "##############################" +echo " GET CONFIG PARAMS - 1 " +echo "##############################" +./get_params.sh bms config default +./get_params.sh gpp config default +./get_params.sh sdr config default +./get_params.sh rf config default +./get_params.sh power config default +./get_params.sh ethernet config default +./get_params.sh sync config default +./get_params.sh hci config default + +echo "##############################" +echo " SET CONFIG PARAMS " +echo "##############################" +./set_config_params.sh bms +./set_config_params.sh gpp +./set_config_params.sh sdr +./set_config_params.sh rf +./set_config_params.sh power +./set_config_params.sh ethernet +./set_config_params.sh sync +./set_config_params.sh hci + +echo "##############################" +echo " GET CONFIG PARAMS - 2 " +echo "##############################" +./get_params.sh bms config verify +./get_params.sh gpp config verify +./get_params.sh sdr config verify +./get_params.sh rf config verify +./get_params.sh power config verify +./get_params.sh ethernet config verify +./get_params.sh sync config verify +./get_params.sh hci config verify + +echo "##############################" +echo " POST COMMANDS " +echo "##############################" +./get_params.sh system post + +echo "##############################" +echo " GET STATUS PARAMS " +echo "##############################" +./get_params.sh bms status +./get_params.sh gpp status +./get_params.sh sdr status +./get_params.sh rf status +./get_params.sh power status +./get_params.sh ethernet status +./get_params.sh sync status +./get_params.sh testmodule status +./get_params.sh obc status +./get_params.sh hci status +./get_params.sh system status + +echo "##############################" +echo " GET COMMANDS - 1 " +echo "##############################" +./get_params.sh command + +echo "##############################" +echo " GET DEBUG COMMANDS - 1 " +echo "##############################" +./get_params.sh debug I2C default +./get_params.sh debug GPIO default +./get_params.sh debug MDIO default + +echo "##############################" +echo " SET DEBUG COMMANDS " +echo "##############################" +./set_config_params.sh debug I2C FW +./set_config_params.sh debug GPIO FW +./set_config_params.sh debug MDIO + +echo "##############################" +echo " GET DEBUG COMMANDS - 2 " +echo "##############################" +./get_params.sh debug I2C verify +./get_params.sh debug GPIO verify +./get_params.sh debug MDIO verify + +echo " >>> TESTING DONE <<< " diff --git a/firmware/host/util/logger.c b/firmware/host/util/logger.c new file mode 100644 index 0000000000..b7f63ac94f --- /dev/null +++ b/firmware/host/util/logger.c @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* OC includes */ +#include + +/************************************************************************** + * Function Name : initlog + * Description : This Function used to initialize the logging + * functionality + * Input(s) : ident + * Output(s) : + ***************************************************************************/ +void initlog(const char* ident) +{ + openlog(ident, LOG_CONS | LOG_PID, LOG_USER); +} + +/************************************************************************** + * Function Name : deinitlog + * Description : This Function used to uninitialize logging + * functionality + * Input(s) : + * Output(s) : + ***************************************************************************/ +void deinitlog(void) +{ + closelog(); +} diff --git a/firmware/host/util/util.c b/firmware/host/util/util.c new file mode 100644 index 0000000000..819932c6fa --- /dev/null +++ b/firmware/host/util/util.c @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +/* stdlib includes */ +#include +#include + +#define UTIL_NUMBER_ZERO 0 + +void hexdisp(const unsigned char* buf, int buflen) +{ + int c=UTIL_NUMBER_ZERO, i=UTIL_NUMBER_ZERO; + for (c=UTIL_NUMBER_ZERO; c0x20 && buf[i]<0x7F) ? buf[i] : '.'); + printf("\n"); + } + } + printf("\n"); +}