summaryrefslogtreecommitdiff
path: root/gsupplicant
diff options
context:
space:
mode:
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>2014-09-03 06:56:51 (GMT)
committerPatrik Flykt <patrik.flykt@linux.intel.com>2014-09-04 11:25:27 (GMT)
commit4fcc8997598bcf38ffbe2ca8d0bd4d43cbace6a7 (patch)
tree05c3ba8018cada69ef4d79eaeedfb2e05ce53eda /gsupplicant
parente0f9d5425fd397edd46ec2a4937ded1e98ace23d (diff)
downloadconnman-4fcc8997598bcf38ffbe2ca8d0bd4d43cbace6a7.tar.gz
connman-4fcc8997598bcf38ffbe2ca8d0bd4d43cbace6a7.tar.xz
gsupplicant: Add helpers for adding/removing P2P services
These are helper functions used by the wifi plugin when registering or unregistering Peer services.
Diffstat (limited to 'gsupplicant')
-rw-r--r--gsupplicant/gsupplicant.h19
-rw-r--r--gsupplicant/supplicant.c126
2 files changed, 145 insertions, 0 deletions
diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 5ad88b0..9a619b8 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -176,6 +176,17 @@ struct _GSupplicantPeerParams {
typedef struct _GSupplicantPeerParams GSupplicantPeerParams;
+struct _GSupplicantP2PServiceParams {
+ int version;
+ char *service;
+ unsigned char *query;
+ int query_length;
+ unsigned char *response;
+ int response_length;
+};
+
+typedef struct _GSupplicantP2PServiceParams GSupplicantP2PServiceParams;
+
/* global API */
typedef void (*GSupplicantCountryCallback) (int result,
const char *alpha2,
@@ -229,6 +240,14 @@ int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
GSupplicantPeerParams *peer_params);
+int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
+ GSupplicantInterfaceCallback callback,
+ GSupplicantP2PServiceParams *p2p_service_params,
+ void *user_data);
+
+int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
+ GSupplicantP2PServiceParams *p2p_service_params);
+
int g_supplicant_interface_connect(GSupplicantInterface *interface,
GSupplicantSSID *ssid,
GSupplicantInterfaceCallback callback,
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 9796fe8..7c0f43a 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -4860,6 +4860,132 @@ int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
return -EINPROGRESS;
}
+struct p2p_service_data {
+ bool registration;
+ GSupplicantInterface *interface;
+ GSupplicantP2PServiceParams *service;
+ GSupplicantInterfaceCallback callback;
+ void *user_data;
+};
+
+static void interface_p2p_service_result(const char *error,
+ DBusMessageIter *iter, void *user_data)
+{
+ struct p2p_service_data *data = user_data;
+ int result = 0;
+
+ SUPPLICANT_DBG("%s result - %s", data->registration ?
+ "Registration" : "Deletion",
+ error ? error : "Success");
+ if (error)
+ result = -EINVAL;
+
+ if (data->callback)
+ data->callback(result, data->interface, data->user_data);
+
+ g_free(data->service->query);
+ g_free(data->service->response);
+ g_free(data->service->service);
+ g_free(data->service);
+ dbus_free(data);
+}
+
+static void interface_p2p_service_params(DBusMessageIter *iter,
+ void *user_data)
+{
+ struct p2p_service_data *data = user_data;
+ GSupplicantP2PServiceParams *service;
+ DBusMessageIter dict;
+ const char *type;
+
+ SUPPLICANT_DBG("");
+
+ service = data->service;
+
+ supplicant_dbus_dict_open(iter, &dict);
+
+ if (service->query && service->response) {
+ type = "bonjour";
+ supplicant_dbus_dict_append_basic(&dict, "service_type",
+ DBUS_TYPE_STRING, &type);
+ supplicant_dbus_dict_append_fixed_array(&dict, "query",
+ DBUS_TYPE_BYTE, &service->query,
+ service->query_length);
+ supplicant_dbus_dict_append_fixed_array(&dict, "response",
+ DBUS_TYPE_BYTE, &service->response,
+ service->response_length);
+ } else if (service->version && service->service) {
+ type = "upnp";
+ supplicant_dbus_dict_append_basic(&dict, "service_type",
+ DBUS_TYPE_STRING, &type);
+ supplicant_dbus_dict_append_basic(&dict, "version",
+ DBUS_TYPE_INT32, &service->version);
+ supplicant_dbus_dict_append_basic(&dict, "service",
+ DBUS_TYPE_STRING, &service->service);
+ }
+
+ supplicant_dbus_dict_close(iter, &dict);
+}
+
+int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
+ GSupplicantInterfaceCallback callback,
+ GSupplicantP2PServiceParams *p2p_service_params,
+ void *user_data)
+{
+ struct p2p_service_data *data;
+ int ret;
+
+ SUPPLICANT_DBG("");
+
+ if (!interface->p2p_support)
+ return -ENOTSUP;
+
+ data = dbus_malloc0(sizeof(*data));
+ data->registration = true;
+ data->interface = interface;
+ data->service = p2p_service_params;
+ data->callback = callback;
+ data->user_data = user_data;
+
+ ret = supplicant_dbus_method_call(interface->path,
+ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
+ interface_p2p_service_params, interface_p2p_service_result,
+ data, interface);
+ if (ret < 0) {
+ dbus_free(data);
+ return ret;
+ }
+
+ return -EINPROGRESS;
+}
+
+int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
+ GSupplicantP2PServiceParams *p2p_service_params)
+{
+ struct p2p_service_data *data;
+ int ret;
+
+ SUPPLICANT_DBG("");
+
+ if (!interface->p2p_support)
+ return -ENOTSUP;
+
+ data = dbus_malloc0(sizeof(*data));
+ data->interface = interface;
+ data->service = p2p_service_params;
+
+ ret = supplicant_dbus_method_call(interface->path,
+ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
+ interface_p2p_service_params, interface_p2p_service_result,
+ data, interface);
+ if (ret < 0) {
+ dbus_free(data);
+ return ret;
+ }
+
+ return -EINPROGRESS;
+}
+
static const char *g_supplicant_rule0 = "type=signal,"
"path=" DBUS_PATH_DBUS ","
"sender=" DBUS_SERVICE_DBUS ","