Hi everyone, I found a problem when using the blobmsg. I have defined the blobmsg_policy as follows:
static const struct blobmsg_policy uswitch_config_policy[__USWITCH_CONFIG_MAX] = {
[USWITCH_CONFIG_ACTION] = {"action", BLOBMSG_TYPE_STRING},
[USWITCH_CONFIG_VLANID] = {"vlan_id", BLOBMSG_TYPE_INT16}, // vlan_id 12bit
[USWITCH_CONFIG_MACADDR] = {"mac_addr", BLOBMSG_TYPE_STRING},
[USWITCH_CONFIG_INTERFACE] = {"interface", BLOBMSG_TYPE_STRING},
};
....
blobmsg_parse(uswitch_config_policy, __USWITCH_CONFIG_MAX, tb,
blobmsg_data(attr), blobmsg_len(attr)); // cannot parse BLOBMSG_TYPE_INT16
but when I invoke the method using ubus call ... '{"vlan_id":100 ...}'
, the blobmsg_parse
cannot parse vlan_id
value, I found out from the message body that the type of vlan_id
is BLOBMSG_TYPE_INT32
, not BLOBMSG_TYPE_INT16
int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len,
struct blob_attr **tb, void *data, unsigned int len) {
....
if (policy[i].type != BLOBMSG_TYPE_UNSPEC &&
policy[i].type != BLOBMSG_CAST_INT64 &&
blob_id(attr) != policy[i].type) // blob_id(attr) = BLOBMSG_TYPE_INT32
// policy[i].type = BLOBMSG_TYPE_INT16
continue;
}
ubus -v list uswitch
command shows the type of vlan_id is unknown
root@OpenWrt:~# ubus -v list uswitch
'uswitch' @5b5acce5
"mac_address_table":{"action":"String","vlan_id":"(unknown)","mac_addr":"String","interface":"String"}
ubus/cli.c
static const char *format_type(void *priv, struct blob_attr *attr)
{
static const char * const attr_types[] = {
[BLOBMSG_TYPE_INT8] = "\"Boolean\"",
[BLOBMSG_TYPE_INT32] = "\"Integer\"",
[BLOBMSG_TYPE_STRING] = "\"String\"",
[BLOBMSG_TYPE_ARRAY] = "\"Array\"",
[BLOBMSG_TYPE_TABLE] = "\"Table\"",
};
const char *type = NULL;
size_t typeid;
if (blob_id(attr) != BLOBMSG_TYPE_INT32)
return NULL;
typeid = blobmsg_get_u32(attr);
if (typeid < ARRAY_SIZE(attr_types))
type = attr_types[typeid];
if (!type)
type = "\"(unknown)\""; /////// unknown
return type;
}
My question is how to use the BLOBMSG_TYPE_INT16
type ? If it's not supported, why not remove it? I found some other projects that use that type too.