summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2005-09-15 08:07:53 +0000
committerMarcel Holtmann <marcel@holtmann.org>2005-09-15 08:07:53 +0000
commit0c9289ad794b5fa0d3117824f61a585d820e4f42 (patch)
tree0cfecc317a7ca908b42cc822ed7d953ad9d7feba
parent12bc903cff57bed548080354159c0841cc20650b (diff)
Extend reply_handler_function() function
-rw-r--r--hcid/dbus.c64
1 files changed, 37 insertions, 27 deletions
diff --git a/hcid/dbus.c b/hcid/dbus.c
index 2f66eae9..df520316 100644
--- a/hcid/dbus.c
+++ b/hcid/dbus.c
@@ -68,39 +68,49 @@ static void reply_handler_function(DBusPendingCall *call, void *user_data)
pin_code_reply_cp pr;
DBusMessage *message;
DBusMessageIter iter;
- int type;
+ int arg_type;
+ int msg_type;
size_t len;
char *pin;
-
+ const char *error_msg;
+
message = dbus_pending_call_steal_reply(call);
-
- if (dbus_message_is_error(message, WRONG_ARGS_ERROR))
- goto error;
-
- dbus_message_iter_init(message, &iter);
-
- type = dbus_message_iter_get_arg_type(&iter);
- if (type != DBUS_TYPE_STRING)
- goto error;
-
- dbus_message_iter_get_basic(&iter, &pin);
- len = strlen(pin);
-
- memset(&pr, 0, sizeof(pr));
- bacpy(&pr.bdaddr, &req->bda);
- memcpy(pr.pin_code, pin, len);
- pr.pin_len = len;
- hci_send_cmd(req->dev, OGF_LINK_CTL, OCF_PIN_CODE_REPLY,
+
+ if (message) {
+ msg_type = dbus_message_get_type(message);
+ dbus_message_iter_init(message, &iter);
+
+ if (msg_type == DBUS_MESSAGE_TYPE_ERROR) {
+ dbus_message_iter_get_basic(&iter, &error_msg);
+
+ /* handling WRONG_ARGS_ERROR, DBUS_ERROR_NO_REPLY, DBUS_ERROR_SERVICE_UNKNOWN */
+ syslog(LOG_ERR, "%s: %s", dbus_message_get_error_name(message), error_msg);
+ hci_send_cmd(req->dev, OGF_LINK_CTL,
+ OCF_PIN_CODE_NEG_REPLY, 6, &req->bda);
+ } else {
+ /* check signature */
+ arg_type = dbus_message_iter_get_arg_type(&iter);
+ if (arg_type != DBUS_TYPE_STRING) {
+ syslog(LOG_ERR, "Wrong reply signature: expected PIN");
+ hci_send_cmd(req->dev, OGF_LINK_CTL,
+ OCF_PIN_CODE_NEG_REPLY, 6, &req->bda);
+ } else {
+ dbus_message_iter_get_basic(&iter, &pin);
+ len = strlen(pin);
+
+ memset(&pr, 0, sizeof(pr));
+ bacpy(&pr.bdaddr, &req->bda);
+ memcpy(pr.pin_code, pin, len);
+ pr.pin_len = len;
+ hci_send_cmd(req->dev, OGF_LINK_CTL, OCF_PIN_CODE_REPLY,
PIN_CODE_REPLY_CP_SIZE, &pr);
+ }
+ }
- dbus_message_unref(message);
- dbus_pending_call_unref(call);
-
- return;
+ dbus_message_unref(message);
+ }
-error:
- hci_send_cmd(req->dev, OGF_LINK_CTL,
- OCF_PIN_CODE_NEG_REPLY, 6, &req->bda);
+ dbus_pending_call_unref(call);
}
static void free_pin_req(void *req)