Lines Matching refs:ctx

26 static int hs20_spp_update_response(struct hs20_osu_client *ctx,
31 struct hs20_osu_client *ctx, const char *pps_fname);
34 static char * get_spp_attr_value(struct xml_node_ctx *ctx, xml_node_t *node,
37 return xml_node_get_attr_value_ns(ctx, node, SPP_NS_URI, attr_name);
41 static int hs20_spp_validate(struct hs20_osu_client *ctx, xml_node_t *node,
44 struct xml_node_ctx *xctx = ctx->xml;
59 write_summary(ctx, "Unexpected SOAP method name '%s' (expected '%s')",
67 write_summary(ctx, "SPP XML schema validation failed");
74 static void add_mo_container(struct xml_node_ctx *ctx, xml_namespace_t *ns,
83 fnode = node_from_file(ctx, fname);
90 tnds = mo_to_tnds(ctx, fnode, 0, urn, "syncml:dmddf1.2");
91 xml_node_free(ctx, fnode);
95 str = xml_node_to_str(ctx, tnds);
96 xml_node_free(ctx, tnds);
100 node = xml_node_create_text(ctx, parent, ns, "moContainer", str);
102 xml_node_add_attr(ctx, node, ns, "moURN", urn);
107 static xml_node_t * build_spp_post_dev_data(struct hs20_osu_client *ctx,
115 write_summary(ctx, "Building sppPostDevData requestReason='%s'",
117 spp_node = xml_node_create_root(ctx->xml, SPP_NS_URI, "spp", &ns,
124 xml_node_add_attr(ctx->xml, spp_node, ns, "sppVersion", "1.0");
125 xml_node_add_attr(ctx->xml, spp_node, NULL, "requestReason", reason);
127 xml_node_add_attr(ctx->xml, spp_node, ns, "sessionID",
129 xml_node_add_attr(ctx->xml, spp_node, NULL, "redirectURI",
132 xml_node_create_text(ctx->xml, spp_node, ns, "supportedSPPVersions",
134 xml_node_create_text(ctx->xml, spp_node, ns, "supportedMOList",
138 add_mo_container(ctx->xml, ns, spp_node, URN_OMA_DM_DEVINFO,
140 add_mo_container(ctx->xml, ns, spp_node, URN_OMA_DM_DEVDETAIL,
147 static int process_update_node(struct hs20_osu_client *ctx, xml_node_t *pps,
158 debug_dump_node(ctx, "updateNode", update);
160 uri = get_spp_attr_value(ctx->xml, update, "managementTreeURI");
170 xml_node_get_attr_value_free(ctx->xml, uri);
176 str = xml_node_get_text(ctx->xml, update);
179 xml_node_get_attr_value_free(ctx->xml, uri);
197 tnds = xml_node_from_buf(ctx->xml, tmp);
202 tnds = xml_node_from_buf(ctx->xml, str);
203 xml_node_get_text_free(ctx->xml, str);
206 xml_node_get_attr_value_free(ctx->xml, uri);
210 unode = tnds_to_mo(ctx->xml, tnds);
211 xml_node_free(ctx->xml, tnds);
214 xml_node_get_attr_value_free(ctx->xml, uri);
218 debug_dump_node(ctx, "Parsed TNDS", unode);
220 if (get_node_uri(ctx->xml, unode, name) == NULL) {
222 xml_node_free(ctx->xml, unode);
223 xml_node_get_attr_value_free(ctx->xml, uri);
229 xml_node_free(ctx->xml, unode);
230 xml_node_get_attr_value_free(ctx->xml, uri);
235 if (ctx->fqdn == NULL) {
237 xml_node_free(ctx->xml, unode);
238 xml_node_get_attr_value_free(ctx->xml, uri);
241 fqdn_len = os_strlen(ctx->fqdn);
242 if (os_strncasecmp(pos, ctx->fqdn, fqdn_len) != 0 ||
245 ctx->fqdn);
246 xml_node_free(ctx->xml, unode);
247 xml_node_get_attr_value_free(ctx->xml, uri);
254 ctx->fqdn);
255 xml_node_free(ctx->xml, unode);
256 xml_node_get_attr_value_free(ctx->xml, uri);
263 node = get_node(ctx->xml, pps, pos);
265 parent = xml_node_get_parent(ctx->xml, node);
266 xml_node_detach(ctx->xml, node);
275 parent = get_node(ctx->xml, pps, pos);
279 xml_node_free(ctx->xml, unode);
280 xml_node_get_attr_value_free(ctx->xml, uri);
285 xml_node_add_child(ctx->xml, parent, unode);
287 xml_node_get_attr_value_free(ctx->xml, uri);
293 static int update_pps(struct hs20_osu_client *ctx, xml_node_t *update,
297 xml_node_for_each_sibling(ctx->xml, update) {
298 xml_node_for_each_check(ctx->xml, update);
299 if (process_update_node(ctx, pps, update) < 0)
303 return update_pps_file(ctx, pps_fname, pps);
307 static void hs20_sub_rem_complete(struct hs20_osu_client *ctx,
315 cmd_set_pps(ctx, pps_fname);
317 if (ctx->no_reconnect)
321 if (wpa_command(ctx->ifname, "INTERWORKING_SELECT auto") < 0)
326 static xml_node_t * hs20_spp_upload_mo(struct hs20_osu_client *ctx,
335 urn = get_spp_attr_value(ctx->xml, cmd, "moURN");
343 xml_node_get_attr_value_free(ctx->xml, urn);
346 xml_node_get_attr_value_free(ctx->xml, urn);
353 node = build_spp_post_dev_data(ctx, &ns, session_id,
357 add_mo_container(ctx->xml, ns, node, URN_HS20_PPS, pps_fname);
359 ret_node = soap_send_receive(ctx->http, node);
363 debug_dump_node(ctx, "Received response to MO upload", ret_node);
365 if (hs20_spp_validate(ctx, ret_node, "sppPostDevDataResponse") < 0) {
367 xml_node_free(ctx->xml, ret_node);
375 static int hs20_add_mo(struct hs20_osu_client *ctx, xml_node_t *add_mo,
381 debug_dump_node(ctx, "Received addMO", add_mo);
383 urn = get_spp_attr_value(ctx->xml, add_mo, "moURN");
391 xml_node_get_attr_value_free(ctx->xml, urn);
394 xml_node_get_attr_value_free(ctx->xml, urn);
396 uri = get_spp_attr_value(ctx->xml, add_mo, "managementTreeURI");
403 ret = hs20_add_pps_mo(ctx, uri, add_mo, fname, fname_len);
404 xml_node_get_attr_value_free(ctx->xml, uri);
409 static int process_spp_user_input_response(struct hs20_osu_client *ctx,
416 debug_dump_node(ctx, "addMO", add_mo);
420 if (hs20_add_mo(ctx, add_mo, fname, sizeof(fname)) < 0) {
423 ctx, session_id,
429 ret = hs20_spp_update_response(ctx, session_id, "OK", NULL);
431 hs20_sub_rem_complete(ctx, fname);
437 static xml_node_t * hs20_spp_user_input_completed(struct hs20_osu_client *ctx,
442 node = build_spp_post_dev_data(ctx, NULL, session_id,
447 ret_node = soap_send_receive(ctx->http, node);
449 if (soap_reinit_client(ctx->http) < 0)
452 node = build_spp_post_dev_data(ctx, NULL, session_id,
456 ret_node = soap_send_receive(ctx->http, node);
462 if (hs20_spp_validate(ctx, ret_node, "sppPostDevDataResponse") < 0) {
464 xml_node_free(ctx->xml, ret_node);
472 static xml_node_t * hs20_spp_get_certificate(struct hs20_osu_client *ctx,
483 res = osu_get_certificate(ctx, cmd);
487 node = build_spp_post_dev_data(ctx, &ns, session_id,
494 ret_node = soap_send_receive(ctx->http, node);
498 debug_dump_node(ctx, "Received response to certificate enrollment "
501 if (hs20_spp_validate(ctx, ret_node, "sppPostDevDataResponse") < 0) {
503 xml_node_free(ctx->xml, ret_node);
511 static int hs20_spp_exec(struct hs20_osu_client *ctx, xml_node_t *exec,
525 debug_dump_node(ctx, "exec", exec);
527 xml_node_for_each_child(ctx->xml, cmd, exec) {
528 xml_node_for_each_check(ctx->xml, cmd);
538 name = xml_node_get_localname(ctx->xml, cmd);
542 uri = xml_node_get_text(ctx->xml, cmd);
549 write_summary(ctx, "Launch browser to URI '%s'", uri);
551 xml_node_get_text_free(ctx->xml, uri);
555 write_summary(ctx, "User response in browser completed successfully");
556 *ret_node = hs20_spp_user_input_completed(ctx, id);
561 write_summary(ctx, "Failed to receive user response");
563 ctx, id, "Error occurred", "Other");
573 *ret_node = hs20_spp_upload_mo(ctx, cmd, id,
580 *ret_node = hs20_spp_get_certificate(ctx, cmd, id,
599 struct hs20_osu_client *ctx,
608 debug_dump_node(ctx, "sppPostDevDataResponse node", node);
610 status = get_spp_attr_value(ctx->xml, node, "sppStatus");
615 write_summary(ctx, "Received sppPostDevDataResponse sppStatus='%s'",
618 session_id = get_spp_attr_value(ctx->xml, node, "sessionID");
627 xml_node_for_each_child(ctx->xml, child, node) {
629 xml_node_for_each_check(ctx->xml, child);
630 debug_dump_node(ctx, "child", child);
631 name = xml_node_get_localname(ctx->xml, child);
653 res = update_pps(ctx, update, pps_fname, pps);
657 ctx, session_id,
661 hs20_sub_rem_complete(ctx, pps_fname);
681 res = update_pps(ctx, update, pps_fname, pps);
683 ctx, session_id,
687 hs20_policy_update_complete(ctx, pps_fname);
698 process_spp_user_input_response(ctx, session_id, add_mo);
716 res = hs20_spp_exec(ctx, exec, session_id,
718 /* xml_node_free(ctx->xml, node); */
721 process_spp_post_dev_data_response(ctx, use,
729 err = get_node(ctx->xml, node, "sppError");
731 code = xml_node_get_attr_value(ctx->xml, err,
735 xml_node_get_attr_value_free(ctx->xml, code);
743 xml_node_get_attr_value_free(ctx->xml, status);
744 xml_node_get_attr_value_free(ctx->xml, session_id);
745 xml_node_free(ctx->xml, node);
749 static int spp_post_dev_data(struct hs20_osu_client *ctx,
757 payload = build_spp_post_dev_data(ctx, NULL, NULL, reason);
761 ret_node = soap_send_receive(ctx->http, payload);
763 const char *err = http_get_err(ctx->http);
766 write_result(ctx, "HTTP error: %s", err);
768 write_summary(ctx, "Failed to send SOAP message");
773 if (hs20_spp_validate(ctx, ret_node, "sppPostDevDataResponse") < 0) {
775 xml_node_free(ctx->xml, ret_node);
779 process_spp_post_dev_data_response(ctx, use, ret_node,
785 void spp_sub_rem(struct hs20_osu_client *ctx, const char *address,
792 write_summary(ctx, "SPP subscription remediation");
794 os_free(ctx->server_url);
795 ctx->server_url = os_strdup(address);
797 if (soap_init_client(ctx->http, address, ctx->ca_fname,
800 spp_post_dev_data(ctx, SPP_SUBSCRIPTION_REMEDIATION,
806 static void hs20_policy_update_complete(struct hs20_osu_client *ctx,
816 cmd_set_pps(ctx, pps_fname);
819 if (wpa_command(ctx->ifname, "INTERWORKING_SELECT auto") < 0)
824 static int process_spp_exchange_complete(struct hs20_osu_client *ctx,
829 debug_dump_node(ctx, "sppExchangeComplete", node);
831 status = get_spp_attr_value(ctx->xml, node, "sppStatus");
836 write_summary(ctx, "Received sppExchangeComplete sppStatus='%s'",
839 session_id = get_spp_attr_value(ctx->xml, node, "sessionID");
842 xml_node_get_attr_value_free(ctx->xml, status);
848 xml_node_get_attr_value_free(ctx->xml, session_id);
852 xml_node_get_attr_value_free(ctx->xml, status);
857 write_summary(ctx, "Unexpected sppStatus '%s'", status);
858 xml_node_get_attr_value_free(ctx->xml, status);
863 static xml_node_t * build_spp_update_response(struct hs20_osu_client *ctx,
871 spp_node = xml_node_create_root(ctx->xml, SPP_NS_URI, "spp", &ns,
876 xml_node_add_attr(ctx->xml, spp_node, ns, "sppVersion", "1.0");
877 xml_node_add_attr(ctx->xml, spp_node, ns, "sessionID", session_id);
878 xml_node_add_attr(ctx->xml, spp_node, ns, "sppStatus", spp_status);
881 node = xml_node_create(ctx->xml, spp_node, ns, "sppError");
883 xml_node_add_attr(ctx->xml, node, NULL, "errorCode",
891 static int hs20_spp_update_response(struct hs20_osu_client *ctx,
899 write_summary(ctx, "Building sppUpdateResponse sppStatus='%s' error_code='%s'",
901 node = build_spp_update_response(ctx, session_id, spp_status,
905 ret_node = soap_send_receive(ctx->http, node);
907 if (soap_reinit_client(ctx->http) < 0)
910 node = build_spp_update_response(ctx, session_id, spp_status,
914 ret_node = soap_send_receive(ctx->http, node);
920 if (hs20_spp_validate(ctx, ret_node, "sppExchangeComplete") < 0) {
922 xml_node_free(ctx->xml, ret_node);
926 ret = process_spp_exchange_complete(ctx, ret_node);
927 xml_node_free(ctx->xml, ret_node);
932 void spp_pol_upd(struct hs20_osu_client *ctx, const char *address,
939 write_summary(ctx, "SPP policy update");
941 os_free(ctx->server_url);
942 ctx->server_url = os_strdup(address);
944 if (soap_init_client(ctx->http, address, ctx->ca_fname, cred_username,
946 spp_post_dev_data(ctx, SPP_POLICY_UPDATE, "Policy update",
952 int cmd_prov(struct hs20_osu_client *ctx, const char *url)
964 url, ctx->ca_fname ? ctx->ca_fname : "N/A");
966 os_free(ctx->server_url);
967 ctx->server_url = os_strdup(url);
969 if (soap_init_client(ctx->http, url, ctx->ca_fname, NULL, NULL, NULL,
972 spp_post_dev_data(ctx, SPP_SUBSCRIPTION_REGISTRATION,
975 return ctx->pps_cred_set ? 0 : -1;
979 int cmd_sim_prov(struct hs20_osu_client *ctx, const char *url)
988 os_free(ctx->server_url);
989 ctx->server_url = os_strdup(url);
993 if (wait_ip_addr(ctx->ifname, 15) < 0) {
997 if (soap_init_client(ctx->http, url, ctx->ca_fname, NULL, NULL, NULL,
1000 spp_post_dev_data(ctx, SPP_SUBSCRIPTION_REGISTRATION,
1003 return ctx->pps_cred_set ? 0 : -1;