Lines Matching refs:hb_context
146 struct hawkbit_context hb_context; member
665 static int hawkbit_parse_deployment(struct hawkbit_context *hb_context, struct hawkbit_dep_res *res, in hawkbit_parse_deployment() argument
692 if (hex2bin(artifact->hashes.sha256, SHA256_HASH_SIZE << 1, hb_context->dl.file_hash, in hawkbit_parse_deployment()
693 sizeof(hb_context->dl.file_hash)) != SHA256_HASH_SIZE) { in hawkbit_parse_deployment()
697 hb_context->dl.file_size = artifact->size; in hawkbit_parse_deployment()
699 if (hb_context->dl.file_size > SLOT1_SIZE) { in hawkbit_parse_deployment()
700 LOG_ERR("Artifact file size too big (got %d, max is %d)", hb_context->dl.file_size, in hawkbit_parse_deployment()
869 struct hawkbit_context *hb_context = userdata; in response_cb() local
877 hb_context->code_status = HAWKBIT_PERMISSION_ERROR; in response_cb()
879 hb_context->code_status = HAWKBIT_METADATA_ERROR; in response_cb()
884 switch (hb_context->type) { in response_cb()
887 if (hb_context->dl.http_content_size == 0) { in response_cb()
888 hb_context->dl.http_content_size = rsp->content_length; in response_cb()
895 if ((hb_context->dl.downloaded_size + body_len) > in response_cb()
896 hb_context->response_data_size) { in response_cb()
897 hb_context->response_data_size = in response_cb()
898 hb_context->dl.downloaded_size + body_len; in response_cb()
899 rsp_tmp = k_realloc(hb_context->response_data, in response_cb()
900 hb_context->response_data_size); in response_cb()
903 hb_context->code_status = HAWKBIT_ALLOC_ERROR; in response_cb()
907 hb_context->response_data = rsp_tmp; in response_cb()
909 strncpy(hb_context->response_data + hb_context->dl.downloaded_size, in response_cb()
911 hb_context->dl.downloaded_size += body_len; in response_cb()
915 if (hb_context->dl.http_content_size != hb_context->dl.downloaded_size) { in response_cb()
917 hb_context->dl.http_content_size, in response_cb()
918 hb_context->dl.downloaded_size); in response_cb()
919 hb_context->code_status = HAWKBIT_METADATA_ERROR; in response_cb()
923 hb_context->response_data[hb_context->dl.downloaded_size] = '\0'; in response_cb()
924 memset(&hb_context->results, 0, sizeof(hb_context->results)); in response_cb()
925 if (hb_context->type == HAWKBIT_PROBE) { in response_cb()
927 hb_context->response_data, hb_context->dl.downloaded_size, in response_cb()
929 &hb_context->results.base); in response_cb()
932 hb_context->code_status = HAWKBIT_METADATA_ERROR; in response_cb()
936 hb_context->response_data, hb_context->dl.downloaded_size, in response_cb()
938 &hb_context->results.dep); in response_cb()
941 hb_context->code_status = HAWKBIT_METADATA_ERROR; in response_cb()
949 if (hb_context->dl.http_content_size == 0) { in response_cb()
950 hb_context->dl.http_content_size = rsp->content_length; in response_cb()
957 ret = flash_img_buffered_write(&hb_context->flash_ctx, body_data, body_len, in response_cb()
961 hb_context->code_status = HAWKBIT_DOWNLOAD_ERROR; in response_cb()
966 hb_context->dl.downloaded_size = flash_img_bytes_written(&hb_context->flash_ctx); in response_cb()
969 hb_context->dl.downloaded_size * 100 / hb_context->dl.http_content_size; in response_cb()
971 if (downloaded > hb_context->dl.download_progress) { in response_cb()
972 hb_context->dl.download_progress = downloaded; in response_cb()
973 LOG_DBG("Downloaded: %d%% ", hb_context->dl.download_progress); in response_cb()
977 hb_context->final_data_received = true; in response_cb()
988 static bool send_request(struct hawkbit_context *hb_context, enum hawkbit_http_request type, in send_request() argument
1015 hb_context->final_data_received = false; in send_request()
1016 hb_context->type = type; in send_request()
1065 hb_context->dl.http_content_size = 0; in send_request()
1066 hb_context->dl.downloaded_size = 0; in send_request()
1074 ret = http_client_req(hb_context->sock, &http_req, HAWKBIT_RECV_TIMEOUT, hb_context); in send_request()
1077 hb_context->code_status = HAWKBIT_NETWORKING_ERROR; in send_request()
1081 if (IN_RANGE(hb_context->code_status, HAWKBIT_NETWORKING_ERROR, HAWKBIT_ALLOC_ERROR)) { in send_request()
1173 if (!start_http_client(&s->hb_context.sock)) { in s_http_start()
1174 s->hb_context.code_status = HAWKBIT_NETWORKING_ERROR; in s_http_start()
1178 s->hb_context.response_data_size = RESPONSE_BUFFER_SIZE; in s_http_start()
1180 s->hb_context.response_data = k_calloc(s->hb_context.response_data_size, sizeof(uint8_t)); in s_http_start()
1181 if (s->hb_context.response_data == NULL) { in s_http_start()
1182 cleanup_connection(&s->hb_context.sock); in s_http_start()
1183 s->hb_context.code_status = HAWKBIT_ALLOC_ERROR; in s_http_start()
1192 cleanup_connection(&s->hb_context.sock); in s_http_end()
1193 k_free(s->hb_context.response_data); in s_http_end()
1210 if (!send_request(&s->hb_context, HAWKBIT_PROBE, url_buffer, NULL)) { in s_probe()
1216 if (s->hb_context.results.base.config.polling.sleep) { in s_probe()
1218 LOG_DBG("config.polling.sleep=%s", s->hb_context.results.base.config.polling.sleep); in s_probe()
1219 hawkbit_update_sleep(&s->hb_context.results.base); in s_probe()
1222 if (s->hb_context.results.base._links.cancelAction.href) { in s_probe()
1224 s->hb_context.results.base._links.cancelAction.href); in s_probe()
1226 } else if (s->hb_context.results.base._links.configData.href) { in s_probe()
1228 s->hb_context.results.base._links.configData.href); in s_probe()
1230 } else if (s->hb_context.results.base._links.deploymentBase.href) { in s_probe()
1232 s->hb_context.results.base._links.deploymentBase.href); in s_probe()
1235 s->hb_context.code_status = HAWKBIT_NO_UPDATE; in s_probe()
1255 cancel_base = hawkbit_get_url(s->hb_context.results.base._links.cancelAction.href); in s_cancel()
1258 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_cancel()
1265 ret = hawkbit_find_cancel_action_id(&s->hb_context.results.base, &cancel_action_id); in s_cancel()
1268 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_cancel()
1282 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_cancel()
1287 if (!send_request(&s->hb_context, HAWKBIT_CANCEL, url_buffer, status_buffer)) { in s_cancel()
1314 url_buffer = hawkbit_get_url(s->hb_context.results.base._links.configData.href); in s_config_device()
1317 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_config_device()
1326 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_config_device()
1331 if (!send_request(&s->hb_context, HAWKBIT_CONFIG_DEVICE, url_buffer, status_buffer)) { in s_config_device()
1350 url_buffer = hawkbit_get_url(s->hb_context.results.base._links.deploymentBase.href); in s_probe_deployment_base()
1353 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_probe_deployment_base()
1358 if (!send_request(&s->hb_context, HAWKBIT_PROBE_DEPLOYMENT_BASE, url_buffer, NULL)) { in s_probe_deployment_base()
1364 hawkbit_dump_deployment(&s->hb_context.results.dep); in s_probe_deployment_base()
1366 ret = hawkbit_deployment_get_action_id(&s->hb_context.results.dep, in s_probe_deployment_base()
1367 &s->hb_context.json_action_id); in s_probe_deployment_base()
1369 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_probe_deployment_base()
1374 if (hb_cfg.action_id == s->hb_context.json_action_id) { in s_probe_deployment_base()
1399 CONFIG_BOARD, s->device_id, "deploymentBase", s->hb_context.json_action_id, in s_report()
1404 s->hb_context.json_action_id); in s_report()
1410 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_report()
1415 if (!send_request(&s->hb_context, HAWKBIT_REPORT, url_buffer, status_buffer)) { in s_report()
1447 ret = hawkbit_parse_deployment(&s->hb_context, &s->hb_context.results.dep, &url_buffer); in s_download()
1450 s->hb_context.code_status = HAWKBIT_METADATA_ERROR; in s_download()
1455 flash_img_init(&s->hb_context.flash_ctx); in s_download()
1460 flash_area_ptr = s->hb_context.flash_ctx.flash_area; in s_download()
1462 if (!send_request(&s->hb_context, HAWKBIT_DOWNLOAD, url_buffer, NULL)) { in s_download()
1469 if (!s->hb_context.final_data_received) { in s_download()
1471 s->hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR; in s_download()
1477 fic.match = s->hb_context.dl.file_hash; in s_download()
1478 fic.clen = s->hb_context.dl.downloaded_size; in s_download()
1479 if (flash_img_check(&s->hb_context.flash_ctx, &fic, flash_area_ptr->fa_id)) { in s_download()
1481 s->hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR; in s_download()
1489 s->hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR; in s_download()
1495 s->hb_context.code_status = HAWKBIT_UPDATE_INSTALLED; in s_download()
1496 hawkbit_device_acid_update(s->hb_context.json_action_id); in s_download()
1507 if (IN_RANGE(s->hb_context.code_status, HAWKBIT_NETWORKING_ERROR, in s_terminate()
1510 switch (s->hb_context.code_status) { in s_terminate()
1536 smf_set_terminate(SMF_CTX(s), s->hb_context.code_status); in s_terminate()