mirror of git://git.sysmocom.de/ofono
isimodem: Adapt and refactor devinfo driver
This commit is contained in:
parent
3c2c1f8daf
commit
5de8900262
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include <gisi/message.h>
|
||||||
#include <gisi/client.h>
|
#include <gisi/client.h>
|
||||||
#include <gisi/iter.h>
|
#include <gisi/iter.h>
|
||||||
|
|
||||||
|
@ -47,73 +48,60 @@ struct devinfo_data {
|
||||||
GIsiClient *client;
|
GIsiClient *client;
|
||||||
};
|
};
|
||||||
|
|
||||||
static gboolean info_resp_cb(GIsiClient *client,
|
static void info_resp_cb(const GIsiMessage *msg, void *data)
|
||||||
const void *restrict data, size_t len,
|
|
||||||
uint16_t object, void *opaque)
|
|
||||||
{
|
{
|
||||||
const unsigned char *msg = data;
|
struct isi_cb_data *cbd = data;
|
||||||
struct isi_cb_data *cbd = opaque;
|
|
||||||
ofono_devinfo_query_cb_t cb = cbd->cb;
|
ofono_devinfo_query_cb_t cb = cbd->cb;
|
||||||
|
|
||||||
GIsiSubBlockIter iter;
|
GIsiSubBlockIter iter;
|
||||||
char *info = NULL;
|
uint8_t msgid;
|
||||||
guint8 chars;
|
uint8_t status;
|
||||||
|
|
||||||
if (!msg) {
|
msgid = g_isi_msg_id(msg);
|
||||||
DBG("ISI client error: %d", g_isi_client_error(client));
|
if (msgid != INFO_PRODUCT_INFO_READ_RESP &&
|
||||||
|
msgid != INFO_VERSION_READ_RESP &&
|
||||||
|
msgid != INFO_SERIAL_NUMBER_READ_RESP)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
if (len < 3) {
|
if (g_isi_msg_error(msg) < 0)
|
||||||
DBG("truncated message");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg[0] != INFO_PRODUCT_INFO_READ_RESP
|
|
||||||
&& msg[0] != INFO_VERSION_READ_RESP
|
|
||||||
&& msg[0] != INFO_SERIAL_NUMBER_READ_RESP)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (msg[1] != INFO_OK) {
|
|
||||||
DBG("request failed: %s", info_isi_cause_name(msg[1]));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
for (g_isi_sb_iter_init(&iter, msg, len, 3);
|
if (!g_isi_msg_data_get_byte(msg, 0, &status))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (status != INFO_OK)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
for (g_isi_sb_iter_init(&iter, msg, 2);
|
||||||
g_isi_sb_iter_is_valid(&iter);
|
g_isi_sb_iter_is_valid(&iter);
|
||||||
g_isi_sb_iter_next(&iter)) {
|
g_isi_sb_iter_next(&iter)) {
|
||||||
|
|
||||||
switch (g_isi_sb_iter_get_id(&iter)) {
|
uint8_t id = g_isi_sb_iter_get_id(&iter);
|
||||||
|
uint8_t chars;
|
||||||
|
char *info = NULL;
|
||||||
|
|
||||||
case INFO_SB_PRODUCT_INFO_MANUFACTURER:
|
if (id != INFO_SB_PRODUCT_INFO_MANUFACTURER &&
|
||||||
case INFO_SB_PRODUCT_INFO_NAME:
|
id != INFO_SB_PRODUCT_INFO_NAME &&
|
||||||
case INFO_SB_MCUSW_VERSION:
|
id != INFO_SB_MCUSW_VERSION &&
|
||||||
case INFO_SB_SN_IMEI_PLAIN:
|
id != INFO_SB_SN_IMEI_PLAIN)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (g_isi_sb_iter_get_len(&iter) < 5
|
if (g_isi_sb_iter_get_len(&iter) < 5)
|
||||||
|| !g_isi_sb_iter_get_byte(&iter, &chars, 3)
|
goto error;
|
||||||
|| !g_isi_sb_iter_get_latin_tag(&iter,
|
|
||||||
&info, chars, 4))
|
if (!g_isi_sb_iter_get_byte(&iter, &chars, 3))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (!g_isi_sb_iter_get_latin_tag(&iter, &info, chars, 4))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
CALLBACK_WITH_SUCCESS(cb, info, cbd->data);
|
CALLBACK_WITH_SUCCESS(cb, info, cbd->data);
|
||||||
|
|
||||||
g_free(info);
|
g_free(info);
|
||||||
|
return;
|
||||||
g_free(cbd);
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
DBG("skipping: %s (%zu bytes)",
|
|
||||||
info_subblock_name(g_isi_sb_iter_get_id(&iter)),
|
|
||||||
g_isi_sb_iter_get_len(&iter));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
CALLBACK_WITH_FAILURE(cb, "", cbd->data);
|
CALLBACK_WITH_FAILURE(cb, "", cbd->data);
|
||||||
g_free(cbd);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void isi_query_manufacturer(struct ofono_devinfo *info,
|
static void isi_query_manufacturer(struct ofono_devinfo *info,
|
||||||
|
@ -123,7 +111,7 @@ static void isi_query_manufacturer(struct ofono_devinfo *info,
|
||||||
struct devinfo_data *dev = ofono_devinfo_get_data(info);
|
struct devinfo_data *dev = ofono_devinfo_get_data(info);
|
||||||
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
|
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
|
||||||
|
|
||||||
const unsigned char msg[] = {
|
const uint8_t msg[] = {
|
||||||
INFO_PRODUCT_INFO_READ_REQ,
|
INFO_PRODUCT_INFO_READ_REQ,
|
||||||
INFO_PRODUCT_MANUFACTURER
|
INFO_PRODUCT_MANUFACTURER
|
||||||
};
|
};
|
||||||
|
@ -131,8 +119,8 @@ static void isi_query_manufacturer(struct ofono_devinfo *info,
|
||||||
if (cbd == NULL || dev == NULL)
|
if (cbd == NULL || dev == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_isi_request_make(dev->client, msg, sizeof(msg),
|
if (g_isi_client_send(dev->client, msg, sizeof(msg), INFO_TIMEOUT,
|
||||||
INFO_TIMEOUT, info_resp_cb, cbd))
|
info_resp_cb, cbd, g_free))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -147,16 +135,16 @@ static void isi_query_model(struct ofono_devinfo *info,
|
||||||
struct devinfo_data *dev = ofono_devinfo_get_data(info);
|
struct devinfo_data *dev = ofono_devinfo_get_data(info);
|
||||||
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
|
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
|
||||||
|
|
||||||
const unsigned char msg[] = {
|
const uint8_t msg[] = {
|
||||||
INFO_PRODUCT_INFO_READ_REQ,
|
INFO_PRODUCT_INFO_READ_REQ,
|
||||||
INFO_PRODUCT_NAME
|
INFO_PRODUCT_NAME
|
||||||
};
|
};
|
||||||
|
|
||||||
if (cbd == NULL)
|
if (cbd == NULL || dev == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_isi_request_make(dev->client, msg, sizeof(msg),
|
if (g_isi_client_send(dev->client, msg, sizeof(msg), INFO_TIMEOUT,
|
||||||
INFO_TIMEOUT, info_resp_cb, cbd))
|
info_resp_cb, cbd, g_free))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -171,7 +159,7 @@ static void isi_query_revision(struct ofono_devinfo *info,
|
||||||
struct devinfo_data *dev = ofono_devinfo_get_data(info);
|
struct devinfo_data *dev = ofono_devinfo_get_data(info);
|
||||||
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
|
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
|
||||||
|
|
||||||
const unsigned char msg[] = {
|
const uint8_t msg[] = {
|
||||||
INFO_VERSION_READ_REQ,
|
INFO_VERSION_READ_REQ,
|
||||||
0x00, INFO_MCUSW,
|
0x00, INFO_MCUSW,
|
||||||
0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00
|
||||||
|
@ -180,8 +168,8 @@ static void isi_query_revision(struct ofono_devinfo *info,
|
||||||
if (cbd == NULL || dev == NULL)
|
if (cbd == NULL || dev == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_isi_request_make(dev->client, msg, sizeof(msg),
|
if (g_isi_client_send(dev->client, msg, sizeof(msg), INFO_TIMEOUT,
|
||||||
INFO_TIMEOUT, info_resp_cb, cbd))
|
info_resp_cb, cbd, g_free))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -196,7 +184,7 @@ static void isi_query_serial(struct ofono_devinfo *info,
|
||||||
struct devinfo_data *dev = ofono_devinfo_get_data(info);
|
struct devinfo_data *dev = ofono_devinfo_get_data(info);
|
||||||
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
|
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
|
||||||
|
|
||||||
const unsigned char msg[] = {
|
const uint8_t msg[] = {
|
||||||
INFO_SERIAL_NUMBER_READ_REQ,
|
INFO_SERIAL_NUMBER_READ_REQ,
|
||||||
INFO_SN_IMEI_PLAIN
|
INFO_SN_IMEI_PLAIN
|
||||||
};
|
};
|
||||||
|
@ -204,8 +192,8 @@ static void isi_query_serial(struct ofono_devinfo *info,
|
||||||
if (cbd == NULL || dev == NULL)
|
if (cbd == NULL || dev == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_isi_request_make(dev->client, msg, sizeof(msg),
|
if (g_isi_client_send(dev->client, msg, sizeof(msg), INFO_TIMEOUT,
|
||||||
INFO_TIMEOUT, info_resp_cb, cbd))
|
info_resp_cb, cbd, g_free))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -213,37 +201,16 @@ error:
|
||||||
g_free(cbd);
|
g_free(cbd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean isi_devinfo_register(gpointer user)
|
static void reachable_cb(const GIsiMessage *msg, void *data)
|
||||||
{
|
{
|
||||||
struct ofono_devinfo *info = user;
|
struct ofono_devinfo *info = data;
|
||||||
struct devinfo_data *dd = ofono_devinfo_get_data(info);
|
|
||||||
|
|
||||||
const char *debug = getenv("OFONO_ISI_DEBUG");
|
if (g_isi_msg_error(msg) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (debug && (strcmp(debug, "all") == 0 || strcmp(debug, "info") == 0))
|
ISI_VERSION_DBG(msg);
|
||||||
g_isi_client_set_debug(dd->client, info_debug, NULL);
|
|
||||||
|
|
||||||
ofono_devinfo_register(info);
|
ofono_devinfo_register(info);
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void reachable_cb(GIsiClient *client, gboolean alive, uint16_t object,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
struct ofono_devinfo *info = opaque;
|
|
||||||
|
|
||||||
if (!alive) {
|
|
||||||
DBG("devinfo driver bootstrap failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DBG("%s (v%03d.%03d) reachable",
|
|
||||||
pn_resource_name(g_isi_client_resource(client)),
|
|
||||||
g_isi_version_major(client),
|
|
||||||
g_isi_version_minor(client));
|
|
||||||
|
|
||||||
g_idle_add(isi_devinfo_register, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int isi_devinfo_probe(struct ofono_devinfo *info, unsigned int vendor,
|
static int isi_devinfo_probe(struct ofono_devinfo *info, unsigned int vendor,
|
||||||
|
@ -263,7 +230,7 @@ static int isi_devinfo_probe(struct ofono_devinfo *info, unsigned int vendor,
|
||||||
|
|
||||||
ofono_devinfo_set_data(info, data);
|
ofono_devinfo_set_data(info, data);
|
||||||
|
|
||||||
g_isi_verify(data->client, reachable_cb, info);
|
g_isi_client_verify(data->client, reachable_cb, info, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -272,11 +239,14 @@ static void isi_devinfo_remove(struct ofono_devinfo *info)
|
||||||
{
|
{
|
||||||
struct devinfo_data *data = ofono_devinfo_get_data(info);
|
struct devinfo_data *data = ofono_devinfo_get_data(info);
|
||||||
|
|
||||||
if (data) {
|
ofono_devinfo_set_data(info, NULL);
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
g_isi_client_destroy(data->client);
|
g_isi_client_destroy(data->client);
|
||||||
g_free(data);
|
g_free(data);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static struct ofono_devinfo_driver driver = {
|
static struct ofono_devinfo_driver driver = {
|
||||||
.name = "isimodem",
|
.name = "isimodem",
|
||||||
|
|
Loading…
Reference in New Issue