tech->last_seen = dev_info->last_seen;
retv_if(UAM_ERROR_NONE != __uam_db_begin_transaction(), UAM_ERROR_INVALID_PARAMETER);
- /* Check if IP address was updated then update in DB */
+
+ /* Check if IP/MAC address was updated then update in DB */
if (UAM_TECH_TYPE_WIFI == dev_info->type) {
- uam_db_address_info_t *addr_info = NULL;
- gboolean is_updated = TRUE;
for (l = tech->addresses; NULL != l; l = g_slist_next(l)) {
uam_db_address_info_t *addr = l->data;
- if (!addr || (UAM_ADDR_TYPE_IPv4 != addr->addr_type))
+ if (NULL == addr)
continue;
- if (!strcasecmp(addr->address, dev_info->ipv4_addr))
- is_updated = FALSE;
- else
- UAM_DBG("Old IPv4: %s, New IPv4: %s",
+ if (UAM_ADDR_TYPE_IPv4 == addr->addr_type) {
+
+ if (strcasecmp(addr->address, dev_info->ipv4_addr)) {
+ UAM_DBG("Old IPv4: %s, New IPv4: %s",
addr->address, dev_info->ipv4_addr);
- addr_info = addr;
- break;
- }
- if (is_updated) {
- if (!addr_info) {
- addr_info = g_new0(uam_db_address_info_t, 1);
- tech->addresses = g_slist_append(tech->addresses, addr_info);
- } else {
- g_free(addr_info->address);
+ g_free(addr->address);
+ addr->addr_type = UAM_ADDR_TYPE_IPv4;
+ addr->address = g_strdup(dev_info->ipv4_addr);
+
+ /* Update IP address in DB */
+ ret = _uam_device_db_update_device_ip_address(dev_info->device_id,
+ dev_info->type, dev_info->ipv4_addr);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_WARN("_uam_device_db_update_device_ip_address failed");
+ __uam_db_end_transaction(0);
+ return ret;
+ }
+ }
}
- addr_info->addr_type = UAM_ADDR_TYPE_IPv4;
- addr_info->address = g_strdup(dev_info->ipv4_addr);
+ if (UAM_ADDR_TYPE_WIFI == addr->addr_type) {
- /* Update address in DB */
- ret = _uam_device_db_update_device_ip_address(dev_info->device_id,
- dev_info->type, dev_info->mac, dev_info->ipv4_addr);
- if (UAM_ERROR_NONE != ret) {
- UAM_WARN("_uam_device_db_update_device_ip_address failed");
- __uam_db_end_transaction(0);
- return ret;
+ if (strcasecmp(addr->address, dev_info->mac)) {
+ UAM_DBG("Old MAC: %s, New MAC: %s",
+ addr->address, dev_info->mac);
+
+ g_free(addr->address);
+ addr->addr_type = UAM_ADDR_TYPE_WIFI;
+ addr->address = g_strdup(dev_info->mac);
+
+ /* Update address in DB */
+ ret = _uam_device_db_update_device_mac_address(dev_info->device_id,
+ dev_info->type, dev_info->mac);
+ if (UAM_ERROR_NONE != ret) {
+ UAM_WARN("_uam_device_db_update_device_mac_address failed");
+ __uam_db_end_transaction(0);
+ return ret;
+ }
+ }
}
}
}
"SET presence_state = ? WHERE device_id = ? AND tech_type = ? AND address = ?"
#define UPDATE_IP_ADDRESS "UPDATE devices " \
- "SET ip_address = ? WHERE device_id = ? AND tech_type = ? AND address = ?"
+ "SET ip_address = ? WHERE device_id = ? AND tech_type = ?"
+
+#define UPDATE_MAC_ADDRESS "UPDATE devices " \
+ "SET address = ? WHERE device_id = ? AND tech_type = ?"
#define UPDATE_DEVICE "UPDATE devices " \
"SET (os_type, discriminant, ip_address, service_id, " \
static sqlite3_stmt *update_last_seen;
static sqlite3_stmt *update_presence;
static sqlite3_stmt *update_ip_address;
+static sqlite3_stmt *update_mac_address;
static sqlite3_stmt *update_device;
/* INSERT statements */
FINALIZE(update_last_seen);
FINALIZE(update_presence);
FINALIZE(update_ip_address);
+ FINALIZE(update_mac_address);
FINALIZE(update_device);
FUNC_EXIT;
UPDATE_PRESENCE, __uam_device_finalize_update);
PREPARE_QUERY(rc, db, update_ip_address,
UPDATE_IP_ADDRESS, __uam_device_finalize_update);
+ PREPARE_QUERY(rc, db, update_mac_address,
+ UPDATE_MAC_ADDRESS, __uam_device_finalize_update);
PREPARE_QUERY(rc, db, update_device,
UPDATE_DEVICE, __uam_device_finalize_update);
FUNC_ENTRY;
__uam_device_finalize_delete();
__uam_device_finalize_select();
+ __uam_device_finalize_update();
__uam_device_finalize_insert();
FUNC_EXIT;
}
}
int _uam_device_db_update_device_ip_address(char *device_id, int tech_type,
- char *address, char *ip_address)
+ char *ip_address)
{
int error_code = UAM_ERROR_NONE;
sqlite3_stmt *stmt = update_ip_address;
int sql_ret = SQLITE_OK;
retv_if(NULL == device_id, UAM_ERROR_INVALID_PARAMETER);
- retv_if(NULL == address, UAM_ERROR_INVALID_PARAMETER);
retv_if(NULL == ip_address, UAM_ERROR_INVALID_PARAMETER);
DB_ACTION(sqlite3_bind_text(stmt, 1, ip_address, -1, SQLITE_TRANSIENT),
error_code, handle_error);
DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type),
error_code, handle_error);
- DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT),
+
+ sql_ret = sqlite3_step(stmt);
+ if (sql_ret != SQLITE_DONE) {
+ UAM_ERR("Failed to update IP address [%d:%s]",
+ sql_ret, sqlite3_errmsg(database_handle));
+
+ error_code = UAM_ERROR_DB_FAILED;
+ goto handle_error;
+ }
+
+ UAM_DBG("[%d] IP address updated [%s]", tech_type, ip_address);
+
+handle_error:
+ sqlite3_reset(stmt);
+ return error_code;
+}
+
+int _uam_device_db_update_device_mac_address(char *device_id, int tech_type,
+ char *address)
+{
+ int error_code = UAM_ERROR_NONE;
+ sqlite3_stmt *stmt = update_mac_address;
+ int sql_ret = SQLITE_OK;
+
+ retv_if(NULL == device_id, UAM_ERROR_INVALID_PARAMETER);
+ retv_if(NULL == address, UAM_ERROR_INVALID_PARAMETER);
+
+ DB_ACTION(sqlite3_bind_text(stmt, 1, address, -1, SQLITE_TRANSIENT),
+ error_code, handle_error);
+ DB_ACTION(sqlite3_bind_text(stmt, 2, device_id, -1, SQLITE_TRANSIENT),
+ error_code, handle_error);
+ DB_ACTION(sqlite3_bind_int(stmt, 3, tech_type),
error_code, handle_error);
sql_ret = sqlite3_step(stmt);
if (sql_ret != SQLITE_DONE) {
- UAM_ERR("Failed to update ip address [%d:%s]",
+ UAM_ERR("Failed to update MAC address [%d:%s]",
sql_ret, sqlite3_errmsg(database_handle));
error_code = UAM_ERROR_DB_FAILED;
goto handle_error;
}
- UAM_DBG("ip address updated [%s]", ip_address);
+ UAM_DBG("[%d] MAC address updated [%s]", tech_type, address);
handle_error:
sqlite3_reset(stmt);