diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index df26145..737aee3 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
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,
diff --git a/mesh/mesh-db.c b/mesh/mesh-db.c
index 6f56dc5..2dc13cd 100644
--- a/mesh/mesh-db.c
+++ b/mesh/mesh-db.c
if (!get_int(jpub, "period", &value))
goto fail;
- pub->period = (uint8_t) value;
+ pub->period = value;
if (!get_int(jpub, "credentials", &value))
goto fail;
diff --git a/mesh/mesh-db.h b/mesh/mesh-db.h
index 5dec6cb..b9af120 100644
--- a/mesh/mesh-db.h
+++ b/mesh/mesh-db.h
struct mesh_db_pub {
bool virt;
+ uint32_t period;
uint16_t addr;
uint16_t idx;
uint8_t ttl;
uint8_t credential;
- uint8_t period;
uint8_t count;
uint8_t interval;
uint8_t virt_addr[16];
diff --git a/mesh/model.c b/mesh/model.c
index dc525f7..80c30ed 100644
--- a/mesh/model.c
+++ b/mesh/model.c
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);
}