diff mbox series

[BlueZ,v4,07/13] mesh: Add Mesh Private Beacon server

Message ID 20230124202616.310544-8-brian.gix@gmail.com (mailing list archive)
State Superseded
Headers show
Series Mesh v1.1 additions | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch warning WARNING:PREFER_FALLTHROUGH: Prefer 'fallthrough;' over fallthrough comment #228: FILE: mesh/prvbeac-server.c:74: + /* fall through */ WARNING:PREFER_FALLTHROUGH: Prefer 'fallthrough;' over fallthrough comment #240: FILE: mesh/prvbeac-server.c:86: + /* fall through */ WARNING:PREFER_FALLTHROUGH: Prefer 'fallthrough;' over fallthrough comment #247: FILE: mesh/prvbeac-server.c:93: + /* fall through */ /github/workspace/src/src/13114768.patch total: 0 errors, 3 warnings, 166 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. /github/workspace/src/src/13114768.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
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Brian Gix Jan. 24, 2023, 8:26 p.m. UTC
From: Brian Gix <brian.gix@intel.com>

This initial server supports only the Mesh Private Beacon and returns
"Not Suppoerted" for Get/Set of Private GATT Proxy and Private Node
Identity beacons.
---
 Makefile.mesh         |   1 +
 mesh/prv-beacon.h     |  36 +++++++++++++
 mesh/prvbeac-server.c | 123 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+)
 create mode 100644 mesh/prv-beacon.h
 create mode 100644 mesh/prvbeac-server.c

Comments

Luiz Augusto von Dentz Jan. 24, 2023, 9:52 p.m. UTC | #1
Hi Brian,

On Tue, Jan 24, 2023 at 12:28 PM Brian Gix <brian.gix@gmail.com> wrote:
>
> From: Brian Gix <brian.gix@intel.com>
>
> This initial server supports only the Mesh Private Beacon and returns
> "Not Suppoerted" for Get/Set of Private GATT Proxy and Private Node
> Identity beacons.
> ---
>  Makefile.mesh         |   1 +
>  mesh/prv-beacon.h     |  36 +++++++++++++
>  mesh/prvbeac-server.c | 123 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 160 insertions(+)
>  create mode 100644 mesh/prv-beacon.h
>  create mode 100644 mesh/prvbeac-server.c
>
> diff --git a/Makefile.mesh b/Makefile.mesh
> index e18a169eb..63f085de1 100644
> --- a/Makefile.mesh
> +++ b/Makefile.mesh
> @@ -36,6 +36,7 @@ mesh_sources = mesh/mesh.h mesh/mesh.c \
>                                 mesh/pb-adv.h mesh/pb-adv.c \
>                                 mesh/keyring.h mesh/keyring.c \
>                                 mesh/rpl.h mesh/rpl.c \
> +                               mesh/prv-beacon.h mesh/prvbeac-server.c \

Have the .c follow the same naming convention e.g. prv-beacon.c, we
can actually work out the client vs server internally.

>                                 mesh/mesh-defs.h
>  pkglibexec_PROGRAMS += mesh/bluetooth-meshd
>
> diff --git a/mesh/prv-beacon.h b/mesh/prv-beacon.h
> new file mode 100644
> index 000000000..7be7a01c8
> --- /dev/null
> +++ b/mesh/prv-beacon.h
> @@ -0,0 +1,36 @@
> +/*
> + *
> + *  BlueZ - Bluetooth protocol stack for Linux
> + *
> + *  Copyright (C) 2020  Intel Corporation. All rights reserved.

This should probably be 2023

> + *
> + *
> + *  This library is free software; you can redistribute it and/or
> + *  modify it under the terms of the GNU Lesser General Public
> + *  License as published by the Free Software Foundation; either
> + *  version 2.1 of the License, or (at your option) any later version.
> + *
> + *  This library is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + *  Lesser General Public License for more details.
> + *
> + */
> +
> +struct mesh_node;
> +
> +#define PRV_BEACON_SRV_MODEL   SET_ID(SIG_VENDOR, 0x0008)
> +#define PRV_BEACON_CLI_MODEL   SET_ID(SIG_VENDOR, 0x0009)
> +
> +/* Private Beacon opcodes */
> +#define OP_PRIVATE_BEACON_GET                  0x8060
> +#define OP_PRIVATE_BEACON_SET                  0x8061
> +#define OP_PRIVATE_BEACON_STATUS               0x8062
> +#define OP_PRIVATE_GATT_PROXY_GET              0x8063
> +#define OP_PRIVATE_GATT_PROXY_SET              0x8064
> +#define OP_PRIVATE_GATT_PROXY_STATUS           0x8065
> +#define OP_PRIVATE_NODE_ID_GET                 0x8066
> +#define OP_PRIVATE_NODE_ID_SET                 0x8067
> +#define OP_PRIVATE_NODE_ID_STATUS              0x8068
> +
> +void prv_beacon_server_init(struct mesh_node *node, uint8_t ele_idx);
> diff --git a/mesh/prvbeac-server.c b/mesh/prvbeac-server.c
> new file mode 100644
> index 000000000..78ab94eb3
> --- /dev/null
> +++ b/mesh/prvbeac-server.c
> @@ -0,0 +1,123 @@
> +/*
> + *
> + *  BlueZ - Bluetooth protocol stack for Linux
> + *
> + *  Copyright (C) 2020  Intel Corporation. All rights reserved.
> + *
> + *
> + *  This library is free software; you can redistribute it and/or
> + *  modify it under the terms of the GNU Lesser General Public
> + *  License as published by the Free Software Foundation; either
> + *  version 2.1 of the License, or (at your option) any later version.
> + *
> + *  This library is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + *  Lesser General Public License for more details.
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <sys/time.h>
> +#include <ell/ell.h>
> +
> +#include "mesh/mesh-defs.h"
> +#include "mesh/node.h"
> +#include "mesh/net.h"
> +#include "mesh/appkey.h"
> +#include "mesh/model.h"
> +#include "mesh/mesh-config.h"
> +#include "mesh/prv-beacon.h"
> +
> +#define NOT_SUPPORTED 0x02
> +
> +static bool prvbec_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
> +                               uint16_t net_idx, const uint8_t *data,
> +                               uint16_t size, const void *user_data)
> +{
> +       struct mesh_node *node = (struct mesh_node *) user_data;
> +       const uint8_t *pkt = data;
> +       uint32_t opcode;
> +       uint8_t msg[5];
> +       uint16_t n;
> +       uint8_t period = 0;
> +
> +       if (app_idx != APP_IDX_DEV_LOCAL)
> +               return false;
> +
> +       if (mesh_model_opcode_get(pkt, size, &opcode, &n)) {
> +               size -= n;
> +               pkt += n;
> +       } else
> +               return false;
> +
> +       l_debug("PRV-BEAC-SRV-opcode 0x%x size %u idx %3.3x", opcode, size,
> +                                                               net_idx);
> +
> +       n = 0;
> +
> +       switch (opcode) {
> +       default:
> +               return false;
> +
> +       case OP_PRIVATE_BEACON_SET:
> +               if (size == 1)
> +                       period = 0xff;
> +               else if (size == 2)
> +                       period = pkt[1];
> +               else
> +                       return true;
> +
> +               /* fall through */
> +
> +       case OP_PRIVATE_BEACON_GET:
> +               n = mesh_model_opcode_set(OP_PRIVATE_BEACON_STATUS, msg);
> +
> +               msg[n++] = NOT_SUPPORTED;
> +               msg[n++] = period;
> +
> +               l_debug("Get/Set Private Beacon (%d)", msg[n-2]);
> +               break;
> +
> +       case OP_PRIVATE_GATT_PROXY_SET:
> +               /* fall through */
> +       case OP_PRIVATE_GATT_PROXY_GET:
> +               n = mesh_model_opcode_set(OP_PRIVATE_GATT_PROXY_STATUS, msg);
> +               msg[n++] = NOT_SUPPORTED;
> +               break;
> +
> +       case OP_PRIVATE_NODE_ID_SET:
> +               /* fall through */
> +       case OP_PRIVATE_NODE_ID_GET:
> +               n = mesh_model_opcode_set(OP_PRIVATE_NODE_ID_STATUS, msg);
> +               msg[n++] = NOT_SUPPORTED;
> +               break;
> +       }
> +
> +       if (n)
> +               mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, net_idx,
> +                                               DEFAULT_TTL, false, n, msg);
> +
> +       return true;
> +}
> +
> +static void prvbec_srv_unregister(void *user_data)
> +{
> +}
> +
> +static const struct mesh_model_ops ops = {
> +       .unregister = prvbec_srv_unregister,
> +       .recv = prvbec_srv_pkt,
> +       .bind = NULL,
> +       .sub = NULL,
> +       .pub = NULL
> +};
> +
> +void prv_beacon_server_init(struct mesh_node *node, uint8_t ele_idx)
> +{
> +       l_debug("%2.2x", ele_idx);
> +       mesh_model_register(node, ele_idx, PRV_BEACON_SRV_MODEL, &ops, node);
> +}
> --
> 2.39.1
>
diff mbox series

Patch

diff --git a/Makefile.mesh b/Makefile.mesh
index e18a169eb..63f085de1 100644
--- a/Makefile.mesh
+++ b/Makefile.mesh
@@ -36,6 +36,7 @@  mesh_sources = mesh/mesh.h mesh/mesh.c \
 				mesh/pb-adv.h mesh/pb-adv.c \
 				mesh/keyring.h mesh/keyring.c \
 				mesh/rpl.h mesh/rpl.c \
+				mesh/prv-beacon.h mesh/prvbeac-server.c \
 				mesh/mesh-defs.h
 pkglibexec_PROGRAMS += mesh/bluetooth-meshd
 
diff --git a/mesh/prv-beacon.h b/mesh/prv-beacon.h
new file mode 100644
index 000000000..7be7a01c8
--- /dev/null
+++ b/mesh/prv-beacon.h
@@ -0,0 +1,36 @@ 
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2020  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ */
+
+struct mesh_node;
+
+#define PRV_BEACON_SRV_MODEL	SET_ID(SIG_VENDOR, 0x0008)
+#define PRV_BEACON_CLI_MODEL	SET_ID(SIG_VENDOR, 0x0009)
+
+/* Private Beacon opcodes */
+#define OP_PRIVATE_BEACON_GET			0x8060
+#define OP_PRIVATE_BEACON_SET			0x8061
+#define OP_PRIVATE_BEACON_STATUS		0x8062
+#define OP_PRIVATE_GATT_PROXY_GET		0x8063
+#define OP_PRIVATE_GATT_PROXY_SET		0x8064
+#define OP_PRIVATE_GATT_PROXY_STATUS		0x8065
+#define OP_PRIVATE_NODE_ID_GET			0x8066
+#define OP_PRIVATE_NODE_ID_SET			0x8067
+#define OP_PRIVATE_NODE_ID_STATUS		0x8068
+
+void prv_beacon_server_init(struct mesh_node *node, uint8_t ele_idx);
diff --git a/mesh/prvbeac-server.c b/mesh/prvbeac-server.c
new file mode 100644
index 000000000..78ab94eb3
--- /dev/null
+++ b/mesh/prvbeac-server.c
@@ -0,0 +1,123 @@ 
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2020  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/time.h>
+#include <ell/ell.h>
+
+#include "mesh/mesh-defs.h"
+#include "mesh/node.h"
+#include "mesh/net.h"
+#include "mesh/appkey.h"
+#include "mesh/model.h"
+#include "mesh/mesh-config.h"
+#include "mesh/prv-beacon.h"
+
+#define NOT_SUPPORTED 0x02
+
+static bool prvbec_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
+				uint16_t net_idx, const uint8_t *data,
+				uint16_t size, const void *user_data)
+{
+	struct mesh_node *node = (struct mesh_node *) user_data;
+	const uint8_t *pkt = data;
+	uint32_t opcode;
+	uint8_t msg[5];
+	uint16_t n;
+	uint8_t period = 0;
+
+	if (app_idx != APP_IDX_DEV_LOCAL)
+		return false;
+
+	if (mesh_model_opcode_get(pkt, size, &opcode, &n)) {
+		size -= n;
+		pkt += n;
+	} else
+		return false;
+
+	l_debug("PRV-BEAC-SRV-opcode 0x%x size %u idx %3.3x", opcode, size,
+								net_idx);
+
+	n = 0;
+
+	switch (opcode) {
+	default:
+		return false;
+
+	case OP_PRIVATE_BEACON_SET:
+		if (size == 1)
+			period = 0xff;
+		else if (size == 2)
+			period = pkt[1];
+		else
+			return true;
+
+		/* fall through */
+
+	case OP_PRIVATE_BEACON_GET:
+		n = mesh_model_opcode_set(OP_PRIVATE_BEACON_STATUS, msg);
+
+		msg[n++] = NOT_SUPPORTED;
+		msg[n++] = period;
+
+		l_debug("Get/Set Private Beacon (%d)", msg[n-2]);
+		break;
+
+	case OP_PRIVATE_GATT_PROXY_SET:
+		/* fall through */
+	case OP_PRIVATE_GATT_PROXY_GET:
+		n = mesh_model_opcode_set(OP_PRIVATE_GATT_PROXY_STATUS, msg);
+		msg[n++] = NOT_SUPPORTED;
+		break;
+
+	case OP_PRIVATE_NODE_ID_SET:
+		/* fall through */
+	case OP_PRIVATE_NODE_ID_GET:
+		n = mesh_model_opcode_set(OP_PRIVATE_NODE_ID_STATUS, msg);
+		msg[n++] = NOT_SUPPORTED;
+		break;
+	}
+
+	if (n)
+		mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, net_idx,
+						DEFAULT_TTL, false, n, msg);
+
+	return true;
+}
+
+static void prvbec_srv_unregister(void *user_data)
+{
+}
+
+static const struct mesh_model_ops ops = {
+	.unregister = prvbec_srv_unregister,
+	.recv = prvbec_srv_pkt,
+	.bind = NULL,
+	.sub = NULL,
+	.pub = NULL
+};
+
+void prv_beacon_server_init(struct mesh_node *node, uint8_t ele_idx)
+{
+	l_debug("%2.2x", ele_idx);
+	mesh_model_register(node, ele_idx, PRV_BEACON_SRV_MODEL, &ops, node);
+}