int stobFile(const char *inFilename, const char *outFilename, DFError **error) { char *str = readString(inFilename,error); if (str == NULL) return 0;; DFBuffer *bin = stringToBinary(str); int ok = writeData(bin,outFilename,error); DFBufferRelease(bin); free(str); return ok; }
int sendSimIOCmdUICC(const RIL_SIM_IO_v6 *ioargs, ATResponse **atresponse, RIL_SIM_IO_Response *sr) { int err; int resplen; char *line, *resp; char *data = NULL; unsigned short lc = simIOGetLogicalChannel(); unsigned char sw1, sw2; if (lc == 0) return -EIO; memset(sr, 0, sizeof(*sr)); switch (ioargs->command) { case 0xC0: /* Get response */ /* Convert Get response to Select. */ asprintf(&data, "00A4000402%.4X00", ioargs->fileid); break; case 0xB0: /* Read binary */ case 0xB2: /* Read record */ asprintf(&data, "00%.2X%.2X%.2X%.2X", (unsigned char)ioargs->command, (unsigned char)ioargs->p1, (unsigned char)ioargs->p2, (unsigned char)ioargs->p3); break; case 0xD6: /* Update binary */ case 0xDC: /* Update record */ if (!ioargs->data) { err = -EINVAL; goto finally; } asprintf(&data, "00%.2X%.2X%.2X%.2X%s", (unsigned char)ioargs->command, (unsigned char)ioargs->p1, (unsigned char)ioargs->p2, (unsigned char)ioargs->p3, ioargs->data); break; default: return -ENOTSUP; } if (data == NULL) { err = -ENOMEM; goto finally; } err = simIOSelectPath(ioargs->path, ioargs->fileid); if (err < 0) goto finally; err = at_send_command_singleline("AT+CGLA=%d,%d,\"%s\"", "+CGLA:", atresponse, lc, strlen(data), data); if (err != AT_NOERROR) goto finally; line = (*atresponse)->p_intermediates->line; err = at_tok_start(&line); if (err < 0) goto finally; err = at_tok_nextint(&line, &resplen); if (err < 0) goto finally; err = at_tok_nextstr(&line, &resp); if (err < 0) goto finally; if ((resplen < 4) || ((size_t)resplen != strlen(resp))) { err = -EINVAL; goto finally; } err = stringToBinary(&resp[resplen - 4], 2, &sw1); if (err < 0) goto finally; err = stringToBinary(&resp[resplen - 2], 2, &sw2); if (err < 0) goto finally; sr->sw1 = sw1; sr->sw2 = sw2; resp[resplen - 4] = 0; sr->simResponse = resp; finally: free(data); return err; }