const char *key);
extern int connman_network_set_uint8(struct connman_network *network,
const char *key, connman_uint8_t value);
+extern connman_uint8_t connman_network_get_uint8(struct connman_network *network,
+ const char *key);
extern int connman_network_set_blob(struct connman_network *network,
const char *key, const void *data, unsigned int size);
extern const void *connman_network_get_blob(struct connman_network *network,
static void connect_known_network(struct connman_device *device)
{
+ struct connman_network *network = NULL;
GHashTableIter iter;
gpointer key, value;
unsigned int count = 0;
g_hash_table_iter_init(&iter, device->networks);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- struct connman_network *network = value;
- int err;
+ connman_uint8_t old_priority, new_priority;
+ connman_uint8_t old_strength, new_strength;
count++;
- if (connman_network_get_remember(network) == FALSE)
+ if (connman_network_get_remember(value) == FALSE)
+ continue;
+
+ if (network == NULL) {
+ network = value;
+ continue;
+ }
+
+ old_priority = connman_network_get_uint8(network, "Priority");
+ new_priority = connman_network_get_uint8(value, "Priority");
+
+ if (new_priority != old_priority) {
+ if (new_priority > old_priority)
+ network = value;
continue;
+ }
+
+ old_strength = connman_network_get_uint8(network, "Strength");
+ old_strength = connman_network_get_uint8(value, "Strength");
+
+ if (new_strength > old_strength)
+ network = value;
+ }
+
+ if (network != NULL) {
+ int err;
err = connman_network_connect(network);
if (err == 0 || err == -EINPROGRESS)
{
DBG("network %p key %s value %d", network, key, value);
- if (g_str_equal(key, "Strength") == TRUE) {
+ if (g_str_equal(key, "Priority") == TRUE)
+ network->priority = value;
+ else if (g_str_equal(key, "Strength") == TRUE) {
network->strength = value;
connman_element_set_static_property(&network->element,
"Strength", DBUS_TYPE_BYTE, &value);
}
/**
+ * connman_network_get_uint8:
+ * @network: network structure
+ * @key: unique identifier
+ *
+ * Get integer value for specific key
+ */
+connman_uint8_t connman_network_get_uint8(struct connman_network *network,
+ const char *key)
+{
+ DBG("network %p key %s", network, key);
+
+ if (g_str_equal(key, "Priority") == TRUE)
+ return network->priority;
+ else if (g_str_equal(key, "Strength") == TRUE)
+ return network->strength;
+
+ return 0;
+}
+
+/**
* connman_network_set_blob:
* @network: network structure
* @key: unique identifier