Kernel based mesh functionality
Subsystems (3)
cover Kernel based mesh functionality
This patch set makes the bluetooth-meshd daemon use the Kernel based mesh support *if available*. It defines and calls the MGMT commands and events needed so that a controller can be used without making it unavailable to the bluetoothd daemon.
Brian Gix (7):
mgmt: Add support for Mesh in the kernel
mgmt: Mesh specific structures and defines
mesh: Add common MGMT command accessors
mesh: rework Mesh-IO for multiple transports
mesh: Added default "auto" to command line parsing
mesh: Add new MGMT based IO transport
mesh: Make Provisioning requests more IO compatible
Makefile.mesh | 9 +- doc/mgmt-api.txt | 180 ++++++++++ lib/mgmt.h | 54 +++ mesh/main.c | 39 +- mesh/mesh-io-api.h | 11 +- mesh/mesh-io-generic.c | 47 +-- mesh/mesh-io-mgmt.c | 787 +++++++++++++++++++++++++++++++++++++++++ mesh/mesh-io-mgmt.h | 11 + mesh/mesh-io-unit.c | 13 +- mesh/mesh-io.c | 191 +++++++--- mesh/mesh-io.h | 4 +- mesh/mesh-mgmt.c | 149 ++++++-- mesh/mesh-mgmt.h | 12 +- mesh/mesh.c | 6 +- mesh/mesh.h | 2 +- mesh/pb-adv.c | 9 +- 16 files changed, 1379 insertions(+), 145 deletions(-) create mode 100644 mesh/mesh-io-mgmt.c create mode 100644 mesh/mesh-io-mgmt.h
Signature · 1 line
2.35.1
PATCH 1/7 mgmt: Add support for Mesh in the kernel
These commands and events allow User space apps to test for Mesh support, and request incoming mesh packets be delivered and request outbound mesh packets to be sent. This is the basis for sharing one controller between the legacy bluetoothd daemon and the mesh bluetooth-meshd daemon.
--- doc/mgmt-api.txt | 180 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+)
doc/mgmt-api.txt +180 -0
@@ -3858,6 +3858,132 @@ Add Advertisement Patterns Monitor With RSSI Threshold Command Invalid Parameters +Set Mesh Receiver Command +========================= + + Command Code: 0x0057 + Controller Index: <controller id> + Command Parameters: Enable (1 Octets) + Window (2 Octets) + Period (2 Octets) + Num AD Types (1 Octets) + AD Types { } + + This command Enables or Disables Mesh Receiving. When enabled passive + scanning remains enabled for this controller. + + The Window/Period values are used to set the Scan Parameters when no + other scanning is being done. + + Num AD Types and AD Types parameter, filter Advertising and Scan + responses by AD type. Reponses that do not contain at least one of the + requested AD types will be ignored. Otherwise they will be delivered + with the Mesh Device Found event. + + Possible errors: Failed + No Resources + Invalid Parameters + + +Read Mesh Features Command +========================== + + Command Code: 0x0058 + Controller Index: <controller id> + Command Parameters: + Return Parameters: Index (2 Octets) + Max Handles (1 Octets) + Used Handles (1 Octets) + Handle { } + + This command is used to both verify that Outbound Mesh packet + support is enabled, and to indicate the number of packets that + can and are simultaneously queued. + + Index identifies the HCI Controller that this information is valid for. + + Max Handles indicates the maximum number of packets that may be queued. + + Used Handles indicates the number of packets awaiting transmission. + + Handle is an array of the currently outstanding packets. + + Possible errors: Failed + No Resources + Invalid Parameters + + +Transmit Mesh Packet Command +============================ + + Command Code: 0x0059 + Controller Index: <controller id> + Command Parameters: Addr (6 octets) + Addr Type (1 Octets) + Instant (8 Octets) + Delay (2 Octets) + Count (1 Octets) + Data (variable) + + Return Parameters: Handle (1 Octets) + + This command sends a Mesh Packet as a NONCONN LE Advertisement. + + The Addr + Addr Type parameters specifify the address to use in the + outbound advertising packet. If BD_ADDR_ANY and LE_RANDOM is set, the + kernel will create a single use non-resolvable address. + + The Instant parameter is used in combination with the Delay + parameter, to finely time the sending of the Advertising packet. It + should be set to the Instant value tag of a received incoming + Mesh Device Found Event. It is only useful in POLL-RESPONSE situations + where a response must be sent within a negotiated time window. The value + of the Instant parameter should not be interpreted by the host, and + only has meaning to the controller. + + The Delay parameter, if 0x0000, will cause the packet to be sent + at the earliest opportunity. If non-Zero, and the controller supports + delayed delivery, the Instant and Delay parameters will be used + to delay the outbound packet. While the Instant is not defined, the + Delay is specified in milliseconds. + + The Count parameter must be sent to a non-Zero value indicating the + number of times this packet will be sent before transmission completes. + If the Delay parameter is non-Zero, then Count must be 1 only. + + The Data parameter is an octet array of the AD Type and Mesh Packet. + + This command will return immediately, and if it succeeds, will generate + a Mesh Packet Transmission Complete event when after the packet has been + sent. + + Possible errors: Failed + Busy + No Resources + Invalid Parameters + + +Cancel Transmit Mesh Packet Command +=================================== + + Command Code: 0x005A + Controller Index: <controller id> + Command Parameters: Handle (1 Octets) + + This command may be used to cancel an outbound transmission request. + + The Handle parameter is the returned handle from a successful Transmit + Mesh Packet request. If Zero is specified as the handle, all outstanding + send requests are canceled. + + For each mesh packet canceled, the Mesh Packet Transmission Complete + event will be generated, regardless of whether the packet was sent + successfully. + + Possible errors: Failed + Invalid Parameters + + Command Complete Event ======================
@@ -4978,3 +5104,57 @@ Advertisement Monitor Device Lost Event 2 LE Random This event will be sent to all management sockets. + + +Mesh Device Found Event +======================= + + Event code: 0x0031 + Controller Index: <controller_id> + Event Parameters: Address (6 Octets) + Address_Type (1 Octet) + RSSI (1 Octet) + Flags (4 Octets) + Instant (8 Octets) + AD_Data_Length (2 Octets) + AD_Data (0-65535 Octets) + + This event indicates that the controller has received an Advertisement + or Scan Result containing an AD Type matching the Mesh scan set. + + The address of the sending device is returned, and must be a valid LE + Address_Type. + + Possible values for the Address_Type parameter: + 0 Reserved (not in use) + 1 LE Public + 2 LE Random + + The RSSI field is a signed octet, and is the RSSI reported by the + receiving controller. + + The Instant field is 64 bit value that represents the instant in time + the packet was received. It's value is not intended to be interpretted + by the host, and is only useful if the host wants to make a timed + response to the received packet. (i.e. a Poll/Response) + + AD_Length and AD_Data contains the Info structure of Advertising and + Scan rsults. To receive this event, AD filters must be requested with + the Set Mesh Receiver command command, specifying which AD Types to + return. All AD structures will be received in this event if any of the + filtered AD Types are present. + + This event will be sent to all management sockets. + + +Mesh Packet Transmit Complete Event +=================================== + + Event code: 0x0032 + Controller Index: <controller_id> + Event Parameters: Handle (1 Octets) + + This event indicates that a requested outbound Mesh packet has + completed and no longer occupies a transmit slot. + + This event will be sent to all management sockets.
Signature · 1 line
2.35.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=617384
---Test result---
Test Summary:
CheckPatch FAIL 4.85 seconds GitLint PASS 2.61 seconds Prep - Setup ELL PASS 48.28 seconds Build - Prep PASS 0.44 seconds Build - Configure PASS 9.45 seconds Build - Make PASS 1347.83 seconds Make Check PASS 12.25 seconds Make Check w/Valgrind PASS 465.19 seconds Make Distcheck PASS 243.36 seconds Build w/ext ELL - Configure PASS 8.66 seconds Build w/ext ELL - Make PASS 1383.39 seconds Incremental Build with patchesFAIL 4627.24 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf Output:
[1/7] mgmt: Add support for Mesh in the kernel WARNING:REPEATED_WORD: Possible repeated word: 'command' #252: FILE: doc/mgmt-api.txt:5143:
+ the Set Mesh Receiver command command, specifying which AD Types to
/github/workspace/src/12757782.patch total: 0 errors, 1 warnings, 189 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/12757782.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.
[3/7] mesh: Add common MGMT command accessors WARNING:TYPO_SPELLING: 'accross' may be misspelled - perhaps 'across'? #69:
a single socket, shared accross all consumers.
^^^^^^^
ERROR:FUNCTION_WITHOUT_ARGS: Bad function definition - void mesh_mgmt_destroy() should probably be void mesh_mgmt_destroy(void) #285: FILE: mesh/mesh-mgmt.c:226:
+void mesh_mgmt_destroy()
/github/workspace/src/12757783.patch total: 1 errors, 1 warnings, 243 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/12757783.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.
[4/7] mesh: rework Mesh-IO for multiple transports WARNING:LINE_SPACING: Missing a blank line after declarations #334: FILE: mesh/mesh-io-mgmt.c:108:
+ const struct dup_filter *filter = a;
+ return !memcmp(filter->addr, b, 6);
WARNING:SPACING: space prohibited between function name and open parenthesis '(' #337: FILE: mesh/mesh-io-mgmt.c:111:
+static void filter_timeout (struct l_timeout *timeout, void *user_data)
ERROR:CODE_INDENT: code indent should use tabs where possible #367: FILE: mesh/mesh-io-mgmt.c:141:
+ uint32_t instant)$
WARNING:LEADING_SPACE: please, no spaces at the start of a line #367: FILE: mesh/mesh-io-mgmt.c:141:
+ uint32_t instant)$
WARNING:SUSPECT_CODE_INDENT: suspect code indent for conditional statements (16, 16) #465: FILE: mesh/mesh-io-mgmt.c:239:
+ if (adv[1] >= 0x29 && adv[1] <= 0x2B)
+ process_rx(io->pvt, ev->rssi, instant, addr, adv + 1, adv[0]);
WARNING:BRACES: braces {} are not necessary for single statement blocks #1102: FILE: mesh/mesh-io.c:51:
+ if (table[i].type == type) {
+ return table[i].api;
+ }
WARNING:BRACES: braces {} are not necessary for any arm of this statement #1173: FILE: mesh/mesh-io.c:97:
+ if (mesh && type != MESH_IO_TYPE_GENERIC) {
[...]
- if (l_queue_push_head(io_list, io))
[...]
WARNING:BRACES: braces {} are not necessary for single statement blocks #1179: FILE: mesh/mesh-io.c:101:
+ else if (!pwr) {
+ api = io_api(MESH_IO_TYPE_GENERIC);
+ }
/github/workspace/src/12757784.patch total: 1 errors, 7 warnings, 1227 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/12757784.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.
##############################
Test: Incremental Build with patches - FAIL
Desc: Incremental build per patch in the series
Output:tools/mgmt-tester.c: In function ‘main’:tools/mgmt-tester.c:12364:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without 12364 | int main(int argc, char *argv[])
| ^~~~
unit/test-avdtp.c: In function ‘main’:
unit/test-avdtp.c:766:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without
766 | int main(int argc, char *argv[])
| ^~~~
unit/test-avrcp.c: In function ‘main’:
unit/test-avrcp.c:989:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without
989 | int main(int argc, char *argv[])
| ^~~~
In file included from mesh/mesh-io-generic.c:26:
./mesh/mesh-mgmt.h:18:5: error: unknown type name ‘mgmt_request_func_t’
18 | mgmt_request_func_t callback,
| ^~~~~~~~~~~~~~~~~~~
./mesh/mesh-mgmt.h:19:22: error: unknown type name ‘mgmt_destroy_func_t’; did you mean ‘bt_hci_destroy_func_t’?
19 | void *user_data, mgmt_destroy_func_t destroy);
| ^~~~~~~~~~~~~~~~~~~
| bt_hci_destroy_func_t
./mesh/mesh-mgmt.h:21:5: error: unknown type name ‘mgmt_notify_func_t’
21 | mgmt_notify_func_t callback,
| ^~~~~~~~~~~~~~~~~~
./mesh/mesh-mgmt.h:22:22: error: unknown type name ‘mgmt_destroy_func_t’; did you mean ‘bt_hci_destroy_func_t’?
22 | void *user_data, mgmt_destroy_func_t destroy);
| ^~~~~~~~~~~~~~~~~~~
| bt_hci_destroy_func_t
mesh/mesh-io-generic.c: In function ‘dev_init’:
mesh/mesh-io-generic.c:448:25: error: passing argument 1 of ‘mesh_mgmt_list’ from incompatible pointer type [-Werror=incompatible-pointer-types]
448 | return mesh_mgmt_list(read_info, io);
| ^~~~~~~~~
| |
| void (*)(int, void *)
In file included from mesh/mesh-io-generic.c:26:
./mesh/mesh-mgmt.h:15:48: note: expected ‘mesh_mgmt_read_info_func_t’ {aka ‘void (*)(int, _Bool, _Bool, _Bool, void *)’} but argument is of type ‘void (*)(int, void *)’
15 | bool mesh_mgmt_list(mesh_mgmt_read_info_func_t cb, void *user_data);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~cc1: all warnings being treated as errors
make[1]: *** [Makefile:7271: mesh/mesh-io-generic.o] Error 1
make: *** [Makefile:4307: all] Error 2
---
Regards,
Linux Bluetooth
PATCH 2/7 mgmt: Mesh specific structures and defines
In reply to Brian GixAdds the Mesh commands and events as described in mgmt-api.txt
--- lib/mgmt.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
lib/mgmt.h +54 -0
@@ -757,6 +757,39 @@ struct mgmt_cp_add_adv_patterns_monitor_rssi {struct mgmt_adv_pattern patterns[0 ]; } __packed; +#define MGMT_OP_SET_MESH_RECEIVER 0x0057 +struct mgmt_cp_set_mesh { +uint8_t enable; +uint16_t window; +uint16_t period; +uint8_t num_ad_types; +uint8_t ad_types[]; +} __packed; + +#define MGMT_OP_MESH_READ_FEATURES 0x0058 +struct mgmt_rp_mesh_read_features { +uint16_t index; +uint8_t max_handles; +uint8_t used_handles; +uint8_t handles[]; +} __packed; + + +#define MGMT_OP_MESH_SEND 0x0059 +struct mgmt_cp_mesh_send { +struct mgmt_addr_info addr; +uint64_t instant; +uint16_t delay; +uint8_t cnt; +uint8_t data[]; +} __packed; + +#define MGMT_OP_MESH_SEND_CANCEL 0x005A +struct mgmt_cp_mesh_send_cancel { +uint8_t handle; +} __packed; + +#define MGMT_EV_CMD_COMPLETE 0x0001struct mgmt_ev_cmd_complete {uint16_t opcode;
@@ -1032,6 +1065,21 @@ struct mgmt_ev_adv_monitor_device_lost {struct mgmt_addr_info addr; } __packed; +#define MGMT_EV_MESH_DEVICE_FOUND 0x0031 +struct mgmt_ev_mesh_device_found { +struct mgmt_addr_info addr; +int8_t rssi; +uint32_t flags; +uint64_t instant; +uint16_t eir_len; +uint8_t eir[]; +} __packed; + +#define MGMT_EV_MESH_PACKET_CMPLT 0x0032 +struct mgmt_ev_mesh_pkt_cmplt { +uint8_t handle; +} __packed; +static const char *mgmt_op[] = {"<0x0000>" ,"Read Version" ,
@@ -1120,6 +1168,10 @@ static const char *mgmt_op[] = {"Add Extended Advertisement Parameters" ,/* 0x0054 */ "Add Extended Advertisement Data" ,"Add Advertisement Patterns Monitor RSSI" , +"Set Mesh Receiver" , +"Read Mesh Features" , +"Mesh Send" , + "Mesh Send Cancel", }; static const char *mgmt_ev[] = {
@@ -1172,6 +1224,8 @@ static const char *mgmt_ev[] = {"Controller Resume" ,"Advertisement Monitor Device Found" ,/* 0x002f */ "Advertisement Monitor Device Lost" , +"Mesh Packet Found" , + "Mesh Packet Complete", }; static const char *mgmt_status[] = {
Signature · 1 line
2.35.1
PATCH 3/7 mesh: Add common MGMT command accessors
In reply to Brian GixWhile mesh-io-mgmt is the main consumer of MGMT services, we also use MGMT to identify controllers and their capabilities, when determining the appropriate Mesh IO carrier. This centralizes all MGMT access to a single socket, shared accross all consumers.
Also fixes the Controller added/removed handling so that a controller disappearing or reappearing gets handled rationally.
--- mesh/mesh-mgmt.c | 149 ++++++++++++++++++++++++++++++++++++----------- mesh/mesh-mgmt.h | 12 +++- 2 files changed, 125 insertions(+), 36 deletions(-)
mesh/mesh-mgmt.c +114 -35
@@ -12,35 +12,63 @@#include <config.h> #endif +#include <ell/ell.h> +#include "lib/bluetooth.h" #include "lib/mgmt.h" #include "src/shared/mgmt.h" -#include "ell/queue.h" -#include "ell/log.h" -#include "ell/util.h" -#include "mesh/mesh-mgmt.h" -struct read_info_reg { -mesh_mgmt_read_info_func_t cb; -void *user_data; -}; - -struct read_info_req { -int index; -struct mesh_io *io; +struct mesh_controler { +int index; +bool mesh_support; +bool powered; }; +static mesh_mgmt_read_info_func_t ctl_info;static struct mgmt *mgmt_mesh; -static struct l_queue *read_info_regs; +static struct l_queue *ctl_list; +static void *list_user_data; +static bool mesh_detected; + +static bool by_index (const void *a,const void *b) +{ +const struct mesh_controler *ctl = a; +int index =L_PTR_TO_UINT (b); -static void process_read_info_req (void *data,void *user_data) +return ctl->index == index; +} + +static void index_removed (uint16_t index,uint16_t length,const void *param, +void *user_data); +static void features_cb (uint8_t status,uint16_t length, +const void *param,void *user_data) { -struct read_info_reg *reg = data;int index =L_PTR_TO_UINT (user_data); +struct mesh_controler *ctl; + - reg->cb (index, reg->user_data); + ctl =l_queue_find (ctl_list, by_index,L_UINT_TO_PTR (index)); +if (!ctl) +return ; + +l_debug ("Status: %d, Length: %d" , status, length); +if (status !=MGMT_STATUS_NOT_SUPPORTED && + status !=MGMT_STATUS_UNKNOWN_COMMAND ) { + ctl->mesh_support = true; +if (!mesh_detected) { +mgmt_register (mgmt_mesh,MGMT_EV_INDEX_REMOVED , +MGMT_INDEX_NONE , index_removed, +NULL ,NULL ); + } + mesh_detected = true; + }else +l_debug ("Kernel mesh not supported for hci%u" , index); + +if (ctl_info) +ctl_info (index, true, ctl->powered, ctl->mesh_support, + list_user_data); } static void read_info_cb(uint8_t status, uint16_t length,
@@ -49,12 +77,25 @@ static void read_info_cb(uint8_t status, uint16_t length,int index =L_PTR_TO_UINT (user_data);const struct mgmt_rp_read_info *rp = param;uint32_t current_settings, supported_settings; +struct mesh_controler *ctl;l_debug ("hci %u status 0x%02x" , index, status); + ctl =l_queue_find (ctl_list, by_index,L_UINT_TO_PTR (index)); +if (!ctl) +return ; +if (status !=MGMT_STATUS_SUCCESS ) { + ctl =l_queue_remove_if (ctl_list, by_index, +L_UINT_TO_PTR (index));l_error ("Failed to read info for hci index %u: %s (0x%02x)" , index,mgmt_errstr (status), status); + +l_warn ("Hci dev %d removal detected" , index); +if (ctl && ctl_info) +ctl_info (index, false, false, false, list_user_data); + +l_free (ctl);return ; }
@@ -69,23 +110,34 @@ static void read_info_cb(uint8_t status, uint16_t length,l_debug ("settings: supp %8.8x curr %8.8x" , supported_settings, current_settings); -if (current_settings &MGMT_SETTING_POWERED ) { -l_info ("Controller hci %u is in use" , index); -return ; - } -if (!(supported_settings &MGMT_SETTING_LE )) {l_info ("Controller hci %u does not support LE" , index); +l_queue_remove (ctl_list, ctl); +l_free (ctl);return ; } -l_queue_foreach (read_info_regs, process_read_info_req, -L_UINT_TO_PTR (index)); +if (current_settings &MGMT_SETTING_POWERED ) + ctl->powered = true; + +mesh_mgmt_send (MGMT_OP_MESH_READ_FEATURES , index,0 ,NULL , + features_cb,L_UINT_TO_PTR (index),NULL ); }static void index_added (uint16_t index,uint16_t length,const void *param,void *user_data) { +struct mesh_controler *ctl =l_queue_find (ctl_list, by_index, +L_UINT_TO_PTR (index)); + +if (!ctl) { + ctl = l_new(struct mesh_controler, 1); + ctl->index = index; +l_queue_push_head (ctl_list, ctl); + }else { + ctl->mesh_support = ctl->powered = false; + } +mgmt_send (mgmt_mesh,MGMT_OP_READ_INFO , index,0 ,NULL , read_info_cb,L_UINT_TO_PTR (index),NULL ); }
@@ -93,7 +145,9 @@ static void index_added(uint16_t index, uint16_t length, const void *param,static void index_removed (uint16_t index,uint16_t length,const void *param,void *user_data) { -l_warn ("Hci dev %4.4x removed" , index); +mgmt_send (mgmt_mesh,MGMT_OP_READ_INFO , index,0 ,NULL , + read_info_cb,L_UINT_TO_PTR (index),NULL ); + } static void read_index_list_cb(uint8_t status, uint16_t length,
@@ -133,8 +187,8 @@ static void read_index_list_cb(uint8_t status, uint16_t length,static bool mesh_mgmt_init (void ) { -if (!read_info_regs) - read_info_regs =l_queue_new (); +if (!ctl_list) + ctl_list =l_queue_new ();if (!mgmt_mesh) { mgmt_mesh =mgmt_new_default ();
@@ -146,8 +200,6 @@ static bool mesh_mgmt_init(void)mgmt_register (mgmt_mesh,MGMT_EV_INDEX_ADDED ,MGMT_INDEX_NONE , index_added,NULL ,NULL ); -mgmt_register (mgmt_mesh,MGMT_EV_INDEX_REMOVED , -MGMT_INDEX_NONE , index_removed,NULL ,NULL ); }return true;
@@ -155,16 +207,11 @@ static bool mesh_mgmt_init(void)bool mesh_mgmt_list (mesh_mgmt_read_info_func_t cb,void *user_data) { -struct read_info_reg *reg; -if (!mesh_mgmt_init ())return false; - reg = l_new(struct read_info_reg, 1); - reg->cb = cb; - reg->user_data = user_data; - -l_queue_push_tail (read_info_regs, reg); + ctl_info = cb; + list_user_data = user_data;/* Use MGMT to find a candidate controller */ l_debug ("send read index_list" );
@@ -175,3 +222,35 @@ bool mesh_mgmt_list(mesh_mgmt_read_info_func_t cb, void *user_data)return true; } + +void mesh_mgmt_destroy () +{ +mgmt_unref (mgmt_mesh); + mgmt_mesh =NULL ; + ctl_info =NULL ; + list_user_data =NULL ; +l_queue_destroy (ctl_list, l_free); + ctl_list =NULL ; +} + +unsigned int mesh_mgmt_send (uint16_t opcode,uint16_t index, +uint16_t length,const void *param, +mgmt_request_func_t callback, +void *user_data,mgmt_destroy_func_t destroy) +{ +return mgmt_send_timeout (mgmt_mesh, opcode, index, length, param, + callback, user_data, destroy,0 ); +} + +unsigned int mesh_mgmt_register (uint16_t event,uint16_t index, +mgmt_notify_func_t callback, +void *user_data,mgmt_destroy_func_t destroy) +{ +return mgmt_register (mgmt_mesh, event, index, callback, + user_data, destroy); +} + +bool mesh_mgmt_unregister (unsigned int id) +{ +return mgmt_unregister (mgmt_mesh, id); +}
mesh/mesh-mgmt.h +11 -1
@@ -9,6 +9,16 @@*/ #include <stdbool.h> -typedef void (*mesh_mgmt_read_info_func_t )(int index,void *user_data); +typedef void (*mesh_mgmt_read_info_func_t )(int index,bool added,bool powered, +bool mesh,void *user_data);bool mesh_mgmt_list (mesh_mgmt_read_info_func_t cb,void *user_data); +unsigned int mesh_mgmt_send (uint16_t opcode,uint16_t index, +uint16_t length,const void *param, +mgmt_request_func_t callback, +void *user_data,mgmt_destroy_func_t destroy); +unsigned int mesh_mgmt_register (uint16_t event,uint16_t index, +mgmt_notify_func_t callback, +void *user_data,mgmt_destroy_func_t destroy); +bool mesh_mgmt_unregister (unsigned int id); +void mesh_mgmt_destroy (void );
Signature · 1 line
2.35.1
PATCH 4/7 mesh: rework Mesh-IO for multiple transports
In reply to Brian GixThis patch adds mesh-io-mgmt (Kernel MGMT based transport) and streamlines the handling of identifying and activating the appropriate transport.
--- mesh/mesh-io-api.h | 11 +- mesh/mesh-io-generic.c | 47 +-- mesh/mesh-io-generic.h | 1 + mesh/mesh-io-mgmt.c | 787 +++++++++++++++++++++++++++++++++++++++++ mesh/mesh-io-unit.c | 11 +- mesh/mesh-io.c | 190 +++++++--- mesh/mesh-io.h | 4 +- 7 files changed, 957 insertions(+), 94 deletions(-) create mode 100644 mesh/mesh-io-mgmt.c
mesh/mesh-io-api.h +7 -4
@@ -10,8 +10,7 @@struct mesh_io_private ; -typedef bool (*mesh_io_init_t )(struct mesh_io *io,void *opts, -mesh_io_ready_func_t cb,void *user_data); +typedef bool (*mesh_io_init_t )(struct mesh_io *io,void *opts,void *user_data);typedef bool (*mesh_io_destroy_t )(struct mesh_io *io);typedef bool (*mesh_io_caps_t )(struct mesh_io *io,struct mesh_io_caps *caps); typedef bool (*mesh_io_send_t)(struct mesh_io *io,
@@ -36,9 +35,13 @@ struct mesh_io_api { };struct mesh_io { -enum mesh_io_type type; -const struct mesh_io_api *api; +int index; +int favored_index; +mesh_io_ready_func_t ready; +struct l_queue *rx_regs;struct mesh_io_private *pvt; +void *user_data; +const struct mesh_io_api *api; };struct mesh_io_table {
mesh/mesh-io-generic.c +11 -36
94 lines not on this page · raw message
mesh/mesh-io-generic.h +1 -0
@@ -9,3 +9,4 @@*/ extern const struct mesh_io_api mesh_io_generic; +extern const struct mesh_io_api mesh_io_mgmt;
mesh/mesh-io-mgmt.c new file +787 -0
787 lines not on this page · raw message
mesh/mesh-io-unit.c +5 -6
@@ -28,10 +28,10 @@#include "mesh/mesh-io-generic.h" struct mesh_io_private { +struct mesh_io *io;struct l_io *sio;void *user_data;char *unique_name; -mesh_io_ready_func_t ready_callback;struct l_timeout *tx_timeout;struct l_queue *rx_regs;struct l_queue *tx_pkts;
@@ -203,14 +203,13 @@ static void unit_up(void *user_data)l_debug ("Started io-unit" ); -if (pvt->ready_callback) - pvt->ready_callback (pvt->user_data, true); +if (pvt->io && pvt->io->ready) + pvt->io->ready (pvt->user_data, true);l_timeout_create_ms (1 , get_name, pvt,NULL ); } -static bool unit_init (struct mesh_io *io,void *opt, -mesh_io_ready_func_t cb,void *user_data) +static bool unit_init (struct mesh_io *io,void *opt,void *user_data) {struct mesh_io_private *pvt;char *sk_path;
@@ -247,7 +246,7 @@ static bool unit_init(struct mesh_io *io, void *opt, pvt->rx_regs =l_queue_new (); pvt->tx_pkts =l_queue_new (); - pvt->ready_callback = cb; + pvt->io = io; pvt->user_data = user_data; io->pvt = pvt;
mesh/mesh-io.c +143 -47
271 lines not on this page · raw message
mesh/mesh-io.h +3 -1
@@ -14,8 +14,10 @@ struct mesh_io;enum mesh_io_type {MESH_IO_TYPE_NONE =0 , +MESH_IO_TYPE_UNIT_TEST , +MESH_IO_TYPE_AUTO ,/* If MGMT required, add after here */ +MESH_IO_TYPE_MGMT ,MESH_IO_TYPE_GENERIC , -MESH_IO_TYPE_UNIT_TEST };enum mesh_io_timing_type {
Signature · 1 line
2.35.1
PATCH 5/7 mesh: Added default "auto" to command line parsing
In reply to Brian GixWhile it will still be possible to request the "unit" and "hci" based transports, "auto" has been added as a default to specify "best choice" as determined by MGMT based enumeration of available controllers.
--- mesh/main.c | 39 +++++++++++++++++++++++++++++++++++---- mesh/mesh.c | 6 +++++- mesh/mesh.h | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-)
mesh/main.c +35 -4
@@ -123,6 +123,12 @@ static void disconnect_callback(void *user_data)l_main_quit (); } +static void kill_to (struct l_timeout *timeout,void *user_data) +{ +l_timeout_remove (timeout); +l_main_quit (); +} +static void signal_handler (uint32_t signo,void *user_data) {static bool terminated;
@@ -131,13 +137,38 @@ static void signal_handler(uint32_t signo, void *user_data)return ;l_info ("Terminating" ); -l_main_quit (); +mesh_cleanup (true); +l_timeout_create (1 , kill_to,NULL ,NULL ); terminated = true; }static bool parse_io (const char *optarg,enum mesh_io_type *type,void **opts) { -if (strstr (optarg,"generic" ) == optarg) { +if (strstr (optarg,"auto" ) == optarg) { +int *index =l_new (int,1 ); + + *type =MESH_IO_TYPE_AUTO ; + *opts = index; + + optarg +=strlen ("auto" ); +if (!*optarg) { + *index =MGMT_INDEX_NONE ; +return true; + } + +if (*optarg !=':' ) +return false; + + optarg++; + +if (sscanf (optarg,"hci%d" , index) ==1 ) +return true; + +if (sscanf (optarg,"%d" , index) ==1 ) +return true; + +return false; + }else if (strstr (optarg,"generic" ) == optarg) {int *index =l_new (int,1 ); *type =MESH_IO_TYPE_GENERIC ;
@@ -251,7 +282,7 @@ int main(int argc, char *argv[]) }if (!io) - io =l_strdup_printf ("generic" ); + io =l_strdup_printf ("auto" );if (!parse_io (io, &io_type, &io_opts)) {l_error ("Invalid io: %s" , io);
@@ -295,7 +326,7 @@ done:l_free (io);l_free (io_opts); -mesh_cleanup (); +mesh_cleanup (false);l_dbus_destroy (dbus);l_main_exit ();
mesh/mesh.c +5 -1
@@ -324,11 +324,15 @@ static void free_pending_join_call(bool failed) join_pending =NULL ; } -void mesh_cleanup (void ) +void mesh_cleanup (bool signaled) {struct l_dbus_message *reply;mesh_io_destroy (mesh.io); + mesh.io =NULL ; + +if (signaled) +return ;if (join_pending) {
mesh/mesh.h +1 -1
@@ -28,7 +28,7 @@ typedef void (*prov_rx_cb_t)(void *user_data, const uint8_t *data,bool mesh_init (const char *config_dir,const char *mesh_conf_fname,enum mesh_io_type type,void *opts,mesh_ready_func_t cb,void *user_data); -void mesh_cleanup (void ); +void mesh_cleanup (bool signaled);bool mesh_dbus_init (struct l_dbus *dbus);const char *mesh_status_str (uint8_t err);
Signature · 1 line
2.35.1
PATCH 6/7 mesh: Add new MGMT based IO transport
In reply to Brian GixAdds required new modules to support kernel based MGMT tx/rx
--- Makefile.mesh | 9 ++++----- mesh/mesh-io-generic.h | 1 - mesh/mesh-io-mgmt.c | 2 +- mesh/mesh-io-mgmt.h | 11 +++++++++++ mesh/mesh-io-unit.c | 2 +- mesh/mesh-io.c | 1 + 6 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 mesh/mesh-io-mgmt.h
Makefile.mesh +4 -5
@@ -13,12 +13,11 @@ endif mesh_sources = mesh/mesh.h mesh/mesh.c \ mesh/net-keys.h mesh/net-keys.c \ mesh/mesh-io.h mesh/mesh-io.c \ - mesh/mesh-mgmt.c mesh/mesh-mgmt.h \ + mesh/mesh-mgmt.h mesh/mesh-mgmt.c \ mesh/error.h mesh/mesh-io-api.h \ - mesh/mesh-io-generic.h \ - mesh/mesh-io-generic.c \ - mesh/mesh-io-unit.h \ - mesh/mesh-io-unit.c \ + mesh/mesh-io-unit.h mesh/mesh-io-unit.c \ + mesh/mesh-io-mgmt.h mesh/mesh-io-mgmt.c \ + mesh/mesh-io-generic.h mesh/mesh-io-generic.c \ mesh/net.h mesh/net.c \ mesh/crypto.h mesh/crypto.c \ mesh/friend.h mesh/friend.c \
mesh/mesh-io-generic.h +0 -1
@@ -9,4 +9,3 @@*/ extern const struct mesh_io_api mesh_io_generic; -extern const struct mesh_io_api mesh_io_mgmt;
mesh/mesh-io-mgmt.c +1 -1
@@ -29,7 +29,7 @@#include "mesh/mesh-mgmt.h" #include "mesh/mesh-io.h" #include "mesh/mesh-io-api.h" -#include "mesh/mesh-io-generic.h" +#include "mesh/mesh-io-mgmt.h" struct mesh_io_private {struct mesh_io *io;
mesh/mesh-io-mgmt.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2018 Intel Corporation. All rights reserved. +* +* +*/ + +extern const struct mesh_io_api mesh_io_mgmt;
mesh/mesh-io-unit.c +1 -1
@@ -25,7 +25,7 @@#include "mesh/dbus.h" #include "mesh/mesh-io.h" #include "mesh/mesh-io-api.h" -#include "mesh/mesh-io-generic.h" +#include "mesh/mesh-io-unit.h" struct mesh_io_private {struct mesh_io *io;
mesh/mesh-io.c +1 -0
@@ -24,6 +24,7 @@#include "mesh/mesh-io-api.h" /* List of Mesh-IO Type headers */ +#include "mesh/mesh-io-mgmt.h" #include "mesh/mesh-io-generic.h" #include "mesh/mesh-io-unit.h"
Signature · 1 line
2.35.1
PATCH 7/7 mesh: Make Provisioning requests more IO compatible
In reply to Brian GixRequests longer (half second) periods between discrete PB-ADV transmissions. This prevents the controller from being overwhelmed by PB-ADV packets when daemon is also an active mesh network member.
--- mesh/pb-adv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
mesh/pb-adv.c +6 -3
@@ -23,6 +23,8 @@#include "mesh/provision.h" #include "mesh/pb-adv.h" +#include "mesh/util.h" +struct pb_adv_session {mesh_prov_open_func_t open_cb;
@@ -158,7 +160,7 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data,l_debug ("max_seg: %2.2x" , max_seg);l_debug ("size: %2.2x, CRC: %2.2x" , size, buf[9 ]); -pb_adv_send (session,MESH_IO_TX_COUNT_UNLIMITED ,200 , +pb_adv_send (session,MESH_IO_TX_COUNT_UNLIMITED ,500 , buf, init_size +10 ); consumed = init_size;
@@ -174,7 +176,7 @@ static void send_adv_segs(struct pb_adv_session *session, const uint8_t *data, buf[6 ] = (i <<2 ) |0x02 ;memcpy (buf +7 , data + consumed, seg_size); -pb_adv_send (session,MESH_IO_TX_COUNT_UNLIMITED ,200 , +pb_adv_send (session,MESH_IO_TX_COUNT_UNLIMITED ,500 , buf, seg_size +7 ); consumed += seg_size;
@@ -270,7 +272,8 @@ static void send_ack(struct pb_adv_session *session, uint8_t trans_num) ack.trans_num = trans_num; ack.opcode =PB_ADV_ACK ; -pb_adv_send (session,1 ,100 , &ack,sizeof (ack)); +pb_adv_send (session,MESH_IO_TX_COUNT_UNLIMITED ,500 , + &ack,sizeof (ack)); }static void send_close_ind (struct pb_adv_session *session,uint8_t reason)
Signature · 1 line
2.35.1