summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaman <mahmoudi.saman1@gmail.com>2020-09-19 08:07:38 +0430
committerSaman Mahmoodi <mahmoudi.saman1@gmail.com>2020-10-06 05:12:22 +0000
commit7a2bf13a66a868157722a06bcf259f94ed6441b5 (patch)
tree3f1b04c42610de5b93d1900f95913f83f7130d96
parent8ba3e0d2ffe62c2c94844d8b536c1d49e12e35dd (diff)
Adding pairing request with authentication as "RequestPinCode"
Adding outgoing pairing request with another BT device when we call pair verb. "RequestPinCode" is handled as xml into bluetooth-agent.c to confirm a pincode and send it to BT device when we call pair request from AGL device to other device. Bug-AGL: SPEC-3610 Signed-off-by: saman <mahmoudi.saman1@gmail.com> Change-Id: I4fa8c9ab5d3bbf323cee7645f217bb1056d93b65
-rw-r--r--README.md2
-rw-r--r--binding/bluetooth-agent.c23
-rw-r--r--binding/bluetooth-api.c26
-rw-r--r--binding/bluetooth-common.h4
-rw-r--r--binding/bluetooth-conf.c46
5 files changed, 98 insertions, 3 deletions
diff --git a/README.md b/README.md
index afb0bdc..5abf125 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Bluetooth service uses the respective BlueZ package to connect to bluetooth devi
| cancel_pairing | cancel an outgoing pair request | |
| confirm_pairing | confirm incoming/outgoing bluetooth pairing pincode | *Request:* {"pincode": 31415} |
| remove_device | remove already paired device | *Request:* {"device": "dev_88_0F_10_96_D3_20"} |
-
+| set_pincode | set pincode as string into database for outgoing pairing request | *Request:* {"pincode": "4321"} |
### managed_objects verb
diff --git a/binding/bluetooth-agent.c b/binding/bluetooth-agent.c
index a942baa..3783b3f 100644
--- a/binding/bluetooth-agent.c
+++ b/binding/bluetooth-agent.c
@@ -41,6 +41,10 @@
static const gchar introspection_xml[] =
"<node>"
" <interface name='org.bluez.Agent1'>"
+" <method name='RequestPinCode'>"
+" <arg name='device' direction='in' type='o'/>"
+" <arg name='pincode' direction='out' type='s'/>"
+" </method>"
" <method name='RequestConfirmation'>"
" <arg name='device' direction='in' type='o'/>"
" <arg name='passkey' direction='in' type='u'/>"
@@ -69,7 +73,7 @@ static void handle_method_call(
GError *error = NULL;
json_object *jev = NULL;
const gchar *path = NULL;
-
+ char *device = NULL;
/* AFB_INFO("sender=%s", sender_name);
AFB_INFO("object_path=%s", object_path);
AFB_INFO("interface=%s", interface_name);
@@ -114,6 +118,23 @@ static void handle_method_call(
afb_event_push(ns->agent_event, jev);
return;
+
+ } else if (!g_strcmp0(method_name, "RequestPinCode")) {
+
+ g_variant_get(parameters, "(o)", &device);
+
+ call_work_lock(ns);
+ cw = call_work_lookup_unlocked(ns, BLUEZ_AT_DEVICE, device, "pair_device");
+
+ if (!cw)
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "No connection pending");
+ else
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", cw->agent_data.fixed_pincode));
+
+ call_work_unlock(ns);
+
+ return;
+
} else if (!g_strcmp0(method_name, "AuthorizeService")) {
/* g_variant_get(parameters, "(os)", &path, &service);
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c
index 876f546..85bd672 100644
--- a/binding/bluetooth-api.c
+++ b/binding/bluetooth-api.c
@@ -1200,6 +1200,8 @@ static void bluetooth_pair_device(afb_req_t request)
cw->request = request;
afb_req_addref(request);
+ cw->agent_data.fixed_pincode = get_pincode(afb_req_get_api(request));
+
cw->cpw = bluez_call_async(ns, BLUEZ_AT_DEVICE, device, "Pair", NULL, &error,
pair_service_callback, cw);
@@ -1392,6 +1394,24 @@ out_success:
afb_req_success(request, NULL, "Bluetooth - AVRCP controls");
}
+static void bluetooth_pincode(afb_req_t request)
+{
+ char *error = NULL;
+ const char *pincode;
+ int rc;
+
+ pincode = afb_req_value(request, "pincode");
+ rc = set_pincode(afb_req_get_api(request), pincode, &error);
+
+ if (rc) {
+ afb_req_fail(request, "failed", error);
+ return;
+ }
+
+ afb_req_success(request, NULL, "Bluetooth - pincode");
+ return;
+}
+
static const afb_verb_t bluetooth_verbs[] = {
{
.verb = "subscribe",
@@ -1453,7 +1473,11 @@ static const afb_verb_t bluetooth_verbs[] = {
.session = AFB_SESSION_NONE,
.callback = bluetooth_avrcp_controls,
.info = "AVRCP controls"
- },
+ }, {
+ .verb = "set_pincode",
+ .session = AFB_SESSION_NONE,
+ .callback = bluetooth_pincode,
+ .info = "Set pincode for outgoing pairing"},
{ } /* marker for end of the array */
};
diff --git a/binding/bluetooth-common.h b/binding/bluetooth-common.h
index 70975a5..616e322 100644
--- a/binding/bluetooth-common.h
+++ b/binding/bluetooth-common.h
@@ -78,6 +78,7 @@ struct init_data {
struct agent_data {
int pin_code;
+ gchar *fixed_pincode;
gchar *device_path;
};
@@ -105,6 +106,9 @@ void bluetooth_unregister_agent(struct bluetooth_state *ns);
gchar *get_default_adapter(afb_api_t api);
int set_default_adapter(afb_api_t api, const char *adapter);
+int set_pincode(afb_api_t api, const char *pincode, char **error);
+gchar *get_pincode(afb_api_t api);
+
/* utility methods in bluetooth-util.c */
extern gboolean auto_lowercase_keys;
diff --git a/binding/bluetooth-conf.c b/binding/bluetooth-conf.c
index ff888d6..b4dea34 100644
--- a/binding/bluetooth-conf.c
+++ b/binding/bluetooth-conf.c
@@ -77,3 +77,49 @@ int set_default_adapter(afb_api_t api, const char *adapter)
out:
return ret;
}
+
+gchar *get_pincode(afb_api_t api)
+{
+ json_object *response, *query, *val;
+ gchar *pincode = NULL;
+
+ query = json_object_new_object();
+ json_object_object_add(query, "key", json_object_new_string("pincode"));
+
+ afb_api_call_sync(api, "persistence", "read", query, &response, NULL, NULL);
+
+ if (json_object_object_get_ex(response, "value", &val))
+ pincode = g_strdup(json_object_get_string(val));
+ else
+ pincode = "1234";
+ json_object_put(response);
+
+ return pincode;
+}
+
+int set_pincode(afb_api_t api, const char *pincode, char **error)
+{
+ json_object *response, *query;
+ int ret;
+ gchar *endptr = NULL;
+ query = json_object_new_object();
+ if (strlen(pincode) > 8 || strlen(pincode) < 4)
+ {
+ *error = "length of pincode must be between 4 and 8";
+ return -1;
+ }
+
+ g_ascii_strtoll(pincode, &endptr, 10);
+ if (*endptr)
+ {
+ *error = "pincode must be as digits";
+ return -1;
+ }
+ json_object_object_add(query, "key", json_object_new_string("pincode"));
+ json_object_object_add(query, "value", json_object_new_string(pincode));
+
+ ret = afb_api_call_sync(api, "persistence", "update", query, &response, NULL, NULL);
+ json_object_put(response);
+
+ return ret;
+} \ No newline at end of file