diff mbox series

[BlueZ,6/6] tools/mesh-gatt: Add generic power onoff client model

Message ID 20211207225604.35156-7-daniele.biagetti@cblelectronics.com (mailing list archive)
State Changes Requested
Headers show
Series tools/mesh-gatt meshctl tool improvements | expand

Checks

Context Check Description
tedd_an/checkpatch fail [BlueZ,6/6] tools/mesh-gatt: Add generic power onoff client model ERROR:CODE_INDENT: code indent should use tabs where possible #181: FILE: tools/mesh-gatt/onpowerup-model.c:45: + if (power_onoff_app_idx != APP_IDX_INVALID) {$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #181: FILE: tools/mesh-gatt/onpowerup-model.c:45: + if (power_onoff_app_idx != APP_IDX_INVALID) {$ WARNING:UNNECESSARY_ELSE: else is not generally useful after a break or return #183: FILE: tools/mesh-gatt/onpowerup-model.c:47: + return MESH_STATUS_INSUFF_RESOURCES; + } else { ERROR:CODE_INDENT: code indent should use tabs where possible #184: FILE: tools/mesh-gatt/onpowerup-model.c:48: + power_onoff_app_idx = app_idx;$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #184: FILE: tools/mesh-gatt/onpowerup-model.c:48: + power_onoff_app_idx = app_idx;$ ERROR:CODE_INDENT: code indent should use tabs where possible #185: FILE: tools/mesh-gatt/onpowerup-model.c:49: + bt_shell_printf("OnPowerUp client model: new binding"$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #185: FILE: tools/mesh-gatt/onpowerup-model.c:49: + bt_shell_printf("OnPowerUp client model: new binding"$ ERROR:CODE_INDENT: code indent should use tabs where possible #189: FILE: tools/mesh-gatt/onpowerup-model.c:53: + if (power_onoff_app_idx == app_idx)$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #189: FILE: tools/mesh-gatt/onpowerup-model.c:53: + if (power_onoff_app_idx == app_idx)$ ERROR:CODE_INDENT: code indent should use tabs where possible #190: FILE: tools/mesh-gatt/onpowerup-model.c:54: + power_onoff_app_idx = APP_IDX_INVALID;$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #190: FILE: tools/mesh-gatt/onpowerup-model.c:54: + power_onoff_app_idx = APP_IDX_INVALID;$ ERROR:CODE_INDENT: code indent should use tabs where possible #200: FILE: tools/mesh-gatt/onpowerup-model.c:64: + char s[10];$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #200: FILE: tools/mesh-gatt/onpowerup-model.c:64: + char s[10];$ ERROR:CODE_INDENT: code indent should use tabs where possible #212: FILE: tools/mesh-gatt/onpowerup-model.c:76: + case OP_GENERIC_POWER_ONOFF_STATUS:$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #212: FILE: tools/mesh-gatt/onpowerup-model.c:76: + case OP_GENERIC_POWER_ONOFF_STATUS:$ WARNING:LONG_LINE_STRING: line length of 84 exceeds 80 columns #213: FILE: tools/mesh-gatt/onpowerup-model.c:77: + bt_shell_printf("OnPowerUp Model Message received (%d) opcode %x\n", ERROR:CODE_INDENT: code indent should use tabs where possible #213: FILE: tools/mesh-gatt/onpowerup-model.c:77: + bt_shell_printf("OnPowerUp Model Message received (%d) opcode %x\n",$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #213: FILE: tools/mesh-gatt/onpowerup-model.c:77: + bt_shell_printf("OnPowerUp Model Message received (%d) opcode %x\n",$ WARNING:LONG_LINE: line length of 85 exceeds 80 columns #214: FILE: tools/mesh-gatt/onpowerup-model.c:78: + len, opcode); ERROR:CODE_INDENT: code indent should use tabs where possible #214: FILE: tools/mesh-gatt/onpowerup-model.c:78: + len, opcode);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #214: FILE: tools/mesh-gatt/onpowerup-model.c:78: + len, opcode);$ ERROR:CODE_INDENT: code indent should use tabs where possible #215: FILE: tools/mesh-gatt/onpowerup-model.c:79: + print_byte_array("\t",data, len);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #215: FILE: tools/mesh-gatt/onpowerup-model.c:79: + print_byte_array("\t",data, len);$ ERROR:SPACING: space required after that ',' (ctx:VxV) #215: FILE: tools/mesh-gatt/onpowerup-model.c:79: + print_byte_array("\t",data, len); ^ ERROR:CODE_INDENT: code indent should use tabs where possible #216: FILE: tools/mesh-gatt/onpowerup-model.c:80: + if (len != 1)$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #216: FILE: tools/mesh-gatt/onpowerup-model.c:80: + if (len != 1)$ ERROR:CODE_INDENT: code indent should use tabs where possible #217: FILE: tools/mesh-gatt/onpowerup-model.c:81: + break;$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #217: FILE: tools/mesh-gatt/onpowerup-model.c:81: + break;$ ERROR:CODE_INDENT: code indent should use tabs where possible #218: FILE: tools/mesh-gatt/onpowerup-model.c:82: + if(data[0] == 0){$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #218: FILE: tools/mesh-gatt/onpowerup-model.c:82: + if(data[0] == 0){$ WARNING:SUSPECT_CODE_INDENT: suspect code indent for conditional statements (16, 20) #218: FILE: tools/mesh-gatt/onpowerup-model.c:82: + if(data[0] == 0){ + sprintf(s, "%s", "OFF"); ERROR:SPACING: space required before the open brace '{' #218: FILE: tools/mesh-gatt/onpowerup-model.c:82: + if(data[0] == 0){ ERROR:SPACING: space required before the open parenthesis '(' #218: FILE: tools/mesh-gatt/onpowerup-model.c:82: + if(data[0] == 0){ WARNING:BRACES: braces {} are not necessary for any arm of this statement #218: FILE: tools/mesh-gatt/onpowerup-model.c:82: + if(data[0] == 0){ [...] + }else if(data[0] == 1){ [...] + }else if(data[0] == 2){ [...] + }else{ [...] ERROR:CODE_INDENT: code indent should use tabs where possible #219: FILE: tools/mesh-gatt/onpowerup-model.c:83: + sprintf(s, "%s", "OFF");$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #219: FILE: tools/mesh-gatt/onpowerup-model.c:83: + sprintf(s, "%s", "OFF");$ ERROR:CODE_INDENT: code indent should use tabs where possible #220: FILE: tools/mesh-gatt/onpowerup-model.c:84: + }else if(data[0] == 1){$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #220: FILE: tools/mesh-gatt/onpowerup-model.c:84: + }else if(data[0] == 1){$ WARNING:SUSPECT_CODE_INDENT: suspect code indent for conditional statements (16, 20) #220: FILE: tools/mesh-gatt/onpowerup-model.c:84: + }else if(data[0] == 1){ + sprintf(s, "%s", "ON"); ERROR:SPACING: space required before the open brace '{' #220: FILE: tools/mesh-gatt/onpowerup-model.c:84: + }else if(data[0] == 1){ ERROR:SPACING: space required after that close brace '}' #220: FILE: tools/mesh-gatt/onpowerup-model.c:84: + }else if(data[0] == 1){ ERROR:SPACING: space required before the open parenthesis '(' #220: FILE: tools/mesh-gatt/onpowerup-model.c:84: + }else if(data[0] == 1){ ERROR:CODE_INDENT: code indent should use tabs where possible #221: FILE: tools/mesh-gatt/onpowerup-model.c:85: + sprintf(s, "%s", "ON");$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #221: FILE: tools/mesh-gatt/onpowerup-model.c:85: + sprintf(s, "%s", "ON");$ ERROR:CODE_INDENT: code indent should use tabs where possible #222: FILE: tools/mesh-gatt/onpowerup-model.c:86: + }else if(data[0] == 2){$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #222: FILE: tools/mesh-gatt/onpowerup-model.c:86: + }else if(data[0] == 2){$ WARNING:SUSPECT_CODE_INDENT: suspect code indent for conditional statements (16, 20) #222: FILE: tools/mesh-gatt/onpowerup-model.c:86: + }else if(data[0] == 2){ + sprintf(s, "%s", "RESUME"); ERROR:SPACING: space required before the open brace '{' #222: FILE: tools/mesh-gatt/onpowerup-model.c:86: + }else if(data[0] == 2){ ERROR:SPACING: space required after that close brace '}' #222: FILE: tools/mesh-gatt/onpowerup-model.c:86: + }else if(data[0] == 2){ ERROR:SPACING: space required before the open parenthesis '(' #222: FILE: tools/mesh-gatt/onpowerup-model.c:86: + }else if(data[0] == 2){ ERROR:CODE_INDENT: code indent should use tabs where possible #223: FILE: tools/mesh-gatt/onpowerup-model.c:87: + sprintf(s, "%s", "RESUME");$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #223: FILE: tools/mesh-gatt/onpowerup-model.c:87: + sprintf(s, "%s", "RESUME");$ ERROR:CODE_INDENT: code indent should use tabs where possible #224: FILE: tools/mesh-gatt/onpowerup-model.c:88: + }else{$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #224: FILE: tools/mesh-gatt/onpowerup-model.c:88: + }else{$ WARNING:SUSPECT_CODE_INDENT: suspect code indent for conditional statements (16, 20) #224: FILE: tools/mesh-gatt/onpowerup-model.c:88: + }else{ + sprintf(s, "%s", "?UNKNOWN"); ERROR:SPACING: space required before the open brace '{' #224: FILE: tools/mesh-gatt/onpowerup-model.c:88: + }else{ ERROR:SPACING: space required after that close brace '}' #224: FILE: tools/mesh-gatt/onpowerup-model.c:88: + }else{ ERROR:CODE_INDENT: code indent should use tabs where possible #225: FILE: tools/mesh-gatt/onpowerup-model.c:89: + sprintf(s, "%s", "?UNKNOWN");$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #225: FILE: tools/mesh-gatt/onpowerup-model.c:89: + sprintf(s, "%s", "?UNKNOWN");$ ERROR:CODE_INDENT: code indent should use tabs where possible #226: FILE: tools/mesh-gatt/onpowerup-model.c:90: + }$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #226: FILE: tools/mesh-gatt/onpowerup-model.c:90: + }$ WARNING:LONG_LINE: line length of 87 exceeds 80 columns #227: FILE: tools/mesh-gatt/onpowerup-model.c:91: + bt_shell_printf("Node %4.4x: OnPowerUp Status present = %s\n", src, s); ERROR:CODE_INDENT: code indent should use tabs where possible #227: FILE: tools/mesh-gatt/onpowerup-model.c:91: + bt_shell_printf("Node %4.4x: OnPowerUp Status present = %s\n", src, s);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #227: FILE: tools/mesh-gatt/onpowerup-model.c:91: + bt_shell_printf("Node %4.4x: OnPowerUp Status present = %s\n", src, s);$ ERROR:CODE_INDENT: code indent should use tabs where possible #228: FILE: tools/mesh-gatt/onpowerup-model.c:92: + break;$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #228: FILE: tools/mesh-gatt/onpowerup-model.c:92: + break;$ WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #252: FILE: tools/mesh-gatt/onpowerup-model.c:116: + for (i = 0; i < sizeof(parms)/sizeof(parms[0]) && i < (unsigned) argc; WARNING:ARRAY_SIZE: Prefer ARRAY_SIZE(parms) #252: FILE: tools/mesh-gatt/onpowerup-model.c:116: + for (i = 0; i < sizeof(parms)/sizeof(parms[0]) && i < (unsigned) argc; WARNING:NAKED_SSCANF: unchecked sscanf return value #254: FILE: tools/mesh-gatt/onpowerup-model.c:118: + sscanf(argv[i], "%x", &parms[i]); WARNING:UNNECESSARY_ELSE: else is not generally useful after a break or return #273: FILE: tools/mesh-gatt/onpowerup-model.c:137: + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } else { ERROR:CODE_INDENT: code indent should use tabs where possible #274: FILE: tools/mesh-gatt/onpowerup-model.c:138: + bt_shell_printf("Controlling OnPowerUp for node %4.4x\n", dst);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #274: FILE: tools/mesh-gatt/onpowerup-model.c:138: + bt_shell_printf("Controlling OnPowerUp for node %4.4x\n", dst);$ ERROR:CODE_INDENT: code indent should use tabs where possible #276: FILE: tools/mesh-gatt/onpowerup-model.c:140: + set_menu_prompt("OnPowerUp", argv[1]);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #276: FILE: tools/mesh-gatt/onpowerup-model.c:140: + set_menu_prompt("OnPowerUp", argv[1]);$ ERROR:SPACING: space required before the open parenthesis '(' #286: FILE: tools/mesh-gatt/onpowerup-model.c:150: + if(!node) ERROR:CODE_INDENT: code indent should use tabs where possible #292: FILE: tools/mesh-gatt/onpowerup-model.c:156: + target, power_onoff_app_idx, buf, len);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #292: FILE: tools/mesh-gatt/onpowerup-model.c:156: + target, power_onoff_app_idx, buf, len);$ ERROR:CODE_INDENT: code indent should use tabs where possible #308: FILE: tools/mesh-gatt/onpowerup-model.c:172: + if (!node){$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #308: FILE: tools/mesh-gatt/onpowerup-model.c:172: + if (!node){$ ERROR:SPACING: space required before the open brace '{' #308: FILE: tools/mesh-gatt/onpowerup-model.c:172: + if (!node){ WARNING:BRACES: braces {} are not necessary for single statement blocks #308: FILE: tools/mesh-gatt/onpowerup-model.c:172: + if (!node){ + bt_shell_printf("Warning: node %4.4x not found in database\n",target); + } WARNING:LONG_LINE: line length of 86 exceeds 80 columns #309: FILE: tools/mesh-gatt/onpowerup-model.c:173: + bt_shell_printf("Warning: node %4.4x not found in database\n",target); ERROR:CODE_INDENT: code indent should use tabs where possible #309: FILE: tools/mesh-gatt/onpowerup-model.c:173: + bt_shell_printf("Warning: node %4.4x not found in database\n",target);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #309: FILE: tools/mesh-gatt/onpowerup-model.c:173: + bt_shell_printf("Warning: node %4.4x not found in database\n",target);$ ERROR:SPACING: space required after that ',' (ctx:VxV) #309: FILE: tools/mesh-gatt/onpowerup-model.c:173: + bt_shell_printf("Warning: node %4.4x not found in database\n",target); ^ ERROR:CODE_INDENT: code indent should use tabs where possible #310: FILE: tools/mesh-gatt/onpowerup-model.c:174: + }$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #310: FILE: tools/mesh-gatt/onpowerup-model.c:174: + }$ ERROR:CODE_INDENT: code indent should use tabs where possible #312: FILE: tools/mesh-gatt/onpowerup-model.c:176: + n = mesh_opcode_set(OP_GENERIC_POWER_ONOFF_GET, msg);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #312: FILE: tools/mesh-gatt/onpowerup-model.c:176: + n = mesh_opcode_set(OP_GENERIC_POWER_ONOFF_GET, msg);$ ERROR:CODE_INDENT: code indent should use tabs where possible #315: FILE: tools/mesh-gatt/onpowerup-model.c:179: + bt_shell_printf("Failed to send \"GENERIC POWER ONOFF GET\"\n");$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #315: FILE: tools/mesh-gatt/onpowerup-model.c:179: + bt_shell_printf("Failed to send \"GENERIC POWER ONOFF GET\"\n");$ ERROR:CODE_INDENT: code indent should use tabs where possible #335: FILE: tools/mesh-gatt/onpowerup-model.c:199: + if (!node){$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #335: FILE: tools/mesh-gatt/onpowerup-model.c:199: + if (!node){$ ERROR:SPACING: space required before the open brace '{' #335: FILE: tools/mesh-gatt/onpowerup-model.c:199: + if (!node){ WARNING:BRACES: braces {} are not necessary for single statement blocks #335: FILE: tools/mesh-gatt/onpowerup-model.c:199: + if (!node){ + bt_shell_printf("Warning: node %4.4x not found in database\n",target); + } WARNING:LONG_LINE: line length of 86 exceeds 80 columns #336: FILE: tools/mesh-gatt/onpowerup-model.c:200: + bt_shell_printf("Warning: node %4.4x not found in database\n",target); ERROR:CODE_INDENT: code indent should use tabs where possible #336: FILE: tools/mesh-gatt/onpowerup-model.c:200: + bt_shell_printf("Warning: node %4.4x not found in database\n",target);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #336: FILE: tools/mesh-gatt/onpowerup-model.c:200: + bt_shell_printf("Warning: node %4.4x not found in database\n",target);$ ERROR:SPACING: space required after that ',' (ctx:VxV) #336: FILE: tools/mesh-gatt/onpowerup-model.c:200: + bt_shell_printf("Warning: node %4.4x not found in database\n",target); ^ ERROR:CODE_INDENT: code indent should use tabs where possible #337: FILE: tools/mesh-gatt/onpowerup-model.c:201: + }$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #337: FILE: tools/mesh-gatt/onpowerup-model.c:201: + }$ WARNING:LONG_LINE: line length of 90 exceeds 80 columns #340: FILE: tools/mesh-gatt/onpowerup-model.c:204: + parms[0] != 0 && parms[0] != 1 && parms[0] != 2) { ERROR:CODE_INDENT: code indent should use tabs where possible #340: FILE: tools/mesh-gatt/onpowerup-model.c:204: + parms[0] != 0 && parms[0] != 1 && parms[0] != 2) {$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #340: FILE: tools/mesh-gatt/onpowerup-model.c:204: + parms[0] != 0 && parms[0] != 1 && parms[0] != 2) {$ WARNING:LONG_LINE_STRING: line length of 86 exceeds 80 columns #341: FILE: tools/mesh-gatt/onpowerup-model.c:205: + bt_shell_printf("Bad arguments: Expecting \"0\" or \"1\" or \"2\"\n"); ERROR:CODE_INDENT: code indent should use tabs where possible #341: FILE: tools/mesh-gatt/onpowerup-model.c:205: + bt_shell_printf("Bad arguments: Expecting \"0\" or \"1\" or \"2\"\n");$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #341: FILE: tools/mesh-gatt/onpowerup-model.c:205: + bt_shell_printf("Bad arguments: Expecting \"0\" or \"1\" or \"2\"\n");$ ERROR:CODE_INDENT: code indent should use tabs where possible #345: FILE: tools/mesh-gatt/onpowerup-model.c:209: + n = mesh_opcode_set(OP_GENERIC_POWER_ONOFF_SET, msg);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #345: FILE: tools/mesh-gatt/onpowerup-model.c:209: + n = mesh_opcode_set(OP_GENERIC_POWER_ONOFF_SET, msg);$ ERROR:CODE_INDENT: code indent should use tabs where possible #350: FILE: tools/mesh-gatt/onpowerup-model.c:214: + bt_shell_printf("Failed to send \"GENERIC POWER ONOFF SET\"\n");$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #350: FILE: tools/mesh-gatt/onpowerup-model.c:214: + bt_shell_printf("Failed to send \"GENERIC POWER ONOFF SET\"\n");$ ERROR:CODE_INDENT: code indent should use tabs where possible #358: FILE: tools/mesh-gatt/onpowerup-model.c:222: + .name = "power_onoff",$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #358: FILE: tools/mesh-gatt/onpowerup-model.c:222: + .name = "power_onoff",$ ERROR:CODE_INDENT: code indent should use tabs where possible #359: FILE: tools/mesh-gatt/onpowerup-model.c:223: + .desc = "Power OnOff (OnPowerUp) Model Submenu",$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #359: FILE: tools/mesh-gatt/onpowerup-model.c:223: + .desc = "Power OnOff (OnPowerUp) Model Submenu",$ ERROR:CODE_INDENT: code indent should use tabs where possible #364: FILE: tools/mesh-gatt/onpowerup-model.c:228: + "Get OnPowerUp status"},$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #364: FILE: tools/mesh-gatt/onpowerup-model.c:228: + "Get OnPowerUp status"},$ ERROR:CODE_INDENT: code indent should use tabs where possible #365: FILE: tools/mesh-gatt/onpowerup-model.c:229: + {"set", "<0/1/2>",^I^I^Icmd_set,$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #365: FILE: tools/mesh-gatt/onpowerup-model.c:229: + {"set", "<0/1/2>",^I^I^Icmd_set,$ WARNING:LONG_LINE: line length of 89 exceeds 80 columns #366: FILE: tools/mesh-gatt/onpowerup-model.c:230: + "Set OnPowerUp status (OFF/ON/RESTORE)"}, ERROR:CODE_INDENT: code indent should use tabs where possible #366: FILE: tools/mesh-gatt/onpowerup-model.c:230: + "Set OnPowerUp status (OFF/ON/RESTORE)"},$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #366: FILE: tools/mesh-gatt/onpowerup-model.c:230: + "Set OnPowerUp status (OFF/ON/RESTORE)"},$ ERROR:CODE_INDENT: code indent should use tabs where possible #379: FILE: tools/mesh-gatt/onpowerup-model.c:243: + if (!node_local_model_register(ele, GENERIC_POWER_ONOFF_CLIENT_MODEL_ID,$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #379: FILE: tools/mesh-gatt/onpowerup-model.c:243: + if (!node_local_model_register(ele, GENERIC_POWER_ONOFF_CLIENT_MODEL_ID,$ ERROR:CODE_INDENT: code indent should use tabs where possible #383: FILE: tools/mesh-gatt/onpowerup-model.c:247: + bt_shell_add_submenu(&power_onoff_menu);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #383: FILE: tools/mesh-gatt/onpowerup-model.c:247: + bt_shell_add_submenu(&power_onoff_menu);$ WARNING:LONG_LINE_STRING: line length of 86 exceeds 80 columns #431: FILE: tools/meshctl.c:2008: + g_printerr("Failed to initialize mesh generic power On/Off client\n"); /github/workspace/src/12662893.patch total: 61 errors, 66 warnings, 315 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. NOTE: Whitespace errors detected. You may wish to use scripts/cleanpatch or scripts/cleanfile /github/workspace/src/12662893.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/gitlint success Gitlint PASS

Commit Message

Daniele Biagetti Dec. 7, 2021, 10:56 p.m. UTC
---
 Makefile.tools                    |   4 +-
 tools/mesh-gatt/local_node.json   |   6 +-
 tools/mesh-gatt/onpowerup-model.c | 250 ++++++++++++++++++++++++++++++
 tools/mesh-gatt/onpowerup-model.h |  21 +++
 tools/meshctl.c                   |   4 +
 5 files changed, 283 insertions(+), 2 deletions(-)
 create mode 100644 tools/mesh-gatt/onpowerup-model.c
 create mode 100644 tools/mesh-gatt/onpowerup-model.h
diff mbox series

Patch

diff --git a/Makefile.tools b/Makefile.tools
index c0d2e27de..f9fecfe9d 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -333,7 +333,9 @@  tools_meshctl_SOURCES = tools/meshctl.c \
 				tools/mesh-gatt/onoff-model.h \
 				tools/mesh-gatt/onoff-model.c \
 				tools/mesh-gatt/level-model.h \
-				tools/mesh-gatt/level-model.c
+				tools/mesh-gatt/level-model.c \
+				tools/mesh-gatt/onpowerup-model.h \
+				tools/mesh-gatt/onpowerup-model.c
 tools_meshctl_LDADD = gdbus/libgdbus-internal.la src/libshared-glib.la \
 				lib/libbluetooth-internal.la \
 				$(GLIB_LIBS) $(DBUS_LIBS) -ljson-c -lreadline
diff --git a/tools/mesh-gatt/local_node.json b/tools/mesh-gatt/local_node.json
index 462cd815d..2c332eb1c 100644
--- a/tools/mesh-gatt/local_node.json
+++ b/tools/mesh-gatt/local_node.json
@@ -36,7 +36,7 @@ 
             {
                 "elementIndex": 0,
                 "location": "0001",
-                "models": ["0000", "0001", "1001", "1003"]
+                "models": ["0000", "0001", "1001", "1003", "1008"]
             }
         ]
     },
@@ -56,6 +56,10 @@ 
                 {
                  "modelId": "1003",
                  "bind": [1]
+                },
+                {
+                 "modelId": "1008",
+                 "bind": [1]
                 }
             ]
           }
diff --git a/tools/mesh-gatt/onpowerup-model.c b/tools/mesh-gatt/onpowerup-model.c
new file mode 100644
index 000000000..4ae7713e4
--- /dev/null
+++ b/tools/mesh-gatt/onpowerup-model.c
@@ -0,0 +1,250 @@ 
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2017  Intel Corporation. All rights reserved.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <sys/uio.h>
+#include <wordexp.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <glib.h>
+
+#include "src/shared/shell.h"
+#include "src/shared/util.h"
+
+#include "tools/mesh-gatt/mesh-net.h"
+#include "tools/mesh-gatt/keys.h"
+#include "tools/mesh-gatt/net.h"
+#include "tools/mesh-gatt/node.h"
+#include "tools/mesh-gatt/prov-db.h"
+#include "tools/mesh-gatt/util.h"
+#include "tools/mesh-gatt/onpowerup-model.h"
+
+static uint8_t trans_id;
+static uint16_t power_onoff_app_idx = APP_IDX_INVALID;
+
+static int client_bind(uint16_t app_idx, int action)
+{
+	if (action == ACTION_ADD) {
+                if (power_onoff_app_idx != APP_IDX_INVALID) {
+			return MESH_STATUS_INSUFF_RESOURCES;
+		} else {
+                        power_onoff_app_idx = app_idx;
+                        bt_shell_printf("OnPowerUp client model: new binding"
+					" %4.4x\n", app_idx);
+		}
+	} else {
+                if (power_onoff_app_idx == app_idx)
+                        power_onoff_app_idx = APP_IDX_INVALID;
+	}
+	return MESH_STATUS_SUCCESS;
+}
+
+static bool client_msg_recvd(uint16_t src, uint8_t *data,
+				uint16_t len, void *user_data)
+{
+	uint32_t opcode;
+	int n;
+        char s[10];
+
+	if (mesh_opcode_get(data, len, &opcode, &n)) {
+		len -= n;
+		data += n;
+	} else
+		return false;
+
+	switch (opcode) {
+	default:
+		return false;
+
+        case OP_GENERIC_POWER_ONOFF_STATUS:
+                bt_shell_printf("OnPowerUp Model Message received (%d) opcode %x\n",
+                                                                        len, opcode);
+                print_byte_array("\t",data, len);
+                if (len != 1)
+                        break;
+                if(data[0] == 0){
+                    sprintf(s, "%s", "OFF");
+                }else if(data[0] == 1){
+                    sprintf(s, "%s", "ON");
+                }else if(data[0] == 2){
+                    sprintf(s, "%s", "RESUME");
+                }else{
+                    sprintf(s, "%s", "?UNKNOWN");
+                }
+                bt_shell_printf("Node %4.4x: OnPowerUp Status present = %s\n", src, s);
+                break;
+	}
+	return true;
+}
+
+
+static uint32_t target;
+static uint32_t parms[8];
+
+static uint32_t read_input_parameters(int argc, char *argv[])
+{
+	uint32_t i;
+
+	if (!argc)
+		return 0;
+
+	--argc;
+	++argv;
+
+	if (!argc || argv[0][0] == '\0')
+		return 0;
+
+	memset(parms, 0xff, sizeof(parms));
+
+	for (i = 0; i < sizeof(parms)/sizeof(parms[0]) && i < (unsigned) argc;
+									i++) {
+		sscanf(argv[i], "%x", &parms[i]);
+		if (parms[i] == 0xffffffff)
+			break;
+	}
+
+	return i;
+}
+
+static void cmd_set_node(int argc, char *argv[])
+{
+	uint32_t dst;
+	char *end;
+
+	dst = strtol(argv[1], &end, 16);
+	if (end != (argv[1] + 4)) {
+		bt_shell_printf("Bad unicast address %s: "
+				"expected format 4 digit hex\n", argv[1]);
+		target = UNASSIGNED_ADDRESS;
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	} else {
+                bt_shell_printf("Controlling OnPowerUp for node %4.4x\n", dst);
+		target = dst;
+                set_menu_prompt("OnPowerUp", argv[1]);
+		return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+	}
+}
+
+static bool send_cmd(uint8_t *buf, uint16_t len)
+{
+	struct mesh_node *node = node_get_local_node();
+	uint8_t ttl;
+
+	if(!node)
+		return false;
+
+	ttl = node_get_default_ttl(node);
+
+	return net_access_layer_send(ttl, node_get_primary(node),
+                                        target, power_onoff_app_idx, buf, len);
+}
+
+static void cmd_get_status(int argc, char *argv[])
+{
+	uint16_t n;
+	uint8_t msg[32];
+	struct mesh_node *node;
+
+	if (IS_UNASSIGNED(target)) {
+		bt_shell_printf("Destination not set\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	node = node_find_by_addr(target);
+
+        if (!node){
+                bt_shell_printf("Warning: node %4.4x not found in database\n",target);
+        }
+
+        n = mesh_opcode_set(OP_GENERIC_POWER_ONOFF_GET, msg);
+
+	if (!send_cmd(msg, n)) {
+                bt_shell_printf("Failed to send \"GENERIC POWER ONOFF GET\"\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static void cmd_set(int argc, char *argv[])
+{
+	uint16_t n;
+	uint8_t msg[32];
+	struct mesh_node *node;
+
+	if (IS_UNASSIGNED(target)) {
+		bt_shell_printf("Destination not set\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	node = node_find_by_addr(target);
+
+        if (!node){
+                bt_shell_printf("Warning: node %4.4x not found in database\n",target);
+        }
+
+	if ((read_input_parameters(argc, argv) != 1) &&
+                                        parms[0] != 0 && parms[0] != 1 && parms[0] != 2) {
+                bt_shell_printf("Bad arguments: Expecting \"0\" or \"1\" or \"2\"\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+        n = mesh_opcode_set(OP_GENERIC_POWER_ONOFF_SET, msg);
+	msg[n++] = parms[0];
+	msg[n++] = trans_id++;
+
+	if (!send_cmd(msg, n)) {
+                bt_shell_printf("Failed to send \"GENERIC POWER ONOFF SET\"\n");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static const struct bt_shell_menu power_onoff_menu = {
+        .name = "power_onoff",
+        .desc = "Power OnOff (OnPowerUp) Model Submenu",
+	.entries = {
+	{"target",		"<unicast>",			cmd_set_node,
+						"Set node to configure"},
+	{"get",			NULL,				cmd_get_status,
+                                                "Get OnPowerUp status"},
+        {"set",                 "<0/1/2>",			cmd_set,
+                                                "Set OnPowerUp status (OFF/ON/RESTORE)"},
+	{} },
+};
+
+static struct mesh_model_ops client_cbs = {
+	client_msg_recvd,
+	client_bind,
+	NULL,
+	NULL
+};
+
+bool power_onoff_client_init(uint8_t ele)
+{
+        if (!node_local_model_register(ele, GENERIC_POWER_ONOFF_CLIENT_MODEL_ID,
+					&client_cbs, NULL))
+		return false;
+
+        bt_shell_add_submenu(&power_onoff_menu);
+
+	return true;
+}
diff --git a/tools/mesh-gatt/onpowerup-model.h b/tools/mesh-gatt/onpowerup-model.h
new file mode 100644
index 000000000..f8347d830
--- /dev/null
+++ b/tools/mesh-gatt/onpowerup-model.h
@@ -0,0 +1,21 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2017  Intel Corporation. All rights reserved.
+ *
+ *
+ */
+
+#define GENERIC_POWER_ONOFF_SERVER_MODEL_ID         0x1006
+#define GENERIC_POWER_ONOFF_SETUP_SERVER_MODEL_ID   0x1007
+#define GENERIC_POWER_ONOFF_CLIENT_MODEL_ID         0x1008
+
+#define OP_GENERIC_POWER_ONOFF_GET			0x8211
+#define OP_GENERIC_POWER_ONOFF_STATUS			0x8212
+#define OP_GENERIC_POWER_ONOFF_SET			0x8213
+#define OP_GENERIC_POWER_ONOFF_SET_UNACK		0x8214
+
+void power_onoff_set_node(const char *args);
+bool power_onoff_client_init(uint8_t ele);
diff --git a/tools/meshctl.c b/tools/meshctl.c
index 69f8d412f..bd4314790 100644
--- a/tools/meshctl.c
+++ b/tools/meshctl.c
@@ -49,6 +49,7 @@ 
 #include "mesh-gatt/prov-db.h"
 #include "mesh-gatt/onoff-model.h"
 #include "mesh-gatt/level-model.h"
+#include "mesh-gatt/onpowerup-model.h"
 
 /* String display constants */
 #define COLORED_NEW	COLOR_GREEN "NEW" COLOR_OFF
@@ -2003,6 +2004,9 @@  int main(int argc, char *argv[])
 	if (!level_client_init(PRIMARY_ELEMENT_IDX))
 		g_printerr("Failed to initialize mesh generic level client\n");
 
+	if (!power_onoff_client_init(PRIMARY_ELEMENT_IDX))
+		g_printerr("Failed to initialize mesh generic power On/Off client\n");
+
 	status = bt_shell_run();
 
 	g_dbus_client_unref(client);