diff options
author | Nishant Chaprana <n.chaprana@samsung.com> | 2021-03-18 11:38:16 +0530 |
---|---|---|
committer | Nishant Chaprana <n.chaprana@samsung.com> | 2021-04-21 12:38:27 +0530 |
commit | 2bd325428feab81382b17b062d4e3b49ede180e4 (patch) | |
tree | cb49da0242531991d1c97abd6d0bc6ff560b7f9b /src | |
parent | 0e19853f53eaa5eb2545a25f05ea860fd39ac7d8 (diff) | |
download | connman-2bd325428feab81382b17b062d4e3b49ede180e4.tar.gz connman-2bd325428feab81382b17b062d4e3b49ede180e4.tar.bz2 connman-2bd325428feab81382b17b062d4e3b49ede180e4.zip |
Add setter/getter for handling MAC randomization policy
Change-Id: I978ab95f02d04574efc7c3455b71f72841956c36
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/connman.conf | 3 | ||||
-rwxr-xr-x | src/device.c | 91 | ||||
-rw-r--r-- | src/technology.c | 291 |
3 files changed, 385 insertions, 0 deletions
diff --git a/src/connman.conf b/src/connman.conf index adff8fa4..7e33e3ef 100644 --- a/src/connman.conf +++ b/src/connman.conf @@ -39,5 +39,8 @@ <check send_destination="net.connman" send_interface="net.connman.Technology" send_member="SetBSSID" privilege="http://tizen.org/privilege/network.set" /> <check send_destination="net.connman" send_interface="net.connman.Manager" send_member="GetInterfaces" privilege="http://tizen.org/privilege/network.get" /> <check send_destination="net.connman" send_interface="net.connman.Technology" send_member="MeshCommands" privilege="http://tizen.org/privilege/network.set" /> + <check send_destination="net.connman" send_interface="net.connman.Technology" send_member="MacPolicy" privilege="http://tizen.org/privilege/network.set" /> + <check send_destination="net.connman" send_interface="net.connman.Technology" send_member="PreassocMacPolicy" privilege="http://tizen.org/privilege/network.set" /> + <check send_destination="net.connman" send_interface="net.connman.Technology" send_member="RandomMacLifetime" privilege="http://tizen.org/privilege/network.set" /> </policy> </busconfig> diff --git a/src/device.c b/src/device.c index 801400f2..fa5a0016 100755 --- a/src/device.c +++ b/src/device.c @@ -79,6 +79,9 @@ struct connman_device { DBusMessage *pending_reply; int max_scan_ssids; bool is_5_0_ghz_supported; + unsigned int mac_policy; + unsigned int preassoc_mac_policy; + unsigned int random_mac_lifetime; #endif }; @@ -654,6 +657,11 @@ void connman_device_set_interface(struct connman_device *device, void connman_device_set_ident(struct connman_device *device, const char *ident) { +#ifdef TIZEN_EXT + if (device->ident) + return; + else +#endif g_free(device->ident); device->ident = g_strdup(ident); } @@ -1096,6 +1104,11 @@ int connman_device_set_string(struct connman_device *device, DBG("device %p key %s value %s", device, key, value); if (g_str_equal(key, "Address")) { +#ifdef TIZEN_EXT + if (device->address) + return 0; + else +#endif g_free(device->address); device->address = g_strdup(value); } else if (g_str_equal(key, "Name")) { @@ -2099,3 +2112,81 @@ void __connman_device_cleanup(void) dbus_connection_unref(connection); #endif } + +#ifdef TIZEN_EXT +void connman_device_mac_policy_notify(struct connman_device *device, + int result, unsigned int policy) +{ + device->mac_policy = policy; + __connman_technology_notify_mac_policy_by_device(device, result, policy); +} + +int connman_device_set_mac_policy(struct connman_device *device, + unsigned int policy) +{ + int err = 0; + + if (!device || !device->driver || !device->driver->set_mac_policy) + return -EOPNOTSUPP; + + device->mac_policy = policy; + err = device->driver->set_mac_policy(device, policy); + return err; +} + +unsigned int connman_device_get_mac_policy(struct connman_device *device) +{ + return device->mac_policy; +} + +void connman_device_preassoc_mac_policy_notify(struct connman_device *device, + int result, unsigned int policy) +{ + device->preassoc_mac_policy = policy; + __connman_technology_notify_preassoc_mac_policy_by_device(device, result, policy); +} + +int connman_device_set_preassoc_mac_policy(struct connman_device *device, + unsigned int policy) +{ + int err = 0; + + if (!device || !device->driver || !device->driver->set_preassoc_mac_policy) + return -EOPNOTSUPP; + + device->preassoc_mac_policy = policy; + err = device->driver->set_preassoc_mac_policy(device, policy); + return err; +} + +unsigned int connman_device_get_preassoc_mac_policy(struct connman_device *device) +{ + return device->preassoc_mac_policy; +} + +void connman_device_random_mac_lifetime_notify(struct connman_device *device, + int result, unsigned int lifetime) +{ + device->random_mac_lifetime = lifetime; + __connman_technology_notify_random_mac_lifetime_by_device(device, result, lifetime); +} + +int connman_device_set_random_mac_lifetime(struct connman_device *device, + unsigned int lifetime) +{ + int err = 0; + + if (!device || !device->driver || !device->driver->set_random_mac_lifetime) + return -EOPNOTSUPP; + + device->random_mac_lifetime = lifetime; + err = device->driver->set_random_mac_lifetime(device, lifetime); + return err; +} + +unsigned int connman_device_get_random_mac_lifetime(struct connman_device *device) +{ + return device->random_mac_lifetime; +} + +#endif diff --git a/src/technology.c b/src/technology.c index 440d7ebb..c476b3ed 100644 --- a/src/technology.c +++ b/src/technology.c @@ -100,6 +100,9 @@ struct connman_technology { bool dbus_registered; #if defined TIZEN_EXT char **enabled_devices; + unsigned int mac_policy; + unsigned int preassoc_mac_policy; + unsigned int random_mac_lifetime; #endif #if defined TIZEN_EXT_WIFI_MESH DBusMessage *mesh_dbus_msg; @@ -218,6 +221,19 @@ static void technology_save(struct connman_technology *technology) "Tethering.Passphrase", technology->tethering_passphrase); +#ifdef TIZEN_EXT + if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) { + g_key_file_set_uint64(keyfile, identifier, "MacPolicy", + technology->mac_policy); + + g_key_file_set_uint64(keyfile, identifier, "PreassocMacPolicy", + technology->preassoc_mac_policy); + + g_key_file_set_uint64(keyfile, identifier, "RandomMacLifetime", + technology->random_mac_lifetime); + } +#endif /* TIZEN_EXT */ + done: g_free(identifier); @@ -488,6 +504,34 @@ static void technology_load(struct connman_technology *technology) technology->tethering_passphrase = g_key_file_get_string(keyfile, identifier, "Tethering.Passphrase", NULL); + +#ifdef TIZEN_EXT + if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) { + unsigned int val = 0; + + val = g_key_file_get_uint64(keyfile, + identifier, "MacPolicy", NULL); + if (val <= 2) + technology->mac_policy = val; + else + technology->mac_policy = 0; + + val = g_key_file_get_uint64(keyfile, + identifier, "PreassocMacPolicy", NULL); + if (val <= 2) + technology->preassoc_mac_policy = val; + else + technology->preassoc_mac_policy = 0; + + val = g_key_file_get_uint64(keyfile, + identifier, "RandomMacLifetime", NULL); + if (val > 0) + technology->random_mac_lifetime = val; + else + technology->random_mac_lifetime = 60; + } +#endif /* TIZEN_EXT */ + done: g_free(identifier); @@ -666,6 +710,18 @@ static void append_properties(DBusMessageIter *iter, connman_dbus_dict_append_basic(&dict, "TetheringPassphrase", DBUS_TYPE_STRING, &technology->tethering_passphrase); + + connman_dbus_dict_append_basic(&dict, "MacPolicy", + DBUS_TYPE_UINT32, + &(technology->mac_policy)); + + connman_dbus_dict_append_basic(&dict, "PreassocMacPolicy", + DBUS_TYPE_UINT32, + &(technology->preassoc_mac_policy)); + + connman_dbus_dict_append_basic(&dict, "RandomMacLifetime", + DBUS_TYPE_UINT32, + &(technology->random_mac_lifetime)); #if defined TIZEN_EXT if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) connman_dbus_dict_append_dict(&dict, "Device.List", @@ -1078,6 +1134,190 @@ int set_connman_bssid(enum bssid_type mode, char *bssid, const char *ifname) return bssid_len; } + +void connman_technology_mac_policy_notify(struct connman_technology *technology, + unsigned int policy) +{ + DBG("Mac polict set to %u", policy); + + technology->mac_policy = policy; + technology_save(technology); +} + +void __connman_technology_notify_mac_policy_by_device(struct connman_device *device, + int result, unsigned int policy) +{ + struct connman_technology *technology; + enum connman_service_type type; + + type = __connman_device_get_service_type(device); + technology = technology_find(type); + + if (!technology) + return; + + connman_technology_mac_policy_notify(technology, policy); +} + +static DBusMessage *set_mac_policy(struct connman_technology *technology, + DBusMessage *msg, unsigned int policy) +{ + DBusMessage *reply = NULL; + int err = 0; + unsigned int last_policy = technology->mac_policy; + + if (technology->rfkill_driven && technology->hardblocked) { + err = -EACCES; + goto make_reply; + } + + for (GSList *list = technology->device_list; list; list = list->next) { + struct connman_device *device = list->data; + + err = connman_device_set_mac_policy(device, policy); + if (err < 0) + break; + } + +make_reply: + if (err < 0) { + if (err != -EACCES && err != -EOPNOTSUPP) { + for (GSList *list = technology->device_list; list; list = list->next) { + struct connman_device *device = list->data; + + connman_device_set_mac_policy(device, last_policy); + } + } + + reply = __connman_error_failed(msg, -err); + } else { + reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); + } + + return reply; +} + +void connman_technology_preassoc_mac_policy_notify(struct connman_technology *technology, + unsigned int policy) +{ + DBG("Preassoc mac polict set to %u", policy); + + technology->preassoc_mac_policy = policy; + technology_save(technology); +} + +void __connman_technology_notify_preassoc_mac_policy_by_device(struct connman_device *device, + int result, unsigned int policy) +{ + struct connman_technology *technology; + enum connman_service_type type; + + type = __connman_device_get_service_type(device); + technology = technology_find(type); + + if (!technology) + return; + + connman_technology_preassoc_mac_policy_notify(technology, policy); +} + +static DBusMessage *set_preassoc_mac_policy(struct connman_technology *technology, + DBusMessage *msg, unsigned int policy) +{ + DBusMessage *reply = NULL; + int err = 0; + unsigned int last_policy = technology->preassoc_mac_policy; + + if (technology->rfkill_driven && technology->hardblocked) { + err = -EACCES; + goto make_reply; + } + + for (GSList *list = technology->device_list; list; list = list->next) { + struct connman_device *device = list->data; + + err = connman_device_set_preassoc_mac_policy(device, policy); + if (err < 0) + break; + } + +make_reply: + if (err < 0) { + if (err != -EACCES && err != -EOPNOTSUPP) { + for (GSList *list = technology->device_list; list; list = list->next) { + struct connman_device *device = list->data; + + connman_device_set_preassoc_mac_policy(device, last_policy); + } + } + + reply = __connman_error_failed(msg, -err); + } else { + reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); + } + + return reply; +} + +void connman_technology_random_mac_lifetime_notify(struct connman_technology *technology, + unsigned int lifetime) +{ + DBG("Random mac lifetime set to %u", lifetime); + + technology->random_mac_lifetime = lifetime; + technology_save(technology); +} + +void __connman_technology_notify_random_mac_lifetime_by_device(struct connman_device *device, + int result, unsigned int lifetime) +{ + struct connman_technology *technology; + enum connman_service_type type; + + type = __connman_device_get_service_type(device); + technology = technology_find(type); + + if (!technology) + return; + + connman_technology_random_mac_lifetime_notify(technology, lifetime); +} + +static DBusMessage *set_random_mac_lifetime(struct connman_technology *technology, + DBusMessage *msg, unsigned int lifetime) +{ + DBusMessage *reply = NULL; + int err = 0; + unsigned int last_lifetime = technology->random_mac_lifetime; + + if (technology->rfkill_driven && technology->hardblocked) { + err = -EACCES; + goto make_reply; + } + + for (GSList *list = technology->device_list; list; list = list->next) { + struct connman_device *device = list->data; + + err = connman_device_set_random_mac_lifetime(device, lifetime); + } + +make_reply: + if (err < 0) { + if (err != -EACCES && err != -EOPNOTSUPP) { + for (GSList *list = technology->device_list; list; list = list->next) { + struct connman_device *device = list->data; + + connman_device_set_random_mac_lifetime(device, last_lifetime); + } + } + + reply = __connman_error_failed(msg, -err); + } else { + reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); + } + + return reply; +} #endif static DBusMessage *set_property(DBusConnection *conn, @@ -1203,6 +1443,53 @@ static DBusMessage *set_property(DBusConnection *conn, dbus_message_iter_get_basic(&value, &key); DBG("BSSID %s", key); set_connman_bssid(SET_BSSID, key, NULL); + } else if (g_str_equal(name, "MacPolicy")) { + dbus_uint32_t mac_policy; + + if (technology->type != CONNMAN_SERVICE_TYPE_WIFI) + return __connman_error_not_supported(msg); + + if (type != DBUS_TYPE_UINT32) + return __connman_error_invalid_arguments(msg); + + dbus_message_iter_get_basic(&value, &mac_policy); + + if (mac_policy <= 2) + return set_mac_policy(technology, msg, mac_policy); + else + return __connman_error_invalid_arguments(msg); + + } else if (g_str_equal(name, "PreassocMacPolicy")) { + dbus_uint32_t preassoc_mac_policy; + + if (technology->type != CONNMAN_SERVICE_TYPE_WIFI) + return __connman_error_not_supported(msg); + + if (type != DBUS_TYPE_UINT32) + return __connman_error_invalid_arguments(msg); + + dbus_message_iter_get_basic(&value, &preassoc_mac_policy); + + if (preassoc_mac_policy <= 2) + return set_preassoc_mac_policy(technology, msg, preassoc_mac_policy); + else + return __connman_error_invalid_arguments(msg); + + } else if (g_str_equal(name, "RandomMacLifetime")) { + dbus_uint32_t random_mac_lifetime; + + if (technology->type != CONNMAN_SERVICE_TYPE_WIFI) + return __connman_error_not_supported(msg); + + if (type != DBUS_TYPE_UINT32) + return __connman_error_invalid_arguments(msg); + + dbus_message_iter_get_basic(&value, &random_mac_lifetime); + + if (random_mac_lifetime > 0) + return set_random_mac_lifetime(technology, msg, random_mac_lifetime); + else + return __connman_error_invalid_arguments(msg); #endif } else return __connman_error_invalid_property(msg); @@ -2960,6 +3247,10 @@ done: #if defined TIZEN_EXT const char *ifname = connman_device_get_string(device, "Interface"); __connman_technology_notify_device_detected(technology, ifname, true); + + connman_device_set_mac_policy(device, technology->mac_policy); + connman_device_set_preassoc_mac_policy(device, technology->preassoc_mac_policy); + connman_device_set_random_mac_lifetime(device, technology->random_mac_lifetime); #endif return 0; } |