int ssm_oem_driver_intf(int cmd, char *mode, int len) { int rc, req_len, resp_len; struct tzapp_get_mode_info_req *get_mode_req; struct tzapp_get_mode_info_rsp *get_mode_resp; /* */ if (!ssm_drv) return -ENODEV; mutex_lock(&ssm_drv->mutex); if (ssm_drv->app_status == RETRY) { /* */ rc = ssm_load_app(ssm_drv); if (rc) { rc = -ENODEV; goto unlock; } } else if (ssm_drv->app_status == FAILED) { rc = -ENODEV; goto unlock; } /* */ if (!ssm_drv->ready) { rc = smd_open(ssm_drv->channel_name, &ssm_drv->ch, ssm_drv, modem_request); if (rc) { rc = -EAGAIN; goto unlock; } else ssm_drv->ready = true; } /* */ if (!ssm_drv->key_status) { rc = -EAGAIN; goto unlock; } /* */ rc = 0; switch (cmd) { case SSM_READY: break; case SSM_MODE_INFO_READY: ssm_drv->update_status = RETRY; /* */ req_len = sizeof(struct tzapp_get_mode_info_req); resp_len = sizeof(struct tzapp_get_mode_info_rsp); setup_cmd_rsp_buffers(ssm_drv->qseecom_handle, (void **)&get_mode_req, &req_len, (void **)&get_mode_resp, &resp_len); get_mode_req->tzapp_ssm_cmd = GET_ENC_MODE; rc = qseecom_set_bandwidth(ssm_drv->qseecom_handle, 1); if (rc) { ssm_drv->update_status = FAILED; dev_err(ssm_drv->dev, "set bandwidth failed\n"); rc = -EIO; break; } rc = qseecom_send_command(ssm_drv->qseecom_handle, (void *)get_mode_req, req_len, (void *)get_mode_resp, resp_len); if (rc || get_mode_resp->status) { ssm_drv->update_status = FAILED; break; } rc = qseecom_set_bandwidth(ssm_drv->qseecom_handle, 0); if (rc) { ssm_drv->update_status = FAILED; dev_err(ssm_drv->dev, "clear bandwidth failed\n"); rc = -EIO; break; } if (get_mode_resp->enc_mode_len > ENC_MODE_MAX_SIZE) { ssm_drv->update_status = FAILED; rc = -EINVAL; break; } /* */ rc = update_modem(SSM_ATOM_MODE_UPDATE, ssm_drv, get_mode_resp->enc_mode_len, get_mode_resp->enc_mode_info); if (rc) ssm_drv->update_status = FAILED; break; case SSM_SET_MODE: ssm_drv->update_status = RETRY; if (len > ENC_MODE_MAX_SIZE) { ssm_drv->update_status = FAILED; rc = -EINVAL; break; } memcpy(ssm_drv->resp->enc_mode_info, mode, len); ssm_drv->resp->enc_mode_len = len; /* */ rc = update_modem(SSM_ATOM_MODE_UPDATE, ssm_drv, ssm_drv->resp->enc_mode_len, ssm_drv->resp->enc_mode_info); if (rc) ssm_drv->update_status = FAILED; break; case SSM_GET_MODE_STATUS: rc = ssm_drv->update_status; break; default: rc = -EINVAL; dev_err(ssm_drv->dev, "Invalid command\n"); break; }; unlock: mutex_unlock(&ssm_drv->mutex); return rc; }
int main(int argc, char *argv[]) { int ret_val = -1; int tries = 0; unsigned char settings[2]; parse_command_line(argc, argv); while (ret_val != 0 && tries < 1) { tries++; ret_val = open_modem(); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error opening modem, please run the program again\n"); return finish_up(-1); } ret_val = -1; printf("Step 1 Find the modem\n"); while (ret_val != 0 && tries < 1) { tries++; ret_val = find_modem(); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error finding modem, please run the program again\n"); return finish_up(-1); } ret_val = -1; // Steps 2-4 Get the modem settings while (tries < 3) { printf("Step %d get the modem settings\n", tries + 2); tries++; ret_val = settings_modem(settings); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error getting modem settings, please run the program again\n"); return finish_up(-1); } ret_val = -1; if (settings[0] != 0x03 || settings[1] != 0x03) { if (debug) printf("Looks like modem needs resetting\n"); reboot_modem(); settings_modem(settings); settings_modem(settings); } ret_val = -1; // Step 5 Update basis printf("Step 5 updating the basis\n"); while (ret_val != 0 && tries < 2) { tries++; ret_val = update_basis(); } tries = 0; ret_val = -1; // Step 6 Update Modem printf("Step 6 updating the modem\n"); while (ret_val != 0 && tries < 1) { tries++; ret_val = update_modem(); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error updating modem, please run the program again\n"); return finish_up(-1); } ret_val = -1; // Step 7 Get modem settings printf("Step 7 getting the modem settings\n"); while (tries < 1) { tries++; ret_val = settings_modem(settings); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error getting modem settings, please run the program again\n"); return finish_up(-1); } ret_val = -1; // Step 8 Get basis settings printf("Step 8 getting the basis settings\n"); while (ret_val != 0 && tries < 2) { tries++; ret_val = settings_basis(settings); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error getting basis settings, please run the program again\n"); return finish_up(-1); } ret_val = -1; // Step 9 and 10 Get modem settings while (tries < 2) { printf("Step %d, getting the modem settings\n", tries + 9); tries++; ret_val = settings_modem(settings); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error getting modem settings, please run the program again\n"); return finish_up(-1); } ret_val = -1; // Step 11 Set basis filter printf("Step 11 setting the basis filter\n"); while (ret_val != 0 && tries < 1) { tries++; ret_val = set_filter_basis(); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error setting basis filter, please run the program again\n"); return finish_up(-1); } ret_val = -1; // Step 12 Set modem filter printf("Step 12 setting the modem filter\n"); while (ret_val != 0 && tries < 1) { tries++; ret_val = set_filter_modem(); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error setting modem filter, please run the program again\n"); return finish_up(-1); } ret_val = -1; // Step 13 Reboot basis printf("Step 13 rebooting basis \n"); while (ret_val != 0 && tries < 1) { tries++; ret_val = reboot_basis(); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error rebooting basis, please run the program again\n"); return finish_up(-1); } ret_val = -1; // Step 14 Reboot modem printf("Step 14, rebooting the modem \n"); while (ret_val != 0 && tries < 1) { tries++; ret_val = reboot_modem(); } tries = 0; if (ret_val && !ignore_errors) { printf ("Error rebooting modem, please run the program again\n"); return finish_up(-1); } return finish_up(0); }