uint8_t retransmit;
int status;
bool cred_flag, b_virt = false;
+ bool vendor = false;
+ struct mesh_model_pub *pub;
+ uint8_t ele_idx;
switch (size) {
default:
retransmit = pkt[8];
mod_id = l_get_le16(pkt + 9) << 16;
mod_id |= l_get_le16(pkt + 11);
+ vendor = true;
break;
case 25:
retransmit = pkt[22];
mod_id = l_get_le16(pkt + 23) << 16;
mod_id |= l_get_le16(pkt + 25);
+ vendor = true;
break;
}
ele_addr = l_get_le16(pkt);
l_debug("pub_set: status %d, ea %4.4x, ota: %4.4x, mod: %x, idx: %3.3x",
status, ele_addr, ota, mod_id, idx);
- if (IS_UNASSIGNED(ota) && !b_virt)
+ if (IS_UNASSIGNED(ota) && !b_virt) {
ttl = period = idx = 0;
+ /* Remove model publication from config file */
+ if (status == MESH_STATUS_SUCCESS)
+ mesh_db_model_pub_del(node_jconfig_get(node), ele_addr,
+ vendor ? mod_id : mod_id & 0x0000ffff,
+ vendor);
+ goto done;
+ }
+
+ if (status != MESH_STATUS_SUCCESS)
+ goto done;
+
+ ele_idx = node_get_element_idx(node, ele_addr);
+ pub = mesh_model_pub_get(node, ele_idx, mod_id, &status);
+
+ if (pub) {
+ struct mesh_db_pub db_pub = {
+ .virt = b_virt,
+ .addr = ota,
+ .idx = idx,
+ .ttl = ttl,
+ .credential = pub->credential,
+ .period = period,
+ .count = pub->retransmit >> 5,
+ .interval = ((0x1f & pub->retransmit) + 1) * 50
+ };
+
+ if (b_virt)
+ memcpy(db_pub.virt_addr, pub_addr, 16);
+
+ /* Save model publication to config file */
+ if (!mesh_db_model_pub_add(node_jconfig_get(node), ele_addr,
+ vendor ? mod_id : mod_id & 0x0000ffff,
+ vendor, &db_pub))
+ status = MESH_STATUS_STORAGE_FAIL;
+ }
+
+done:
if (!unreliable)
send_pub_status(node, src, dst, status, ele_addr, ota,
mod_id, idx, cred_flag, ttl, period,
return get_model(node, (uint8_t) ele_idx, mod_id, fail);
}
-static uint32_t convert_pub_period_to_ms(uint8_t pub_period)
+static uint32_t pub_period_to_ms(uint8_t pub_period)
{
int n;
- n = (pub_period & 0x3f);
+ n = pub_period >> 2;
- switch (pub_period >> 6) {
+ switch (pub_period & 0x3) {
default:
return n * 100;
case 2:
l_free(mod->pub);
mod->pub = NULL;
- /* TODO: remove from storage */
-
+ /*
+ * TODO: Instead of reporting period of 0, report publication
+ * address as unassigned
+ */
if (!mod->cbs)
/* External models */
config_update_model_pub_period(node, mod->ele_idx, mod->id, 0);
if (result != MESH_STATUS_SUCCESS)
return result;
- /* TODO: save to storage */
-
/*
* If the publication address is set to unassigned address value,
* remove publication
/* External model */
config_update_model_pub_period(node, ele_idx, id,
- convert_pub_period_to_ms(period));
+ pub_period_to_ms(period));
return MESH_STATUS_SUCCESS;
}
/* Model periodic publication interval, if present */
if (mod->pub) {
- uint32_t period = convert_pub_period_to_ms(mod->pub->period);
+ uint32_t period = pub_period_to_ms(mod->pub->period);
dbus_append_dict_entry_basic(builder, "PublicationPeriod", "u",
&period);
}