diff options
| author | Johan Hedberg <johan.hedberg@nokia.com> | 2008-06-09 04:37:29 +0000 | 
|---|---|---|
| committer | Johan Hedberg <johan.hedberg@nokia.com> | 2008-06-09 04:37:29 +0000 | 
| commit | 8eae4fc054a6f522d9cbc24dbe824838056f0dcf (patch) | |
| tree | 83c35c3a15e9c20ce944add18fbc7fc8d1f6ece1 | |
| parent | 4aa07a5ae2035b9ad13c63c3cb85192c85d85252 (diff) | |
Add support for Simple Pairing User Notification event
| -rw-r--r-- | hcid/adapter.c | 3 | ||||
| -rw-r--r-- | hcid/adapter.h | 1 | ||||
| -rw-r--r-- | hcid/agent.c | 26 | ||||
| -rw-r--r-- | hcid/agent.h | 3 | ||||
| -rw-r--r-- | hcid/dbus-hci.c | 34 | ||||
| -rw-r--r-- | hcid/dbus-hci.h | 1 | ||||
| -rw-r--r-- | hcid/security.c | 12 | 
7 files changed, 80 insertions, 0 deletions
| diff --git a/hcid/adapter.c b/hcid/adapter.c index dead8c4d..9662559b 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -2629,6 +2629,9 @@ static void cancel_auth_request(int dd, auth_type_t type, bdaddr_t *bda)  		hci_send_cmd(dd, OGF_LINK_CTL, OCF_USER_PASSKEY_NEG_REPLY,  				6, bda);  		break; +	case AUTH_TYPE_NOTIFY: +		/* User Notify doesn't require any reply */ +		break;  	}  } diff --git a/hcid/adapter.h b/hcid/adapter.h index ec2c3f81..844a66f4 100644 --- a/hcid/adapter.h +++ b/hcid/adapter.h @@ -50,6 +50,7 @@ typedef enum {  	AUTH_TYPE_PINCODE,  	AUTH_TYPE_PASSKEY,  	AUTH_TYPE_CONFIRM, +	AUTH_TYPE_NOTIFY,  } auth_type_t;  struct remote_dev_info { diff --git a/hcid/agent.c b/hcid/agent.c index f793a003..da3fb319 100644 --- a/hcid/agent.c +++ b/hcid/agent.c @@ -680,6 +680,32 @@ failed:  	return -1;  } +int agent_display_passkey(struct agent *agent, struct device *device, +				uint32_t passkey) +{ +	DBusMessage *message; + +	message = dbus_message_new_method_call(agent->name, agent->path, +				"org.bluez.Agent", "DisplayPasskey"); +	if (!message) { +		error("Couldn't allocate D-Bus message"); +		return -1; +	} + +	dbus_message_append_args(message, +				DBUS_TYPE_OBJECT_PATH, &device->path, +				DBUS_TYPE_UINT32, &passkey, +				DBUS_TYPE_INVALID); + +	if (!g_dbus_send_message(connection, message)) { +		error("D-Bus send failed"); +		dbus_message_unref(message); +		return -1; +	} + +	return 0; +} +  uint8_t agent_get_io_capability(struct agent *agent)  {  	return agent->capability; diff --git a/hcid/agent.h b/hcid/agent.h index 552c91f2..37ee5edd 100644 --- a/hcid/agent.h +++ b/hcid/agent.h @@ -57,6 +57,9 @@ int agent_request_confirmation(struct agent *agent, struct device *device,  				uint32_t passkey, agent_cb cb,  				void *user_data); +int agent_display_passkey(struct agent *agent, struct device *device, +				uint32_t passkey); +  int agent_cancel(struct agent *agent);  uint8_t agent_get_io_capability(struct agent *agent); diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index b2df0e69..6b9d06bd 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -1174,6 +1174,40 @@ int hcid_dbus_user_passkey(bdaddr_t *sba, bdaddr_t *dba)  	return 0;  } +int hcid_dbus_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey) +{ +	struct adapter *adapter; +	struct device *device; +	struct agent *agent; +	char addr[18]; + +	adapter = adapter_find(sba); +	if (!adapter) { +		error("No matching adapter found"); +		return -1; +	} + +	ba2str(dba, addr); + +	device = adapter_get_device(connection, adapter, addr); +	if (device && device->agent) +		agent = device->agent; +	else +		agent = adapter->agent; + +	if (!agent) { +		error("No agent available for user confirm request"); +		return -1; +	} + +	if (agent_display_passkey(agent, device, passkey) < 0) { +		error("Displaying passkey failed"); +		return -1; +	} + +	return 0; +} +  void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer,  					uint8_t status)  { diff --git a/hcid/dbus-hci.h b/hcid/dbus-hci.h index 509bcb7c..d92a4f30 100644 --- a/hcid/dbus-hci.h +++ b/hcid/dbus-hci.h @@ -50,6 +50,7 @@ int hcid_dbus_get_io_cap(bdaddr_t *local, bdaddr_t *remote, uint8_t *cap,  				uint8_t *auth);  int hcid_dbus_user_confirm(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey);  int hcid_dbus_user_passkey(bdaddr_t *sba, bdaddr_t *dba); +int hcid_dbus_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey);  int unregister_adapter_path(const char *path); diff --git a/hcid/security.c b/hcid/security.c index 17cb2f56..9472930b 100644 --- a/hcid/security.c +++ b/hcid/security.c @@ -383,6 +383,14 @@ static void user_passkey_request(int dev, bdaddr_t *sba, void *ptr)  						AUTH_TYPE_PASSKEY);  } +static void user_passkey_notify(int dev, bdaddr_t *sba, void *ptr) +{ +	evt_user_passkey_notify *req = ptr; + +	if (hcid_dbus_user_notify(sba, &req->bdaddr, btohl(req->passkey)) == 0) +		hcid_dbus_new_auth_request(sba, &req->bdaddr, AUTH_TYPE_NOTIFY); +} +  static void remote_oob_data_request(int dev, bdaddr_t *sba, void *ptr)  {  	hci_send_cmd(dev, OGF_LINK_CTL, OCF_REMOTE_OOB_DATA_NEG_REPLY, 6, ptr); @@ -887,6 +895,10 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer  		user_passkey_request(dev, &di->bdaddr, ptr);  		break; +	case EVT_USER_PASSKEY_NOTIFY: +		user_passkey_notify(dev, &di->bdaddr, ptr); +		break; +  	case EVT_REMOTE_OOB_DATA_REQUEST:  		remote_oob_data_request(dev, &di->bdaddr, ptr);  		break; | 
