Apply firmware via DM for '6 Stored Firmware Image'

This commit is contained in:
Suvendhu Hansa 2025-06-04 16:22:36 +05:30
parent e9179a5786
commit 13c8bed356
4 changed files with 64 additions and 37 deletions

View file

@ -65,6 +65,7 @@
#define DEFAULT_SESSION_TIMEOUT 60 #define DEFAULT_SESSION_TIMEOUT 60
#define MAX_NBRE_SERVICES 256 #define MAX_NBRE_SERVICES 256
#define DEFAULT_SYNC_TIMEOUT 128 #define DEFAULT_SYNC_TIMEOUT 128
#define DEFAULT_UBUS_TIMEOUT 60000
#define BUF_SIZE_8 (8 + 1) #define BUF_SIZE_8 (8 + 1)
#define BUF_SIZE_16 (16 + 1) #define BUF_SIZE_16 (16 + 1)

View file

@ -301,22 +301,6 @@ void ubus_get_bank_status_callback(struct ubus_request *req, int type __attribut
bank->status = 0; bank->status = 0;
} }
int get_applied_firmware_status(struct fwbank_dump *bank)
{
int e;
struct blob_buf b = { 0 };
CWMP_MEMSET(&b, 0, sizeof(struct blob_buf));
blob_buf_init(&b, 0);
e = icwmp_ubus_invoke("fwbank", "dump", b.head, ubus_get_available_bank_callback, &bank);
if (e != 0) {
CWMP_LOG(INFO, "fwbank dump ubus method failed: Ubus err code: %d", e);
}
blob_buf_free(&b);
return e;
}
/* /*
* Apply the new firmware * Apply the new firmware
*/ */
@ -384,47 +368,71 @@ bool cwmp_apply_web_content(char *filepath)
return status; return status;
} }
void wait_firmware_to_be_applied(int bank_id) void fw_upgrade_callback(struct ubus_request *req, int type __attribute__((unused)), struct blob_attr *msg)
{ {
int count = 0; char **fault = (char **)req->priv;
const struct blobmsg_policy p[1] = { { "results", BLOBMSG_TYPE_ARRAY } };
struct blob_attr *tb[1] = { NULL };
blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg));
if (tb[0]) {
struct blob_attr *attr = NULL;
int rem = 0;
do { blobmsg_for_each_attr(attr, tb[0], rem) {
struct fwbank_dump bank = {.bank_id = bank_id, .status = 0}; const struct blobmsg_policy p1[1] = { { "output", BLOBMSG_TYPE_ARRAY } };
if (get_applied_firmware_status(&bank) != CWMP_OK) struct blob_attr *tb1[1] = { NULL };
continue; blobmsg_parse(p1, 1, tb1, blobmsg_data(attr), blobmsg_len(attr));
if (bank.status == 1) if (tb1[0]) {
break; struct blob_attr *param = NULL;
int len = 0;
sleep(2); blobmsg_for_each_attr(param, tb1[0], len) {
count++; const struct blobmsg_policy p2[1] = { { "fault", BLOBMSG_TYPE_INT32 } };
} while(count < 20); struct blob_attr *tb2[1] = { NULL };
blobmsg_parse(p2, 1, tb2, blobmsg_data(param), blobmsg_len(param));
if (tb2[0]) {
*fault = strdup("9010");
return;
}
}
}
}
*fault = NULL;
} else {
*fault = strdup("9010");
}
} }
int cwmp_apply_multiple_firmware() int cwmp_apply_multiple_firmware()
{ {
char *fault_code = NULL;
int e; int e;
int bank_id = get_available_bank_id(); int bank_id = get_available_bank_id();
if (bank_id <= 0) if (bank_id <= 0)
return -1; return -1;
char path[128] = {0}, url[128] = {0};
snprintf(path, sizeof(path), "Device.DeviceInfo.FirmwareImage.%d.Download()", bank_id);
snprintf(url, sizeof(url), "file://%s", FIRMWARE_UPGRADE_IMAGE);
struct blob_buf b = { 0 }; struct blob_buf b = { 0 };
CWMP_MEMSET(&b, 0, sizeof(struct blob_buf)); CWMP_MEMSET(&b, 0, sizeof(struct blob_buf));
blob_buf_init(&b, 0); blob_buf_init(&b, 0);
bb_add_string(&b, "path", FIRMWARE_UPGRADE_IMAGE); bb_add_string(&b, "path", path);
blobmsg_add_u8(&b, "auto_activate", false); void *tbl = blobmsg_open_table(&b, "input");
blobmsg_add_u32(&b, "bank", bank_id); bb_add_string(&b, "URL", url);
blobmsg_add_u8(&b, "keep_settings", cwmp_ctx.conf.fw_upgrade_keep_settings); blobmsg_close_table(&b, tbl);
e = icwmp_ubus_invoke("fwbank", "upgrade", b.head, NULL, NULL); e = icwmp_ubus_invoke_timeout(BBFDM_OBJECT_NAME, "operate", b.head, fw_upgrade_callback, &fault_code, 120000);
blob_buf_free(&b); blob_buf_free(&b);
if (e != 0) { if (e != 0 || CWMP_STRLEN(fault_code) != 0) {
CWMP_LOG(INFO, "fwbank upgrade ubus method failed: Ubus err code: %d", e); CWMP_LOG(INFO, "fwbank upgrade ubus method failed: Ubus err code: %d, fault code: %s", e, fault_code ? fault_code : "");
FREE(fault_code);
return -2; return -2;
} }
//wait until the apply completes
wait_firmware_to_be_applied(bank_id);
//set /var/state 'switch_bank' option //set /var/state 'switch_bank' option
set_uci_path_value(VARSTATE_CONFIG, "icwmp.cpe.switch_bank", "1"); set_uci_path_value(VARSTATE_CONFIG, "icwmp.cpe.switch_bank", "1");

View file

@ -23,6 +23,7 @@ typedef int (*callback)(struct blob_buf *b);
static bool g_bbf_object_available = false; static bool g_bbf_object_available = false;
static struct ubus_context *ubus_ctx = NULL; static struct ubus_context *ubus_ctx = NULL;
struct uloop_timeout u_timeout; struct uloop_timeout u_timeout;
static int ubus_timeout = DEFAULT_UBUS_TIMEOUT;
static int icwmp_register_object(struct ubus_context *ctx); static int icwmp_register_object(struct ubus_context *ctx);
@ -468,13 +469,28 @@ int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg
} }
if (!ubus_lookup_id(ubus_ctx, obj, &id)) if (!ubus_lookup_id(ubus_ctx, obj, &id))
rc = ubus_invoke(ubus_ctx, id, method, msg, icwmp_callback, callback_arg, 60000); rc = ubus_invoke(ubus_ctx, id, method, msg, icwmp_callback, callback_arg, ubus_timeout);
else else
rc = -1; rc = -1;
return rc; return rc;
} }
int icwmp_ubus_invoke_timeout(const char *obj, const char *method, struct blob_attr *msg,
icwmp_ubus_cb icwmp_callback, void *callback_arg, int timeout)
{
int rc = 0;
if (timeout > DEFAULT_UBUS_TIMEOUT)
ubus_timeout = timeout;
rc = icwmp_ubus_invoke(obj, method, msg, icwmp_callback, callback_arg);
ubus_timeout = DEFAULT_UBUS_TIMEOUT;
return rc;
}
int icwmp_ubus_invoke_async(const char *obj, const char *method, struct blob_attr *msg, int icwmp_ubus_invoke_async(const char *obj, const char *method, struct blob_attr *msg,
icwmp_ubus_cb data_callback, icwmp_ubus_async_cb complete_callback) icwmp_ubus_cb data_callback, icwmp_ubus_async_cb complete_callback)
{ {

View file

@ -19,6 +19,8 @@ typedef void (*icwmp_ubus_async_cb)(struct ubus_request *req, int ret);
void bb_add_string(struct blob_buf *bb, const char *name, const char *value); void bb_add_string(struct blob_buf *bb, const char *name, const char *value);
int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg, int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg,
icwmp_ubus_cb icwmp_callback, void *callback_arg); icwmp_ubus_cb icwmp_callback, void *callback_arg);
int icwmp_ubus_invoke_timeout(const char *obj, const char *method, struct blob_attr *msg,
icwmp_ubus_cb icwmp_callback, void *callback_arg, int timeout);
int icwmp_ubus_invoke_async(const char *obj, const char *method, struct blob_attr *msg, int icwmp_ubus_invoke_async(const char *obj, const char *method, struct blob_attr *msg,
icwmp_ubus_cb data_callback, icwmp_ubus_async_cb complete_callback); icwmp_ubus_cb data_callback, icwmp_ubus_async_cb complete_callback);
int icwmp_uloop_ubus_register(void); int icwmp_uloop_ubus_register(void);