21 #include "rdk_moca_hal.h"
26 handle=malloc(
sizeof(*handle));
27 BRMH_RETURN_IF(handle==NULL, NULL);
28 memset(handle, 0,
sizeof(*handle));
29 handle->printBuf=malloc(RMH_MAX_PRINT_LINE_SIZE);
30 handle->logLevelBitMask=RMH_LOG_ERROR;
31 if (!handle->printBuf) {
32 RMH_PrintErr(
"Unable to allocate print buf of size %u!\n", RMH_MAX_PRINT_LINE_SIZE);
35 handle->eventCB=eventCB;
36 handle->eventCBUserContext=userContext;
37 handle->soclib = dlopen(
"librdkmocahalsoc.so.0", RTLD_LAZY);
39 char *dlErr = dlerror();
40 RMH_Handle (*apiFunc)() = dlsym(handle->soclib,
"RMH_Initialize");
43 RMH_PrintTrace(
"Error 'RMH_Initialize' in dlopen: '%s'. APIs will return RMH_INVALID_INTERNAL_STATE!\n", dlErr);
46 RMH_PrintErr(
"Unable to find 'RMH_Initialize' in SoC library! APIs will return RMH_INVALID_INTERNAL_STATE!\n");
49 handle->handle = apiFunc(eventCB, userContext);
50 if (!handle->handle) {
51 RMH_PrintErr(
"Failed when initializing the SoC MoCA Hal!\n");
57 RMH_PrintWrn(
"Failed to open the SoC library 'librdkmocahalsoc.so.0', all MoCA APIs will return RMH_UNIMPLEMENTED! Please ensure it's properly installed on this system\n");
59 RMH_PrintTrace(
"Initialized generic handle:0x%p socHandle:0x%p\n", handle, handle->handle);
70 __attribute__((visibility(
"hidden"))) const
char * const RMH_ResultStr[] = { ENUM_RMH_Result };
71 __attribute__((visibility(
"hidden"))) const
char * const RMH_LinkStatusStr[] = { ENUM_RMH_LinkStatus };
72 __attribute__((visibility(
"hidden"))) const
char * const RMH_AdmissionStatusStr[] = { ENUM_RMH_AdmissionStatus };
73 __attribute__((visibility(
"hidden"))) const
char * const RMH_PowerModeStr[] = { ENUM_RMH_PowerMode };
74 __attribute__((visibility(
"hidden"))) const
char * const RMH_BandStr[] = { ENUM_RMH_Band };
75 __attribute__((visibility(
"hidden"))) const
char * const RMH_MoCAVersionStr[] = { ENUM_RMH_MoCAVersion };
76 __attribute__((visibility(
"hidden"))) const
char * const RMH_LogLevelStr[] = { ENUM_RMH_LogLevel };
77 __attribute__((visibility(
"hidden"))) const
char * const RMH_EventStr[] = { ENUM_RMH_Event };
78 __attribute__((visibility(
"hidden"))) const
char * const RMH_ACATypeStr[] = { ENUM_RMH_ACAType };
79 __attribute__((visibility(
"hidden"))) const
char * const RMH_ACAStatusStr[] = { ENUM_RMH_ACAStatus };
80 __attribute__((visibility(
"hidden"))) const
char * const RMH_MoCAResetReasonStr[] = { ENUM_RMH_MoCAResetReason };
81 __attribute__((visibility(
"hidden"))) const
char * const RMH_SubcarrierProfileStr[] = { ENUM_RMH_SubcarrierProfile };
82 __attribute__((visibility(
"hidden"))) const
char * const RMH_PERModeStr[] = { ENUM_RMH_PERMode };
85 return RMH_ResultStr[value];
89 return RMH_LinkStatusStr[value];
93 return RMH_AdmissionStatusStr[value];
97 return RMH_BandStr[value];
101 return RMH_ACATypeStr[value];
105 return RMH_ACAStatusStr[value];
109 return RMH_MoCAResetReasonStr[value];
113 return RMH_SubcarrierProfileStr[value];
117 return RMH_PERModeStr[value];
124 case RMH_MOCA_VERSION_UNKNOWN:
127 case RMH_MOCA_VERSION_10:
130 case RMH_MOCA_VERSION_11:
133 case RMH_MOCA_VERSION_20:
137 return RMH_MoCAVersionStr[value];
143 const char*
const RMH_BitMAskToString(
const uint32_t value,
char* responseBuf,
const size_t responseBufSize,
const char *
const fixedStrings[],
const uint32_t numFixedStrings) {
147 for(i=0; i < numFixedStrings; i ++) {
148 if ((value & (1u<<i)) == (1u<<i)) {
149 if (responseBufSize <= strlen(responseBuf) + strlen(fixedStrings[i]) + 3) {
150 return "Buffer too small!";
152 if (strlen(responseBuf)) {
153 strcat(responseBuf,
" | ");
155 strcat(responseBuf, fixedStrings[i]);
163 return RMH_BitMAskToString(value, responseBuf, responseBufSize, RMH_PowerModeStr,
sizeof(RMH_PowerModeStr)/
sizeof(RMH_PowerModeStr[0]));
166 const char*
const RMH_LogLevelToString(
const uint32_t value,
char* responseBuf,
const size_t responseBufSize) {
167 return RMH_BitMAskToString(value, responseBuf, responseBufSize, RMH_LogLevelStr,
sizeof(RMH_LogLevelStr)/
sizeof(RMH_LogLevelStr[0]));
170 const char*
const RMH_EventToString(
const uint32_t value,
char* responseBuf,
const size_t responseBufSize) {
171 return RMH_BitMAskToString(value, responseBuf, responseBufSize, RMH_EventStr,
sizeof(RMH_EventStr)/
sizeof(RMH_EventStr[0]));
174 const char*
const RMH_MacToString(
const RMH_MacAddress_t mac,
char* responseBuf,
const size_t responseBufSize) {
175 if (responseBuf && responseBufSize >= 18 ) {
176 int written=snprintf(responseBuf, responseBufSize,
"%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
177 if ((written > 0) && (written < responseBufSize))
180 return "Buffer too small!";