Message ID | 20201006171333.BlueZ.v6.4.Ibbcb11712b613ef95c31b41207c3ea945c830018@changeid (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [BlueZ,v6,1/6] adv_monitor: Implement RSSI Filter logic for background scanning | expand |
Hi Miao, On Tue, Oct 6, 2020 at 5:17 PM Miao-chen Chou <mcchou@chromium.org> wrote: > > From: Howard Chung <howardchung@google.com> > > - Send the MGMT_OP command to kernel upon registration of a Adv patterns > monitor. > - Call Activate() or Release() to client depending on the reply from > kernel > > the call through syslog > > Reviewed-by: Alain Michaud <alainm@chromium.org> > Reviewed-by: Miao-chen Chou <mcchou@chromium.org> > Reviewed-by: Manish Mandlik <mmandlik@chromium.org> > --- > > (no changes since v1) > > src/adv_monitor.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 66 insertions(+), 1 deletion(-) > > diff --git a/src/adv_monitor.c b/src/adv_monitor.c > index fcb127cd4..582cc9a46 100644 > --- a/src/adv_monitor.c > +++ b/src/adv_monitor.c > @@ -588,11 +588,59 @@ done: > return monitor->state != MONITOR_STATE_FAILED; > } > > +/* Handles the callback of Add Adv Patterns Monitor command */ > +static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length, > + const void *param, void *user_data) > +{ > + const struct mgmt_rp_add_adv_patterns_monitor *rp = param; > + struct adv_monitor *monitor = user_data; > + uint16_t adapter_id = monitor->app->manager->adapter_id; > + > + if (status != MGMT_STATUS_SUCCESS || !param) { > + btd_error(adapter_id, "Failed to Add Adv Patterns Monitor " > + "with status 0x%02x", status); > + monitor_release(monitor, NULL); > + return; > + } > + > + if (length < sizeof(*rp)) { > + btd_error(adapter_id, "Wrong size of Add Adv Patterns Monitor " > + "response"); > + monitor_release(monitor, NULL); > + return; > + } > + > + monitor->state = MONITOR_STATE_HONORED; I would reword this state to ACTIVE instead of HONORED as it seems more consistent. > + DBG("Calling Activate() on Adv Monitor of owner %s at path %s", > + monitor->app->owner, monitor->path); > + > + g_dbus_proxy_method_call(monitor->proxy, "Activate", NULL, NULL, NULL, > + NULL); > + > + DBG("Adv Monitor with handle:0x%04x added", > + le16_to_cpu(rp->monitor_handle)); > +} > + > +static void monitor_copy_patterns(void *data, void *user_data) > +{ > + struct btd_adv_monitor_pattern *pattern = data; > + struct mgmt_cp_add_adv_monitor *cp = user_data; > + > + if (!pattern) > + return; > + > + memcpy(cp->patterns + cp->pattern_count, pattern, sizeof(*pattern)); > + cp->pattern_count++; > +} > + > /* Handles an Adv Monitor D-Bus proxy added event */ > static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) > { > struct adv_monitor *monitor; > struct adv_monitor_app *app = user_data; > + struct mgmt_cp_add_adv_monitor *cp = NULL; > + uint8_t pattern_count, cp_len; > uint16_t adapter_id = app->manager->adapter_id; > const char *path = g_dbus_proxy_get_path(proxy); > const char *iface = g_dbus_proxy_get_interface(proxy); > @@ -625,7 +673,24 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) > > queue_push_tail(app->monitors, monitor); > > + pattern_count = queue_length(monitor->patterns); > + cp_len = sizeof(struct mgmt_cp_add_adv_monitor) + > + pattern_count * sizeof(struct mgmt_adv_pattern); > + > + cp = malloc0(cp_len); > + queue_foreach(monitor->patterns, monitor_copy_patterns, cp); > + > + if (!mgmt_send(app->manager->mgmt, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, > + adapter_id, cp_len, cp, add_adv_patterns_monitor_cb, > + monitor, NULL)) { > + error("Unable to send Add Adv Patterns Monitor command"); > + goto done; > + } > + > DBG("Adv Monitor allocated for the object at path %s", path); > + > +done: > + free(cp); > } > > /* Handles the removal of an Adv Monitor D-Bus proxy */ > @@ -1036,7 +1101,7 @@ static void adv_match_per_monitor(void *data, void *user_data) > struct adv_monitor *monitor = data; > struct adv_content_filter_info *info = user_data; > > - if (!monitor && monitor->state != MONITOR_STATE_HONORED) > + if (!monitor || monitor->state != MONITOR_STATE_HONORED) > return; > > /* Reset the intermediate matched status */ > -- > 2.26.2 >
Hi Luiz, On Tue, Oct 6, 2020 at 11:26 PM Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote: > > Hi Miao, > > On Tue, Oct 6, 2020 at 5:17 PM Miao-chen Chou <mcchou@chromium.org> wrote: > > > > From: Howard Chung <howardchung@google.com> > > > > - Send the MGMT_OP command to kernel upon registration of a Adv patterns > > monitor. > > - Call Activate() or Release() to client depending on the reply from > > kernel > > > > the call through syslog > > > > Reviewed-by: Alain Michaud <alainm@chromium.org> > > Reviewed-by: Miao-chen Chou <mcchou@chromium.org> > > Reviewed-by: Manish Mandlik <mmandlik@chromium.org> > > --- > > > > (no changes since v1) > > > > src/adv_monitor.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++- > > 1 file changed, 66 insertions(+), 1 deletion(-) > > > > diff --git a/src/adv_monitor.c b/src/adv_monitor.c > > index fcb127cd4..582cc9a46 100644 > > --- a/src/adv_monitor.c > > +++ b/src/adv_monitor.c > > @@ -588,11 +588,59 @@ done: > > return monitor->state != MONITOR_STATE_FAILED; > > } > > > > +/* Handles the callback of Add Adv Patterns Monitor command */ > > +static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length, > > + const void *param, void *user_data) > > +{ > > + const struct mgmt_rp_add_adv_patterns_monitor *rp = param; > > + struct adv_monitor *monitor = user_data; > > + uint16_t adapter_id = monitor->app->manager->adapter_id; > > + > > + if (status != MGMT_STATUS_SUCCESS || !param) { > > + btd_error(adapter_id, "Failed to Add Adv Patterns Monitor " > > + "with status 0x%02x", status); > > + monitor_release(monitor, NULL); > > + return; > > + } > > + > > + if (length < sizeof(*rp)) { > > + btd_error(adapter_id, "Wrong size of Add Adv Patterns Monitor " > > + "response"); > > + monitor_release(monitor, NULL); > > + return; > > + } > > + > > + monitor->state = MONITOR_STATE_HONORED; > > I would reword this state to ACTIVE instead of HONORED as it seems > more consistent. > Addressed in my local v7. I will send this after we settle down the discussion on the other thread. > > + DBG("Calling Activate() on Adv Monitor of owner %s at path %s", > > + monitor->app->owner, monitor->path); > > + > > + g_dbus_proxy_method_call(monitor->proxy, "Activate", NULL, NULL, NULL, > > + NULL); > > + > > + DBG("Adv Monitor with handle:0x%04x added", > > + le16_to_cpu(rp->monitor_handle)); > > +} > > + > > +static void monitor_copy_patterns(void *data, void *user_data) > > +{ > > + struct btd_adv_monitor_pattern *pattern = data; > > + struct mgmt_cp_add_adv_monitor *cp = user_data; > > + > > + if (!pattern) > > + return; > > + > > + memcpy(cp->patterns + cp->pattern_count, pattern, sizeof(*pattern)); > > + cp->pattern_count++; > > +} > > + > > /* Handles an Adv Monitor D-Bus proxy added event */ > > static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) > > { > > struct adv_monitor *monitor; > > struct adv_monitor_app *app = user_data; > > + struct mgmt_cp_add_adv_monitor *cp = NULL; > > + uint8_t pattern_count, cp_len; > > uint16_t adapter_id = app->manager->adapter_id; > > const char *path = g_dbus_proxy_get_path(proxy); > > const char *iface = g_dbus_proxy_get_interface(proxy); > > @@ -625,7 +673,24 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) > > > > queue_push_tail(app->monitors, monitor); > > > > + pattern_count = queue_length(monitor->patterns); > > + cp_len = sizeof(struct mgmt_cp_add_adv_monitor) + > > + pattern_count * sizeof(struct mgmt_adv_pattern); > > + > > + cp = malloc0(cp_len); > > + queue_foreach(monitor->patterns, monitor_copy_patterns, cp); > > + > > + if (!mgmt_send(app->manager->mgmt, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, > > + adapter_id, cp_len, cp, add_adv_patterns_monitor_cb, > > + monitor, NULL)) { > > + error("Unable to send Add Adv Patterns Monitor command"); > > + goto done; > > + } > > + > > DBG("Adv Monitor allocated for the object at path %s", path); > > + > > +done: > > + free(cp); > > } > > > > /* Handles the removal of an Adv Monitor D-Bus proxy */ > > @@ -1036,7 +1101,7 @@ static void adv_match_per_monitor(void *data, void *user_data) > > struct adv_monitor *monitor = data; > > struct adv_content_filter_info *info = user_data; > > > > - if (!monitor && monitor->state != MONITOR_STATE_HONORED) > > + if (!monitor || monitor->state != MONITOR_STATE_HONORED) > > return; > > > > /* Reset the intermediate matched status */ > > -- > > 2.26.2 > > > > > -- > Luiz Augusto von Dentz Regards, Miao
diff --git a/src/adv_monitor.c b/src/adv_monitor.c index fcb127cd4..582cc9a46 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -588,11 +588,59 @@ done: return monitor->state != MONITOR_STATE_FAILED; } +/* Handles the callback of Add Adv Patterns Monitor command */ +static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + const struct mgmt_rp_add_adv_patterns_monitor *rp = param; + struct adv_monitor *monitor = user_data; + uint16_t adapter_id = monitor->app->manager->adapter_id; + + if (status != MGMT_STATUS_SUCCESS || !param) { + btd_error(adapter_id, "Failed to Add Adv Patterns Monitor " + "with status 0x%02x", status); + monitor_release(monitor, NULL); + return; + } + + if (length < sizeof(*rp)) { + btd_error(adapter_id, "Wrong size of Add Adv Patterns Monitor " + "response"); + monitor_release(monitor, NULL); + return; + } + + monitor->state = MONITOR_STATE_HONORED; + + DBG("Calling Activate() on Adv Monitor of owner %s at path %s", + monitor->app->owner, monitor->path); + + g_dbus_proxy_method_call(monitor->proxy, "Activate", NULL, NULL, NULL, + NULL); + + DBG("Adv Monitor with handle:0x%04x added", + le16_to_cpu(rp->monitor_handle)); +} + +static void monitor_copy_patterns(void *data, void *user_data) +{ + struct btd_adv_monitor_pattern *pattern = data; + struct mgmt_cp_add_adv_monitor *cp = user_data; + + if (!pattern) + return; + + memcpy(cp->patterns + cp->pattern_count, pattern, sizeof(*pattern)); + cp->pattern_count++; +} + /* Handles an Adv Monitor D-Bus proxy added event */ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) { struct adv_monitor *monitor; struct adv_monitor_app *app = user_data; + struct mgmt_cp_add_adv_monitor *cp = NULL; + uint8_t pattern_count, cp_len; uint16_t adapter_id = app->manager->adapter_id; const char *path = g_dbus_proxy_get_path(proxy); const char *iface = g_dbus_proxy_get_interface(proxy); @@ -625,7 +673,24 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) queue_push_tail(app->monitors, monitor); + pattern_count = queue_length(monitor->patterns); + cp_len = sizeof(struct mgmt_cp_add_adv_monitor) + + pattern_count * sizeof(struct mgmt_adv_pattern); + + cp = malloc0(cp_len); + queue_foreach(monitor->patterns, monitor_copy_patterns, cp); + + if (!mgmt_send(app->manager->mgmt, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, + adapter_id, cp_len, cp, add_adv_patterns_monitor_cb, + monitor, NULL)) { + error("Unable to send Add Adv Patterns Monitor command"); + goto done; + } + DBG("Adv Monitor allocated for the object at path %s", path); + +done: + free(cp); } /* Handles the removal of an Adv Monitor D-Bus proxy */ @@ -1036,7 +1101,7 @@ static void adv_match_per_monitor(void *data, void *user_data) struct adv_monitor *monitor = data; struct adv_content_filter_info *info = user_data; - if (!monitor && monitor->state != MONITOR_STATE_HONORED) + if (!monitor || monitor->state != MONITOR_STATE_HONORED) return; /* Reset the intermediate matched status */