24 #define RDK_FILE_PATH_PREVENT_MOCA_START "/opt/sysproperties/mocakillswitchenable"
25 #define RDK_FILE_PATH_PREVENT_MOCA_START2 "/opt/mocakillswitchenable"
29 const char *
const RMH_LogLevelStr[] = { ENUM_RMH_LogLevel };
35 RMH_Result RMHApp_DisableDriverDebugLogging(
const RMHApp *app) {
37 RMH_LogLevel logLevel;
40 RMH_PrintMsg(
"MoCA stopping logging to %s\n", fileName);
43 RMH_PrintErr(
"Failed to stop logging!\n");
49 RMH_PrintErr(
"Failed to get driver log level!\n");
53 if ((~logLevel & RMH_LOG_DEBUG) == RMH_LOG_DEBUG) {
54 RMH_PrintMsg(
"MoCA driver debug logging already disabled\n");
59 RMH_PrintErr(
"Failed to set log level to exclude RMH_LOG_DEFAULT!\n");
62 RMH_PrintMsg(
"MoCA driver debug logging disabled\n");
67 RMH_Result RMHApp_EnableDriverDebugLogging(
const RMHApp *app) {
68 char logFileName[1024];
69 RMH_LogLevel logLevel;
72 RMH_PrintMsg(
"Logging to '%s'\n", logFileName);
76 RMH_PrintErr(
"Failed to get driver log level!\n");
80 if ((logLevel & RMH_LOG_DEBUG) == RMH_LOG_DEBUG) {
81 RMH_PrintMsg(
"MoCA driver debug logging already enabled\n");
86 RMH_PrintErr(
"Failed to set driver log level to include RMH_LOG_DEBUG!\n");
89 RMH_PrintMsg(
"MoCA driver debug logging enabled\n");
93 RMH_Result RMHApp_DriverLogForever(
const RMHApp *app) {
94 char logFileName[1024];
95 RMH_LogLevel logLevel;
98 RMH_PrintMsg(
"Stop logging to '%s'.\n", logFileName);
102 RMH_PrintErr(
"Unable to create dedicated log file!\n");
107 RMH_PrintErr(
"Unable to start logging in %s!\n", logFileName);
112 RMH_PrintErr(
"Failed to get driver log level!\n");
116 if ((logLevel & RMH_LOG_DEBUG) != RMH_LOG_DEBUG) {
118 RMH_PrintErr(
"Failed to set log level to RMH_LOG_DEBUG!\n");
122 RMH_PrintMsg(
"Started logging enabled to '%s'.\n", logFileName);
126 RMH_Result RMHApp_Stop(
const RMHApp *app) {
131 RMH_PrintErr(
"MoCA is already stopped\n");
132 return RMH_INVALID_INTERNAL_STATE;
136 if (ret == RMH_SUCCESS) {
137 RMH_PrintMsg(
"MoCA successfully stopped\n");
142 RMH_Result RMHApp_Start(
const RMHApp *app) {
143 bool started =
false;
147 RMH_PrintErr(
"MoCA is already started\n");
148 return RMH_INVALID_INTERNAL_STATE;
151 if (access(RDK_FILE_PATH_PREVENT_MOCA_START, F_OK ) != -1) {
152 RMH_PrintWrn(
"Refusing to start MoCA because the file %s exists!\n", RDK_FILE_PATH_PREVENT_MOCA_START);
154 else if (access(RDK_FILE_PATH_PREVENT_MOCA_START2, F_OK ) != -1) {
155 RMH_PrintWrn(
"Refusing to start MoCA because the file %s exists!\n", RDK_FILE_PATH_PREVENT_MOCA_START2);
159 if (ret == RMH_SUCCESS) {
160 RMH_PrintMsg(
"MoCA successfully started\n");
170 const char * RMHApp_ReadNextArg(
RMHApp *app) {
171 const char *str=NULL;
172 if (app->argc >= 1) {
174 app->argv=&app->argv[1];
181 uint32_t ReadLine(
const char *prompt,
RMHApp *app,
char *buf,
const uint32_t bufSize) {
182 const char *input=NULL;
183 if (app->argRunCommand == NULL) {
185 RMH_PrintMsg(
"%s", prompt);
186 input=fgets(buf, bufSize, stdin);
188 buf[strcspn(buf,
"\n")] =
'\0';
192 input=RMHApp_ReadNextArg(app);
194 strncpy(buf, input, bufSize);
199 return (input && strlen(input)) ? strlen(input) : 0;
202 RMH_Result RMHApp_ReadMenuOption(
RMHApp *app, uint32_t *value,
bool helpSupported,
bool *helpRequested) {
204 if (ReadLine(
"Enter your choice (number): ", app, input,
sizeof(input))) {
206 *value=(uint32_t)strtol(input, &end, 10);
207 if (end != input && errno != ERANGE) {
209 if (helpRequested != NULL) *helpRequested=
false;
212 else if (helpSupported && end[0] ==
'?' && end[1] ==
'\0') {
213 if (helpRequested != NULL) *helpRequested=
true;
218 RMH_PrintErr(
"Bad input. Please enter a valid unsigned number\n");
223 RMH_Result RMHApp_ReadUint32(
RMHApp *app, uint32_t *value) {
225 if (ReadLine(
"Enter your choice (number): ", app, input,
sizeof(input))) {
227 *value=(uint32_t)strtol(input, &end, 10);
228 if (end != input && *end ==
'\0' && errno != ERANGE) {
232 RMH_PrintErr(
"Bad input. Please enter a valid unsigned number\n");
237 RMH_Result RMHApp_ReadMAC(
RMHApp *app, RMH_MacAddress_t* response) {
242 if (ReadLine(
"Enter MAC address (XX:XX:XX:XX:XX:XX): ", app, input,
sizeof(input)) == 17) {
243 if(sscanf( input,
"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx%c", &val[0], &val[1], &val[2], &val[3], &val[4], &val[5], &dummy) == 6) {
244 for( i = 0; i < 6; i++ ) (*response)[i] = (uint8_t)val[i];
248 RMH_PrintErr(
"Bad input. Please enter a valid MAC address in the for 'XX:XX:XX:XX:XX:XX':\n");
253 RMH_Result RMHApp_ReadLogLevel(
RMHApp *app, uint32_t *value) {
257 if (ReadLine(
"Enter your choice (number or string): ", app, input,
sizeof(input))) {
259 *value=(uint32_t)strtol(input, &end, 10);
260 if (end != input && *end ==
'\0' && errno != ERANGE &&
261 *value>=0 && *value<
sizeof(RMH_LogLevelStr)/
sizeof(RMH_LogLevelStr[0])) {
264 for(i=0; i!=
sizeof(RMH_LogLevelStr)/
sizeof(RMH_LogLevelStr[0]); i++) {
265 if (strcasecmp(input, RMH_LogLevelStr[i]) == 0) {
271 RMH_PrintErr(
"Bad input. Please enter a valid number or log level\n");
276 RMH_Result RMHApp_ReadInt32(
RMHApp *app, int32_t *value) {
278 if (ReadLine(
"Enter your choice (number): ", app, input,
sizeof(input))) {
280 *value=(uint32_t)strtol(input, &end, 10);
281 if (end != input && *end ==
'\0' && errno != ERANGE) {
285 RMH_PrintErr(
"Bad input. Please enter a valid signed number\n");
290 RMH_Result RMHApp_ReadUint32Hex(
RMHApp *app, uint32_t *value) {
292 if (ReadLine(
"Enter your choice (Hex): ", app, input,
sizeof(input))) {
294 *value=(uint32_t)strtol(input, &end, 0);
295 if (end != input && *end ==
'\0' && errno != ERANGE) {
299 RMH_PrintErr(
"Bad input. Please enter a valid unsigned number\n");
304 RMH_Result RMHApp_ReadBool(
RMHApp *app,
bool *value) {
306 if (ReadLine(
"Enter your choice (TRUE,FALSE or 1,0): ", app, input,
sizeof(input))) {
307 if ((strcmp(input,
"1") == 0) || (strcasecmp(input,
"TRUE") == 0)) {
311 else if ((strcmp(input,
"0") == 0) || (strcasecmp(input,
"FALSE") == 0)) {
316 RMH_PrintErr(
"Bad input. Please use only TRUE,FALSE or 1,0\n");
321 RMH_Result RMHApp_ReadString(
RMHApp *app,
char *buf,
const uint32_t bufSize) {
322 if (ReadLine(
"Enter your choice: ", app, buf, bufSize)) {
325 RMH_PrintErr(
"Bad input. Please provide a valid string.\n");
330 RMH_Result RMHApp_ReadACAType(
RMHApp *app, RMH_ACAType *value) {
333 snprintf(choices,
sizeof(choices)/
sizeof(choices[0]),
"Enter your choice [EVM(%u),QUIET(%u)]: ", RMH_ACA_TYPE_EVM, RMH_ACA_TYPE_QUIET);
335 if (ReadLine(choices, app, input,
sizeof(input))) {
336 int inputAsInt=(int)(input[0] -
'0');
337 if ((inputAsInt == RMH_ACA_TYPE_EVM) || (strcasecmp(input,
"RMH_ACA_TYPE_EVM") == 0) || (strcasecmp(input,
"EVM") == 0)) {
338 *value=RMH_ACA_TYPE_EVM;
341 else if ((inputAsInt == RMH_ACA_TYPE_QUIET) || (strcasecmp(input,
"RMH_ACA_TYPE_QUIET") == 0) || (strcasecmp(input,
"QUIET") == 0)) {
342 *value=RMH_ACA_TYPE_QUIET;
346 RMH_PrintErr(
"Bad input\n");
351 RMH_Result RMHApp_ReadPowerMode(
RMHApp *app, RMH_PowerMode *value) {
354 snprintf(choices,
sizeof(choices)/
sizeof(choices[0]),
"Enter your choice [ACTIVE(%u),IDLE(%u),STANDBY(%u),SLEEP(%u)]: ", RMH_POWER_MODE_M0_ACTIVE, RMH_POWER_MODE_M1_IDLE, RMH_POWER_MODE_M2_STANDBY, RMH_POWER_MODE_M3_SLEEP);
355 if (ReadLine(choices, app, input,
sizeof(input))) {
356 int inputAsInt=(int)(input[0] -
'0');
357 if ((inputAsInt == RMH_POWER_MODE_M0_ACTIVE) || (strcasecmp(input,
"RMH_POWER_MODE_M0_ACTIVE") == 0) || (strcasecmp(input,
"ACTIVE") == 0)) {
358 *value=RMH_POWER_MODE_M0_ACTIVE;
361 else if ((inputAsInt == RMH_POWER_MODE_M1_IDLE) || (strcasecmp(input,
"RMH_POWER_MODE_M1_IDLE") == 0) || (strcasecmp(input,
"IDLE") == 0)) {
362 *value=RMH_POWER_MODE_M1_IDLE;
365 else if ((inputAsInt == RMH_POWER_MODE_M2_STANDBY) || (strcasecmp(input,
"RMH_POWER_MODE_M2_STANDBY") == 0) || (strcasecmp(input,
"STANDBY") == 0)) {
366 *value=RMH_POWER_MODE_M2_STANDBY;
369 else if ((inputAsInt == RMH_POWER_MODE_M3_SLEEP) || (strcasecmp(input,
"RMH_POWER_MODE_M3_SLEEP") == 0) || (strcasecmp(input,
"SLEEP") == 0)) {
370 *value=RMH_POWER_MODE_M3_SLEEP;
374 RMH_PrintErr(
"Bad input\n");
379 RMH_Result RMHApp_ReadPERMode(
RMHApp *app, RMH_PERMode *value) {
381 if (ReadLine(
"Enter your choice (LEGACY,NPER,VLPER or 0,1,2): ", app, input,
sizeof(input))) {
382 if ((strcmp(input,
"0") == 0) || (strcasecmp(input,
"RMH_PER_MODE_LEGACY") == 0) || (strcasecmp(input,
"LEGACY") == 0)) {
383 *value=RMH_PER_MODE_LEGACY;
386 else if ((strcmp(input,
"1") == 0) || (strcasecmp(input,
"RMH_PER_MODE_NOMINAL") == 0) || (strcasecmp(input,
"NPER") == 0)) {
387 *value=RMH_PER_MODE_NOMINAL;
390 else if ((strcmp(input,
"2") == 0) || (strcasecmp(input,
"RMH_PER_MODE_VERY_LOW") == 0) || (strcasecmp(input,
"VLPER") == 0)) {
391 *value=RMH_PER_MODE_VERY_LOW;
395 RMH_PrintErr(
"Bad input. Please use only LEGACY,NPER,VLPER or 0,1,2\n");
404 RMH_Result RMHApp__OUT_UINT32(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, uint32_t* response)) {
406 RMH_Result ret = api(app->rmh, &response);
407 if (ret == RMH_SUCCESS) {
408 RMH_PrintMsg(
"%u\n", response);
414 RMH_Result RMHApp__OUT_UINT32_HEX(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, uint32_t* response)) {
416 RMH_Result ret = api(app->rmh, &response);
417 if (ret == RMH_SUCCESS) {
418 RMH_PrintMsg(
"0x%08x\n", response);
424 RMH_Result RMHApp__OUT_INT32(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, int32_t* response)) {
426 RMH_Result ret = api(app->rmh, &response);
427 if (ret == RMH_SUCCESS) {
428 RMH_PrintMsg(
"%d\n", response);
434 RMH_Result RMHApp__OUT_UINT32_ARRAY(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, uint32_t* responseBuf,
const size_t responseBufSize,
size_t* responseBufUsed)) {
435 uint32_t responseBuf[256];
436 size_t responseBufUsed;
439 RMH_Result ret = api(app->rmh, responseBuf,
sizeof(responseBuf)/
sizeof(responseBuf[0]), &responseBufUsed);
440 if (ret == RMH_SUCCESS) {
441 for (i=0; i < responseBufUsed; i++) {
442 RMH_PrintMsg(
"[%02u] %u\n", i, responseBuf[i]);
449 RMH_Result RMHApp__OUT_MAC_ARRAY(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_MacAddress_t* responseBuf,
const size_t responseBufSize,
size_t* responseBufUsed)) {
450 RMH_MacAddress_t responseBuf[32];
451 size_t responseBufUsed;
455 RMH_Result ret = api(app->rmh, responseBuf,
sizeof(responseBuf)/
sizeof(responseBuf[0]), &responseBufUsed);
456 if (ret == RMH_SUCCESS) {
457 for (i=0; i < responseBufUsed; i++) {
458 RMH_PrintMsg(
"[%02u] %s\n", i,
RMH_MacToString(responseBuf[i], macStr,
sizeof(macStr)/
sizeof(macStr[0])));
465 RMH_Result RMHApp__IN_UINT32_OUT_UINT32(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId, uint32_t* response)) {
468 RMH_Result ret=RMHApp_ReadUint32(app, &nodeId);
469 if (ret == RMH_SUCCESS) {
470 ret = api(app->rmh, nodeId, &response);
471 if (ret == RMH_SUCCESS) {
472 RMH_PrintMsg(
"%u\n", response);
479 RMH_Result RMHApp__IN_UINT32_IN_UINT32(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId,
const uint32_t value)) {
480 uint32_t nodeId, value;
481 RMH_PrintMsg(
"Enter a node ID first, then the desired value\n", value, nodeId);
482 RMH_Result ret=RMHApp_ReadUint32(app, &nodeId);
483 if (ret == RMH_SUCCESS) {
484 RMH_Result ret=RMHApp_ReadUint32(app, &value);
485 if (ret == RMH_SUCCESS) {
486 ret = api(app->rmh, nodeId, value);
487 if (ret == RMH_SUCCESS) {
488 RMH_PrintMsg(
"Success passing %u for node id %u\n", value, nodeId);
496 RMH_Result RMHApp__IN_UINT32_OUT_INT32(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId, int32_t* response)) {
499 RMH_Result ret=RMHApp_ReadUint32(app, &nodeId);
500 if (ret == RMH_SUCCESS) {
501 ret = api(app->rmh, nodeId, &response);
502 if (ret == RMH_SUCCESS) {
503 RMH_PrintMsg(
"%d\n", response);
510 RMH_Result RMHApp__IN_UINT32_OUT_FLOAT(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId,
float* response)) {
513 RMH_Result ret=RMHApp_ReadUint32(app, &nodeId);
514 if (ret == RMH_SUCCESS) {
515 ret = api(app->rmh, nodeId, &response);
516 if (ret == RMH_SUCCESS) {
517 RMH_PrintMsg(
"%.03f\n", response);
524 RMH_Result RMHApp__OUT_BOOL(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
bool* response)) {
526 RMH_Result ret = api(app->rmh, &response);
527 if (ret == RMH_SUCCESS) {
528 RMH_PrintMsg(
"%s\n", response ?
"TRUE" :
"FALSE");
534 RMH_Result RMHApp__IN_UINT32_OUT_BOOL(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId,
bool* response)) {
537 RMH_Result ret=RMHApp_ReadUint32(app, &nodeId);
538 if (ret == RMH_SUCCESS) {
539 ret = api(app->rmh, nodeId, &response);
540 if (ret == RMH_SUCCESS) {
541 RMH_PrintMsg(
"%s\n", response ?
"TRUE" :
"FALSE");
548 RMH_Result RMHApp__OUT_STRING(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
char* responseBuf,
const size_t responseBufSize)) {
550 RMH_Result ret = api(app->rmh, response,
sizeof(response));
551 if (ret == RMH_SUCCESS) {
552 RMH_PrintMsg(
"%s\n", response);
558 RMH_Result RMHApp__OUT_UINT8_ARRAY(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, uint8_t* responseArray,
const size_t responseArraySize,
size_t* responseArrayUsed)) {
559 uint8_t responseBuf[1024];
560 size_t responseBufUsed;
563 RMH_Result ret = api(app->rmh, responseBuf,
sizeof(responseBuf)/
sizeof(responseBuf[0]), &responseBufUsed);
564 if (ret == RMH_SUCCESS) {
565 for (i=0; i < responseBufUsed;) {
566 RMH_PrintMsg(
"[%04u] ", i);
567 for (j=0; j < 16 && i < responseBufUsed; j++,i++) {
569 RMH_PrintMsg(
"%02u ", responseBuf[i]);
572 RMH_PrintMsg(
"%02u ", responseBuf[i]);
582 RMH_Result RMHApp__IN_UINT32_OUT_STRING(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId,
char* responseBuf,
const size_t responseBufSize)) {
585 RMH_Result ret=RMHApp_ReadUint32(app, &nodeId);
586 if (ret == RMH_SUCCESS) {
587 ret = api(app->rmh, nodeId, response,
sizeof(response));
588 if (ret == RMH_SUCCESS) {
589 RMH_PrintMsg(
"%s\n", response);
596 RMH_Result RMHApp__IN_RMH_ENUM(
RMHApp *app,
const char*
const (*api)(
const RMH_Result)) {
597 RMH_Result enumIndex;
598 RMH_Result ret=RMHApp_ReadUint32(app, (uint32_t*)&enumIndex);
599 if (ret == RMH_SUCCESS) {
600 const char * str = api(enumIndex);
602 RMH_PrintMsg(
"%s\n", str);
609 RMH_Result RMHApp__OUT_MAC(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_MacAddress_t* response)) {
610 RMH_MacAddress_t response;
611 RMH_Result ret = api(app->rmh, &response);
612 if (ret == RMH_SUCCESS) {
614 RMH_PrintMsg(
"%s\n",
RMH_MacToString(response, mac,
sizeof(mac)/
sizeof(mac[0])));
620 RMH_Result RMHApp__IN_MAC(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const RMH_MacAddress_t value)) {
621 RMH_MacAddress_t mac;
622 RMH_Result ret=RMHApp_ReadMAC(app, &mac);
623 if (ret == RMH_SUCCESS) {
624 ret = api(app->rmh, mac);
625 if (ret == RMH_SUCCESS) {
627 RMH_PrintMsg(
"Success passing to %s\n",
RMH_MacToString(mac, macStr,
sizeof(macStr)/
sizeof(macStr[0])));
634 RMH_Result RMHApp__IN_MAC_OUT_UINT32(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const RMH_MacAddress_t flowId, uint32_t* response)) {
635 RMH_MacAddress_t mac;
638 RMH_Result ret=RMHApp_ReadMAC(app, &mac);
639 if (ret == RMH_SUCCESS) {
640 ret = api(app->rmh, mac, &response);
641 if (ret == RMH_SUCCESS) {
642 RMH_PrintMsg(
"%u\n", response);
649 RMH_Result RMHApp__IN_MAC_OUT_MAC(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const RMH_MacAddress_t flowId, RMH_MacAddress_t* response)) {
650 RMH_MacAddress_t mac;
651 RMH_MacAddress_t response;
653 RMH_Result ret=RMHApp_ReadMAC(app, &mac);
654 if (ret == RMH_SUCCESS) {
655 ret = api(app->rmh, mac, &response);
656 if (ret == RMH_SUCCESS) {
658 RMH_PrintMsg(
"%s\n",
RMH_MacToString(response, mac,
sizeof(mac)/
sizeof(mac[0])));
665 RMH_Result RMHApp__IN_UINT32_OUT_MAC(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId, RMH_MacAddress_t* response)) {
666 RMH_MacAddress_t response;
668 RMH_Result ret=RMHApp_ReadUint32(app, &nodeId);
669 if (ret == RMH_SUCCESS) {
670 ret = api(app->rmh, nodeId, &response);
671 if (ret == RMH_SUCCESS) {
673 RMH_PrintMsg(
"%s\n",
RMH_MacToString(response, macStr,
sizeof(macStr)/
sizeof(macStr[0])));
680 RMH_Result RMHApp__OUT_POWER_MODE(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_PowerMode* response)) {
681 RMH_PowerMode response=0;
682 RMH_Result ret = api(app->rmh, &response);
683 if (ret == RMH_SUCCESS) {
691 RMH_Result RMHApp__IN_POWER_MODE(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const RMH_PowerMode response)) {
693 RMH_Result ret=RMHApp_ReadPowerMode(app, &mode);
694 if (ret == RMH_SUCCESS) {
695 RMH_Result ret = api(app->rmh, mode);
696 if (ret == RMH_SUCCESS) {
698 RMH_PrintMsg(
"Success setting power mode to %s\n",
RMH_PowerModeToString(mode, outStr,
sizeof(outStr)));
708 RMH_Result RMHApp__OUT_BAND(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_Band* response)) {
710 RMH_Result ret = api(app->rmh, &response);
711 if (ret == RMH_SUCCESS) {
718 RMH_Result RMHApp__OUT_LINK_STATUS(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_LinkStatus* response)) {
719 RMH_LinkStatus response=0;
720 RMH_Result ret = api(app->rmh, &response);
721 if (ret == RMH_SUCCESS) {
728 RMH_Result RMHApp__OUT_MOCA_VERSION(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_MoCAVersion* response)) {
729 RMH_MoCAVersion response=0;
730 RMH_Result ret = api(app->rmh, &response);
731 if (ret == RMH_SUCCESS) {
738 RMH_Result RMHApp__IN_UINT32_OUT_MOCA_VERSION(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId, RMH_MoCAVersion* response)) {
739 RMH_MoCAVersion response=0;
741 RMH_Result ret=RMHApp_ReadUint32(app, &nodeId);
742 if (ret == RMH_SUCCESS) {
743 ret = api(app->rmh, nodeId, &response);
744 if (ret == RMH_SUCCESS) {
752 RMH_Result RMHApp__OUT_LOGLEVEL(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_LogLevel* response)) {
753 RMH_LogLevel response=0;
754 RMH_Result ret = api(app->rmh, &response);
755 if (ret == RMH_SUCCESS) {
766 RMH_Result ret = api(app->rmh, &response);
767 if (ret == RMH_SUCCESS) {
769 for (i = 0; i < RMH_MAX_MOCA_NODES; i++) {
770 if (response.nodePresent[i]) {
771 RMH_PrintMsg(
"NodeId:%u -- %u\n", i, response.nodeValue[i]);
783 RMH_Result ret = api(app->rmh, &response);
784 if (ret == RMH_SUCCESS) {
785 char phyStrBegin[256];
786 char *phyStrEnd=phyStrBegin+
sizeof(phyStrBegin);
787 char *phyStr=phyStrBegin;
789 phyStr+=snprintf(phyStr, phyStrEnd-phyStr,
" ");
790 for (i = 0; i < RMH_MAX_MOCA_NODES; i++) {
791 if (response.nodePresent[i]) {
792 phyStr+=snprintf(phyStr, phyStrEnd-phyStr,
" %02u ", i);
795 RMH_PrintMsg(
"%s\n", phyStrBegin);
797 for (i = 0; i < RMH_MAX_MOCA_NODES; i++) {
798 if (response.nodePresent[i]) {
799 char *phyStr=phyStrBegin;
801 phyStr+=snprintf(phyStr, phyStrEnd-phyStr,
"%02u: ", i);
802 for (j = 0; j < RMH_MAX_MOCA_NODES; j++) {
804 phyStr+=snprintf(phyStr, phyStrEnd-phyStr,
" -- ");
805 }
else if (response.nodePresent[j]) {
806 phyStr+=snprintf(phyStr, phyStrEnd-phyStr,
"%04u ", nl->nodeValue[j]);
809 RMH_PrintMsg(
"%s\n", phyStrBegin);
821 RMH_Result RMHApp__IN_BOOL (
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const bool value)) {
823 RMH_Result ret=RMHApp_ReadBool(app, &value);
824 if (ret == RMH_SUCCESS) {
825 ret = api(app->rmh, value);
826 if (ret == RMH_SUCCESS) {
827 RMH_PrintMsg(
"Success passing %s\n", value ?
"TRUE" :
"FALSE");
834 RMH_Result RMHApp__IN_UINT32(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t value)) {
836 RMH_Result ret=RMHApp_ReadUint32(app, &value);
837 if (ret == RMH_SUCCESS) {
838 ret = api(app->rmh, value);
839 if (ret == RMH_SUCCESS) {
840 RMH_PrintMsg(
"Success passing %u\n", value);
847 RMH_Result RMHApp__IN_INT32(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const int32_t value)) {
849 RMH_Result ret=RMHApp_ReadInt32(app, &value);
850 if (ret == RMH_SUCCESS) {
851 ret = api(app->rmh, value);
852 if (ret == RMH_SUCCESS) {
853 RMH_PrintMsg(
"Success passing %d\n", value);
860 RMH_Result RMHApp__IN_UINT32_HEX(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t value)) {
862 RMH_Result ret=RMHApp_ReadUint32Hex(app, &value);
863 if (ret == RMH_SUCCESS) {
864 ret = api(app->rmh, value);
865 if (ret == RMH_SUCCESS) {
866 RMH_PrintMsg(
"Success passing 0x%08x\n", value);
873 RMH_Result RMHApp__IN_STRING(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const char* value)) {
875 RMH_Result ret=RMHApp_ReadString(app, input,
sizeof(input));
876 if (ret == RMH_SUCCESS) {
877 ret = api(app->rmh, input);
878 if (ret == RMH_SUCCESS) {
879 RMH_PrintMsg(
"Success passing %s\n", input);
886 RMH_Result RMHApp__IN_LOGLEVEL(
RMHApp *app, RMH_Result (*api)(
RMH_Handle rmh,
const RMH_LogLevel response)) {
890 for (i=0; (app->argRunCommand==NULL) && i !=
sizeof(RMH_LogLevelStr)/
sizeof(RMH_LogLevelStr[0]); i++ ) {
891 RMH_PrintMsg(
"%d. %s\n", i, RMH_LogLevelStr[i]);
893 RMH_Result ret=RMHApp_ReadLogLevel(app, &value);
894 if (ret == RMH_SUCCESS) {
895 ret = api(app->rmh, value);
896 if (ret == RMH_SUCCESS) {
897 RMH_PrintMsg(
"Success passing %u\n", value);
904 RMH_Result RMHApp__PRINT_STATUS(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const char*filename)) {
905 RMH_Result ret = api(app->rmh, NULL);
906 if (ret == RMH_SUCCESS) {
907 RMH_PrintMsg(
"Success\n");
913 RMH_Result RMHApp__HANDLE_ONLY(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle)) {
914 RMH_Result ret = api(app->rmh);
915 if (ret == RMH_SUCCESS) {
916 RMH_PrintMsg(
"Success\n");
922 RMH_Result RMHApp__LOCAL_HANDLE_ONLY(
const RMHApp *app, RMH_Result (*api)(
const RMHApp* app)) {
927 RMH_Result RMHApp__GET_TABOO(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, uint32_t* start, uint32_t* mask)) {
930 RMH_Result ret = api(app->rmh, &start, &mask);
931 if (ret == RMH_SUCCESS) {
932 RMH_PrintMsg(
"Start channel: %u\n", start);
933 RMH_PrintMsg(
"Channel Mask: 0x%08x\n", mask);
939 RMH_Result RMHApp__SET_TABOO(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t start,
const uint32_t mask)) {
943 RMH_Result ret=RMHApp_ReadUint32(app, &start);
944 if (ret == RMH_SUCCESS) {
945 RMH_Result ret=RMHApp_ReadUint32Hex(app, &mask);
946 if (ret == RMH_SUCCESS) {
947 ret = api(app->rmh, start, mask);
948 if (ret == RMH_SUCCESS) {
949 RMH_PrintMsg(
"Success setting Start:%u Channel Mask:0x%08x\n", start, mask);
958 RMH_Result RMHApp__OUT_ACA_TYPE(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_ACAType* response)) {
959 RMH_ACAType response=0;
960 RMH_Result ret = api(app->rmh, &response);
961 if (ret == RMH_SUCCESS) {
968 RMH_Result RMHApp__OUT_ACA_STATUS(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_ACAStatus* response)) {
969 RMH_ACAStatus response;
970 RMH_Result ret = api(app->rmh, &response);
971 if (ret == RMH_SUCCESS) {
978 RMH_Result RMHApp__REQUEST_ACA(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t channelNum,
const uint32_t sourceNodeId,
const uint32_t destinationNodeMask,
const RMH_ACAType type)) {
980 uint32_t sourceNodeId;
981 uint32_t destinationNodeMask;
985 ret=RMHApp_ReadUint32(app, &channelNum);
986 if (ret != RMH_SUCCESS) {
987 RMH_PrintErr(
"Failed reading channel number\n");
991 ret=RMHApp_ReadUint32(app, &sourceNodeId);
992 if (ret != RMH_SUCCESS) {
993 RMH_PrintErr(
"Failed reading source node id\n");
997 ret=RMHApp_ReadUint32Hex(app, &destinationNodeMask);
998 if (ret != RMH_SUCCESS) {
999 RMH_PrintErr(
"Failed reading destination node mask\n");
1003 ret=RMHApp_ReadACAType(app, &type);
1004 if (ret != RMH_SUCCESS) {
1005 RMH_PrintErr(
"Failed reading ACA type\n");
1009 ret = api(app->rmh, channelNum, sourceNodeId, destinationNodeMask, type);
1010 if (ret != RMH_SUCCESS) {
1011 RMH_PrintErr(
"Failed in ACA request\n");
1015 RMH_ACAStatus status;
1017 if (ret == RMH_SUCCESS) {
1023 if (ret == RMH_SUCCESS) {
1024 RMH_PrintMsg(
"RMH_ACA_GetTotalRxPower: %d\n", txPower);
1027 RMH_PrintMsg(
"RMH_ACA_GetPowerProfile:\n");
1033 RMH_Result RMHApp__MoCA_RESET(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeMask,
const uint32_t sleepTime)) {
1038 ret=RMHApp_ReadUint32Hex(app, &nodeMask);
1039 if (ret != RMH_SUCCESS) {
1040 RMH_PrintErr(
"Failed reading node mask\n");
1044 ret=RMHApp_ReadUint32(app, &sleepTime);
1045 if (ret != RMH_SUCCESS) {
1046 RMH_PrintErr(
"Failed reading sleep time\n");
1050 ret = api(app->rmh, nodeMask, sleepTime);
1051 if (ret != RMH_SUCCESS) {
1052 RMH_PrintErr(
"Failed in reset request\n");
1060 RMH_Result RMHApp__OUT_RESET_REASON(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle, RMH_MoCAResetReason* response)) {
1061 RMH_MoCAResetReason response;
1062 RMH_Result ret = api(app->rmh, &response);
1063 if (ret == RMH_SUCCESS) {
1070 void PrintModulation(
RMHApp *app, uint32_t start, uint32_t end, RMH_SubcarrierProfile* array,
size_t arraySize) {
1072 int offset = start < end ? 1 : -1;
1073 for (i=start; i < arraySize;) {
1074 RMH_PrintMsg(
"[%3u-%3u] ", i, i+(31*offset));
1075 for (j=0; j<32 && i < arraySize; j++,i+=offset) {
1076 RMH_PrintMsg(
"%X", array[i]);
1087 RMH_Result RMHApp__OUT_MODULATION(
RMHApp *app, RMH_Result (*api)(
const RMH_Handle handle,
const uint32_t nodeId,
const RMH_PERMode perMode, RMH_SubcarrierProfile* responseArray,
const size_t responseArraySize,
size_t* responseArrayUsed)) {
1089 RMH_SubcarrierProfile responseBuf[512];
1090 size_t responseBufUsed;
1092 RMH_MoCAVersion response;
1093 RMH_PERMode perMode;
1095 ret=RMHApp_ReadUint32(app, &nodeId);
1096 if (ret != RMH_SUCCESS) {
1097 RMH_PrintErr(
"Failed reading node Id\n");
1101 ret=RMHApp_ReadPERMode(app, &perMode);
1102 if (ret != RMH_SUCCESS) {
1103 RMH_PrintErr(
"Failed reading channel type\n");
1107 ret = api(app->rmh, nodeId, perMode, responseBuf,
sizeof(responseBuf)/
sizeof(responseBuf[0]), &responseBufUsed);
1108 if (ret != RMH_SUCCESS) {
1113 if (ret != RMH_SUCCESS) {
1117 case RMH_MOCA_VERSION_10:
1118 case RMH_MOCA_VERSION_11:
1119 PrintModulation(app, 127, 0, responseBuf, responseBufUsed);
1120 PrintModulation(app, 255, 128, responseBuf, responseBufUsed);
1122 case RMH_MOCA_VERSION_20:
1123 PrintModulation(app, 256, 511, responseBuf, responseBufUsed);
1124 PrintModulation(app, 0, 255, responseBuf, responseBufUsed);
1127 RMH_PrintErr(
"Unknown MoCA version.\n");
1139 #define SET_LOCAL_API_HANDLER(HANDLER_FUNCTION, API_FUNCTION, ALIAS_STRING, DESCRIPTION_STR) \
1140 static RMH_API pRMH_API_##API_FUNCTION = { #API_FUNCTION, false, false, NULL, NULL, DESCRIPTION_STR, NULL, 0, NULL }; \
1141 if (app->local.apiListSize < RMH_MAX_NUM_APIS) app->local.apiList[app->local.apiListSize++]=&pRMH_API_##API_FUNCTION; \
1142 SET_API_HANDLER(HANDLER_FUNCTION, API_FUNCTION, ALIAS_STRING);
1144 #define SET_API_HANDLER(HANDLER_FUNCTION, API_FUNCTION, ALIAS_STRING) { \
1145 while(0) HANDLER_FUNCTION(NULL, API_FUNCTION); \
1146 RMHApp_AddAPI(app, #API_FUNCTION, API_FUNCTION, HANDLER_FUNCTION, ALIAS_STRING); \
1150 void RMHApp_AddAPI(
RMHApp* app,
const char* apiName,
const void *apiFunc,
const void *apiHandlerFunc,
const char* apiAlias) {
1151 memset(&app->handledAPIs.apiList[app->handledAPIs.apiListSize], 0,
sizeof(app->handledAPIs.apiList[app->handledAPIs.apiListSize]));
1152 app->handledAPIs.apiList[app->handledAPIs.apiListSize].apiName = apiName;
1153 app->handledAPIs.apiList[app->handledAPIs.apiListSize].apiAlias = (apiAlias && apiAlias[0] !=
'\0' ) ? apiAlias : NULL;
1154 app->handledAPIs.apiList[app->handledAPIs.apiListSize].apiFunc = apiFunc;
1155 app->handledAPIs.apiList[app->handledAPIs.apiListSize].apiHandlerFunc = apiHandlerFunc;
1156 app->handledAPIs.apiListSize++;
1159 void RMHApp_RegisterAPIHandlers(
RMHApp *app) {
1188 SET_API_HANDLER(RMHApp__HANDLE_ONLY, RMH_Self_RestoreRDKDefaultSettings,
"");
1195 SET_API_HANDLER(RMHApp__OUT_UINT32, RMH_Self_GetPrimaryChannelTargetPhyRate,
"");
1196 SET_API_HANDLER(RMHApp__IN_UINT32, RMH_Self_SetPrimaryChannelTargetPhyRate,
"");
1197 SET_API_HANDLER(RMHApp__OUT_UINT32, RMH_Self_GetSecondaryChannelTargetPhyRate,
"");
1198 SET_API_HANDLER(RMHApp__IN_UINT32, RMH_Self_SetSecondaryChannelTargetPhyRate,
"");
1224 SET_API_HANDLER(RMHApp__OUT_POWER_MODE, RMH_Power_GetStandbyMode,
"");
1225 SET_API_HANDLER(RMHApp__IN_POWER_MODE, RMH_Power_SetStandbyMode,
"");
1322 SET_API_HANDLER(RMHApp__OUT_UINT32_NODEMESH, RMH_Network_GetBondedConnections,
"");
1355 SET_API_HANDLER(RMHApp__IN_UINT32_OUT_UINT32, RMH_RemoteNode_GetMaxConstellation_GCD100,
"");
1356 SET_API_HANDLER(RMHApp__IN_UINT32_IN_UINT32, RMH_RemoteNode_SetMaxConstellation_GCD100,
"");
1357 SET_API_HANDLER(RMHApp__IN_UINT32_OUT_UINT32, RMH_RemoteNode_GetMaxConstellation_GCD50,
"");
1358 SET_API_HANDLER(RMHApp__IN_UINT32_IN_UINT32, RMH_RemoteNode_SetMaxConstellation_GCD50,
"");
1359 SET_API_HANDLER(RMHApp__IN_UINT32_OUT_UINT32, RMH_RemoteNode_GetMaxConstellation_P2P100,
"");
1360 SET_API_HANDLER(RMHApp__IN_UINT32_IN_UINT32, RMH_RemoteNode_SetMaxConstellation_P2P100,
"");
1361 SET_API_HANDLER(RMHApp__IN_UINT32_OUT_UINT32, RMH_RemoteNode_GetMaxConstellation_P2P50,
"");
1362 SET_API_HANDLER(RMHApp__IN_UINT32_IN_UINT32, RMH_RemoteNode_SetMaxConstellation_P2P50,
"");
1391 SET_LOCAL_API_HANDLER(RMHApp__LOCAL_HANDLE_ONLY, RMHApp_DriverLogForever,
"log_forever,logforever",
"Enabled debug logging to a dedicated file that does not rotate. This will collect the best logs however if left enabled for long periods of time you can run out of space.");
1392 SET_LOCAL_API_HANDLER(RMHApp__LOCAL_HANDLE_ONLY, RMHApp_EnableDriverDebugLogging,
"log",
"Enable debug logging to the default MoCA log location. This is safe to leave enabled for long periods of time as this default log should be rotated");
1393 SET_LOCAL_API_HANDLER(RMHApp__LOCAL_HANDLE_ONLY, RMHApp_DisableDriverDebugLogging,
"log_stop,logstop",
"Disable MoCA debug logging");
1394 SET_LOCAL_API_HANDLER(RMHApp__LOCAL_HANDLE_ONLY, RMHApp_Start,
"start",
"Shortcut to Enable MoCA");
1395 SET_LOCAL_API_HANDLER(RMHApp__LOCAL_HANDLE_ONLY, RMHApp_Stop,
"stop",
"Shortcut to disable MoCA");