static void ril_stk_terminal_response(struct ofono_stk *stk, int length, const unsigned char *resp, ofono_stk_generic_cb_t cb, void *data) { struct stk_data *sd = ofono_stk_get_data(stk); struct cb_data *cbd = cb_data_new(cb, data); struct parcel rilp; char *hex_tr = NULL; int request = RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE; guint ret; DBG(""); hex_tr = encode_hex(resp, length, 0); DBG("rilmodem terminal response: %s", hex_tr); parcel_init(&rilp); parcel_w_string(&rilp, hex_tr); g_free(hex_tr); hex_tr = NULL; ret = g_ril_send(sd->ril, request, rilp.data, rilp.size, ril_tr_cb, cbd, g_free); parcel_free(&rilp); if (ret <= 0) { g_free(cbd); CALLBACK_WITH_FAILURE(cb, data); } }
static void construct_ack_pdu(struct sms_data *d) { struct sms ackpdu; unsigned char pdu[164]; int len; int tpdu_len; DBG(""); memset(&ackpdu, 0, sizeof(ackpdu)); ackpdu.type = SMS_TYPE_DELIVER_REPORT_ACK; if (!sms_encode(&ackpdu, &len, &tpdu_len, pdu)) goto err; /* Constructing an <ackpdu> according to 27.005 Section 4.6 */ if (len != tpdu_len) goto err; d->cnma_ack_pdu = encode_hex(pdu, tpdu_len, 0); if (d->cnma_ack_pdu == NULL) goto err; d->cnma_ack_pdu_len = tpdu_len; return; err: ofono_error("Unable to construct Deliver ACK PDU"); }
static void ril_stk_envelope(struct ofono_stk *stk, int length, const unsigned char *command, ofono_stk_envelope_cb_t cb, void *data) { struct stk_data *sd = ofono_stk_get_data(stk); struct cb_data *cbd = cb_data_new(cb, data); struct parcel rilp; char *hex_envelope = NULL; int request = RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND; guint ret; DBG(""); hex_envelope = encode_hex(command, length, 0); DBG("rilmodem envelope: %s", hex_envelope); parcel_init(&rilp); parcel_w_string(&rilp, hex_envelope); g_free(hex_envelope); hex_envelope = NULL; ret = g_ril_send(sd->ril, request, rilp.data, rilp.size, ril_envelope_cb, cbd, g_free); parcel_free(&rilp); if (ret <= 0) { g_free(cbd); CALLBACK_WITH_FAILURE(cb, NULL, -1, data); } }
static void ril_cmgs(struct ofono_sms *sms, const unsigned char *pdu, int pdu_len, int tpdu_len, int mms, ofono_sms_submit_cb_t cb, void *user_data) { struct sms_data *sd = ofono_sms_get_data(sms); struct cb_data *cbd = cb_data_new(cb, user_data); struct parcel rilp; char *tpdu; int request = RIL_REQUEST_SEND_SMS; int ret, smsc_len; cbd->user = sd; DBG("pdu_len: %d, tpdu_len: %d mms: %d", pdu_len, tpdu_len, mms); /* TODO: if (mms) { ... } */ parcel_init(&rilp); parcel_w_int32(&rilp, 2); /* Number of strings */ /* SMSC address: * * smsc_len == 1, then zero-length SMSC was spec'd * RILD expects a NULL string in this case instead * of a zero-length string. */ smsc_len = pdu_len - tpdu_len; if (smsc_len > 1) { /* TODO: encode SMSC & write to parcel */ DBG("SMSC address specified (smsc_len %d); NOT-IMPLEMENTED", smsc_len); } parcel_w_string(&rilp, NULL); /* SMSC address; NULL == default */ /* TPDU: * * 'pdu' is a raw hexadecimal string * encode_hex() turns it into an ASCII/hex UTF8 buffer * parcel_w_string() encodes utf8 -> utf16 */ tpdu = encode_hex(pdu + smsc_len, tpdu_len, 0); parcel_w_string(&rilp, tpdu); ret = g_ril_send(sd->ril, request, rilp.data, rilp.size, submit_sms_cb, cbd, g_free); g_ril_append_print_buf(sd->ril, "(%s)", tpdu); g_ril_print_request(sd->ril, ret, request); parcel_free(&rilp); if (ret <= 0) { g_free(cbd); CALLBACK_WITH_FAILURE(cb, -1, user_data); } }
static void ril_sim_update_binary(struct ofono_sim *sim, int fileid, int start, int length, const unsigned char *value, const unsigned char *path, unsigned int path_len, ofono_sim_write_cb_t cb, void *data) { struct sim_data *sd = ofono_sim_get_data(sim); struct cb_data *cbd = cb_data_new(cb, data, sd); char *hex_path; struct parcel rilp; char *hex_data; int p1, p2; DBG("file 0x%04x", fileid); hex_path = get_path(g_ril_vendor(sd->ril), sd->app_type, fileid, path, path_len); if (hex_path == NULL) { ofono_error("Couldn't build SIM read info request - NULL path"); goto error; } p1 = start >> 8; p2 = start & 0xff; hex_data = encode_hex(value, length, 0); parcel_init(&rilp); parcel_w_int32(&rilp, CMD_UPDATE_BINARY); parcel_w_int32(&rilp, fileid); parcel_w_string(&rilp, hex_path); parcel_w_int32(&rilp, p1); /* P1 */ parcel_w_int32(&rilp, p2); /* P2 */ parcel_w_int32(&rilp, length); /* P3 (Lc) */ parcel_w_string(&rilp, hex_data); /* data */ parcel_w_string(&rilp, NULL); /* pin2; only for FDN/BDN */ parcel_w_string(&rilp, sd->aid_str); /* AID (Application ID) */ /* sessionId, specific to latest MTK modems (harmless for older ones) */ if (g_ril_vendor(sd->ril) == OFONO_RIL_VENDOR_MTK) parcel_w_int32(&rilp, 0); g_ril_append_print_buf(sd->ril, "(cmd=0x%02X,efid=0x%04X,path=%s," "%d,%d,%d,%s,pin2=(null),aid=%s),", CMD_UPDATE_BINARY, fileid, hex_path, p1, p2, length, hex_data, sd->aid_str); g_free(hex_path); g_free(hex_data); if (g_ril_send(sd->ril, RIL_REQUEST_SIM_IO, &rilp, ril_file_write_cb, cbd, g_free) > 0) return; error: g_free(cbd); CALLBACK_WITH_FAILURE(cb, data); }
static void set_path(struct sim_data *sd, struct parcel *rilp, const int fileid, const guchar *path, const guint path_len) { guchar db_path[6] = { 0x00 }; char *hex_path = NULL; int len = 0; DBG(""); if (path_len > 0 && path_len < 7) { memcpy(db_path, path, path_len); len = path_len; } else if (sd->app_type == RIL_APPTYPE_USIM) { len = sim_ef_db_get_path_3g(fileid, db_path); } else if (sd->app_type == RIL_APPTYPE_SIM) { len = sim_ef_db_get_path_2g(fileid, db_path); } else { ofono_error("Unsupported app_type: 0%x", sd->app_type); } if (len > 0) { hex_path = encode_hex(db_path, len, 0); parcel_w_string(rilp, (char *) hex_path); g_ril_append_print_buf(sd->ril, "%spath=%s,", print_buf, hex_path); g_free(hex_path); } else if (fileid == SIM_EF_ICCID_FILEID || fileid == SIM_EFPL_FILEID) { /* * Special catch-all for EF_ICCID (unique card ID) * and EF_PL files which exist in the root directory. * As the sim_info_cb function may not have yet * recorded the app_type for the SIM, and the path * for both files is the same for 2g|3g, just hard-code. * * See 'struct ef_db' in: * ../../src/simutil.c for more details. */ parcel_w_string(rilp, (char *) ROOTMF); } else { /* * The only known case of this is EFPHASE_FILED (0x6FAE). * The ef_db table ( see /src/simutil.c ) entry for * EFPHASE contains a value of 0x0000 for it's * 'parent3g' member. This causes a NULL path to * be returned. */ DBG("db_get_path*() returned empty path."); parcel_w_string(rilp, NULL); } }
static void output_data_hex(void) { size_t alloc_len = opt_hexdata ? strlen(opt_hexdata) : 512; cstring *s = cstr_new_sz(alloc_len); ser_bp_tx(s, &tx); char hexstr[(s->len * 2) + 1]; encode_hex(hexstr, s->str, s->len); printf("%s\n", hexstr); cstr_free(s, true); }
static void inf_pin_retries_cb(struct ril_msg *message, gpointer user_data) { struct cb_data *cbd = user_data; ofono_sim_pin_retries_cb_t cb = cbd->cb; struct sim_data *sd = cbd->user; struct parcel rilp; int32_t *data; int len; char *hex_dump; int expected; DBG(""); if (message->error != RIL_E_SUCCESS) { ofono_error("Reply failure: %s", ril_error_to_string(message->error)); goto error; } g_ril_init_parcel(message, &rilp); data = parcel_r_raw(&rilp, &len); if (data == NULL) { ofono_error("%s: malformed parcel", __func__); goto error; } hex_dump = encode_hex((unsigned char *) data, len, '\0'); g_ril_append_print_buf(sd->ril, "{%d,%s}", len, hex_dump); g_ril_print_response(sd->ril, message); g_free(hex_dump); expected = sizeof(int32_t) * 5; if (len < expected) { ofono_error("%s: reply too small", __func__); g_free(data); goto error; } /* First integer is INF_RIL_REQUEST_OEM_GET_REMAIN_SIM_PIN_ATTEMPTS */ sd->retries[OFONO_SIM_PASSWORD_SIM_PIN] = data[1]; sd->retries[OFONO_SIM_PASSWORD_SIM_PIN2] = data[2]; sd->retries[OFONO_SIM_PASSWORD_SIM_PUK] = data[3]; sd->retries[OFONO_SIM_PASSWORD_SIM_PUK2] = data[4]; g_free(data); CALLBACK_WITH_SUCCESS(cb, sd->retries, cbd->data); return; error: CALLBACK_WITH_FAILURE(cb, NULL, cbd->data); }
void g_ril_request_oem_hook_raw(GRil *gril, const void *payload, size_t length, struct parcel *rilp) { char *hex_dump = NULL; parcel_init(rilp); parcel_w_raw(rilp, payload, length); if (payload != NULL) hex_dump = encode_hex(payload, length, '\0'); g_ril_append_print_buf(gril, "(%s)", hex_dump? hex_dump: "(null)"); g_free(hex_dump); }
gboolean g_ril_request_sim_write_binary(GRil *gril, const struct req_sim_write_binary *req, struct parcel *rilp) { char *hex_data; int p1, p2; parcel_init(rilp); parcel_w_int32(rilp, CMD_UPDATE_BINARY); parcel_w_int32(rilp, req->fileid); g_ril_append_print_buf(gril, "(cmd=0x%02X,efid=0x%04X,", CMD_UPDATE_BINARY, req->fileid); if (set_path(gril, req->app_type, rilp, req->fileid, req->path, req->path_len) == FALSE) goto error; p1 = req->start >> 8; p2 = req->start & 0xff; hex_data = encode_hex(req->data, req->length, 0); parcel_w_int32(rilp, p1); /* P1 */ parcel_w_int32(rilp, p2); /* P2 */ parcel_w_int32(rilp, req->length); /* P3 (Lc) */ parcel_w_string(rilp, hex_data); /* data */ parcel_w_string(rilp, NULL); /* pin2; only for FDN/BDN */ parcel_w_string(rilp, req->aid_str); /* AID (Application ID) */ /* sessionId, specific to latest MTK modems (harmless for older ones) */ if (g_ril_vendor(gril) == OFONO_RIL_VENDOR_MTK) parcel_w_int32(rilp, 0); g_ril_append_print_buf(gril, "%s%d,%d,%d,%s,pin2=(null),aid=%s)", print_buf, p1, p2, req->length, hex_data, req->aid_str); g_free(hex_data); return TRUE; error: return FALSE; }
static char *get_path(int vendor, guint app_type, const int fileid, const unsigned char *path, unsigned int path_len) { unsigned char db_path[6] = { 0x00 }; unsigned char *comm_path = db_path; int len = 0; if (path_len > 0 && path_len < 7) { memcpy(db_path, path, path_len); len = path_len; goto done; } switch (app_type) { case RIL_APPTYPE_USIM: len = sim_ef_db_get_path_3g(fileid, db_path); break; case RIL_APPTYPE_SIM: len = sim_ef_db_get_path_2g(fileid, db_path); break; default: ofono_error("Unsupported app_type: 0%x", app_type); return NULL; } done: /* * db_path contains the ID of the MF, but MediaTek modems return an * error if we do not remove it. Other devices work the other way * around: they need the MF in the path. In fact MTK behaviour seem to * be the right one: to have the MF in the file is forbidden following * ETSI TS 102 221, section 8.4.2 (we are accessing the card in mode * "select by path from MF", see 3gpp 27.007, +CRSM). */ if (vendor == OFONO_RIL_VENDOR_MTK && len >= (int) ROOTMF_SZ && memcmp(db_path, ROOTMF, ROOTMF_SZ) == 0) { comm_path = db_path + ROOTMF_SZ; len -= ROOTMF_SZ; } if (len == 0) return NULL; return encode_hex(comm_path, len, 0); }
static void bp_json_set_new_script(json_t *obj_parent, const char *key, cstring *s) { json_t *obj = json_object(); assert(obj != NULL); int rc = json_object_set_new(obj_parent, key, obj); assert(rc == 0); char raw_hexstr[(s->len * 2) + 1]; encode_hex(raw_hexstr, s->str, s->len); json_t *hexstr = json_string(raw_hexstr); assert(hexstr != NULL); rc = json_object_set_new(obj, "hex", hexstr); assert(rc == 0); }
static void test_hex(void) { int i; char raw_data[32]; size_t raw_length; uint8_t *encoded_data; uint64_t encoded_length; uint8_t *decoded_data; uint64_t decoded_length; uint8_t expected_data[32]; uint64_t expected_length; for(i = 0; i < 256; i++) { raw_length = sprintf(raw_data, "%c%c%c", i, i, i); encoded_data = encode_hex((uint8_t*)raw_data, raw_length, &encoded_length); expected_length = sprintf((char*)expected_data, "%02x%02x%02x", i, i, i); test_check_memory("encode_hex", expected_data, expected_length, encoded_data, encoded_length); free(encoded_data); } for(i = 0; i < 256; i++) { raw_length = sprintf(raw_data, "%02x%02x%02x", (uint8_t)(i - 1), (uint8_t)(i), (uint8_t)(i + 1)); decoded_data = decode_hex((uint8_t*)raw_data, raw_length, &decoded_length); expected_length = sprintf((char*)expected_data, "%c%c%c", i - 1, i, i + 1); test_check_memory("decode_hex", expected_data, expected_length, decoded_data, decoded_length); free(decoded_data); } /* Side-case: odd numbers of hex digits. */ decoded_data = decode_hex((uint8_t*)"41424", 5, &decoded_length); test_check_memory("decode_hex ('41424')", (uint8_t*)"AB", 2, decoded_data, decoded_length); free(decoded_data); /* Side-case: non-hex characters in the string. */ decoded_data = decode_hex((uint8_t*)"414z4", 5, &decoded_length); test_check_memory("decode_hex ('414z4')", (uint8_t*)"A", 1, decoded_data, decoded_length); free(decoded_data); decoded_data = decode_hex((uint8_t*)"4141z4141", 9, &decoded_length); test_check_memory("decode_hex ('4141z4141')", (uint8_t*)"AAAA", 4, decoded_data, decoded_length); free(decoded_data); }
static void ril_sms_submit(struct ofono_sms *sms, const unsigned char *pdu, int pdu_len, int tpdu_len, int mms, ofono_sms_submit_cb_t cb, void *data) { struct ril_sms *sd = ril_sms_get_data(sms); GRilIoRequest *req = grilio_request_new(); int smsc_len; char *tpdu; DBG("pdu_len: %d, tpdu_len: %d mms: %d", pdu_len, tpdu_len, mms); grilio_request_append_int32(req, 2); /* Number of strings */ /* SMSC address: * * smsc_len == 1, then zero-length SMSC was spec'd * RILD expects a NULL string in this case instead * of a zero-length string. */ smsc_len = pdu_len - tpdu_len; if (smsc_len > 1) { /* TODO: encode SMSC & write to parcel */ DBG("SMSC address specified (smsc_len %d); NOT-IMPLEMENTED", smsc_len); } grilio_request_append_utf8(req, NULL); /* default SMSC address */ /* TPDU: * * 'pdu' is a raw hexadecimal string * encode_hex() turns it into an ASCII/hex UTF8 buffer * grilio_request_append_utf8() encodes utf8 -> utf16 */ tpdu = encode_hex(pdu + smsc_len, tpdu_len, 0); grilio_request_append_utf8(req, tpdu); DBG("%s", tpdu); grilio_queue_send_request_full(sd->q, req, RIL_REQUEST_SEND_SMS, ril_sms_submit_cb, ril_sms_cbd_free, ril_sms_cbd_new(sd, cb, data)); grilio_request_unref(req); g_free(tpdu); }
gboolean g_ril_request_sim_write_record(GRil *gril, const struct req_sim_write_record *req, struct parcel *rilp) { char *hex_data; int p2; parcel_init(rilp); parcel_w_int32(rilp, CMD_UPDATE_RECORD); parcel_w_int32(rilp, req->fileid); g_ril_append_print_buf(gril, "(cmd=0x%02X,efid=0x%04X,", CMD_UPDATE_RECORD, req->fileid); if (set_path(gril, req->app_type, rilp, req->fileid, req->path, req->path_len) == FALSE) goto error; p2 = get_sim_record_access_p2(req->mode); hex_data = encode_hex(req->data, req->length, 0); parcel_w_int32(rilp, req->record); /* P1 */ parcel_w_int32(rilp, p2); /* P2 (access mode) */ parcel_w_int32(rilp, req->length); /* P3 (Lc) */ parcel_w_string(rilp, hex_data); /* data */ parcel_w_string(rilp, NULL); /* pin2; only for FDN/BDN */ parcel_w_string(rilp, req->aid_str); /* AID (Application ID) */ g_ril_append_print_buf(gril, "%s%d,%d,%d,%s,pin2=(null),aid=%s)", print_buf, req->record, p2, req->length, hex_data, req->aid_str); g_free(hex_data); return TRUE; error: return FALSE; }
int _tmain(int argc, _TCHAR* argv[]) { char hex[BUFFER_SIZE]; char b64Enc[BUFFER_SIZE]; char md5Hex[BUFFER_SIZE]; char md5B64[BUFFER_SIZE]; char sha1Hex[BUFFER_SIZE]; char sha1B64[BUFFER_SIZE]; if ( argc < 2 ){ printf("usage: CreateMD5Hash <string>\n"); exit(-1); } BYTE *str = (BYTE*)argv[1]; size_t strSize = strlen(argv[1]); size_t hexSize = encode_hex(str, strSize, hex, sizeof(hex)); size_t b64EncSize = encode_base64(str, strSize, b64Enc, sizeof(b64Enc)); size_t md5HexSize = md5_hex(str, strSize, md5Hex, sizeof(md5Hex)); size_t md5B64Size = md5_base64(str, strSize, md5B64, sizeof(md5B64)); size_t sha1HexSize = sha1_hex(str, strSize, sha1Hex, sizeof(sha1Hex)); size_t sha1B64Size = sha1_base64(str, strSize, sha1B64, sizeof(sha1B64)); printf( "'%s':%d\n" " Hex:\t\t'%s':%d\n" " B64:\t\t'%s':%d\n" " MD5Hex:\t'%s':%d\n" " MD5B64:\t'%s':%d\n" " SHA1Hex:\t'%s':%d\n" " SHA1B64:\t'%s':%d\n", str, strSize, hex, hexSize, b64Enc, b64EncSize, md5Hex, md5HexSize, md5B64, md5B64Size, sha1Hex, sha1HexSize, sha1B64, sha1B64Size ); return 0; }
static void test_submit_encode() { struct sms sms; unsigned char *decoded_pdu; long pdu_len; gboolean ret; unsigned char pdu[176]; int encoded_pdu_len; int encoded_tpdu_len; char *encoded_pdu; decoded_pdu = decode_hex(simple_submit, -1, &pdu_len, 0); g_assert(decoded_pdu); g_assert(pdu_len == (long)strlen(simple_submit) / 2); ret = sms_decode(decoded_pdu, pdu_len, TRUE, 23, &sms); g_free(decoded_pdu); g_assert(ret); g_assert(sms.type == SMS_TYPE_SUBMIT); ret = sms_encode(&sms, &encoded_pdu_len, &encoded_tpdu_len, pdu); if (g_test_verbose()) { int i; for (i = 0; i < encoded_pdu_len; i++) g_print("%02X", pdu[i]); g_print("\n"); } g_assert(ret); g_assert(encoded_tpdu_len == 23); g_assert(encoded_pdu_len == pdu_len); encoded_pdu = encode_hex(pdu, encoded_pdu_len, 0); g_assert(strcmp(simple_submit, encoded_pdu) == 0); g_free(encoded_pdu); }
void g_ril_request_sms_cmgs(GRil *gril, const struct req_sms_cmgs *req, struct parcel *rilp) { int smsc_len; char *tpdu; parcel_init(rilp); parcel_w_int32(rilp, 2); /* Number of strings */ /* * SMSC address: * * smsc_len == 1, then zero-length SMSC was spec'd * RILD expects a NULL string in this case instead * of a zero-length string. */ smsc_len = req->pdu_len - req->tpdu_len; /* TODO: encode SMSC & write to parcel */ if (smsc_len > 1) ofono_error("SMSC address specified (smsc_len %d); " "NOT-IMPLEMENTED", smsc_len); parcel_w_string(rilp, NULL); /* SMSC address; NULL == default */ /* * TPDU: * * 'pdu' is a raw hexadecimal string * encode_hex() turns it into an ASCII/hex UTF8 buffer * parcel_w_string() encodes utf8 -> utf16 */ tpdu = encode_hex(req->pdu + smsc_len, req->tpdu_len, 0); parcel_w_string(rilp, tpdu); g_ril_append_print_buf(gril, "(%s)", tpdu); g_free(tpdu); }
struct reply_oem_hook *g_ril_reply_oem_hook_raw(GRil *gril, const struct ril_msg *message) { struct reply_oem_hook *reply = NULL; struct parcel rilp; reply = g_try_malloc0(sizeof(*reply)); if (reply == NULL) { ofono_error("%s: out of memory", __func__); goto end; } g_ril_init_parcel(message, &rilp); reply->data = parcel_r_raw(&rilp, &(reply->length)); if (rilp.malformed) { ofono_error("%s: malformed parcel", __func__); g_ril_reply_free_oem_hook(reply); reply = NULL; goto end; } g_ril_append_print_buf(gril, "{%d", reply->length); if (reply->data != NULL) { char *hex_dump; hex_dump = encode_hex(reply->data, reply->length, '\0'); g_ril_append_print_buf(gril, "%s,%s", print_buf, hex_dump); g_free(hex_dump); } g_ril_append_print_buf(gril, "%s}", print_buf); g_ril_print_response(gril, message); end: return reply; }
int config_to_string(struct config *config, char *org_buf, int org_buf_sz) { int r = 0; char *buf = org_buf; int buf_sz = org_buf_sz; r = write_line(&buf, &buf_sz, "# This file is automatically generated. Do not edit.\n"); if(r < 0) goto error; char hostname[256]; gethostname(hostname, sizeof(hostname)); time_t now = time(NULL); r = write_line(&buf, &buf_sz, "#Created on %s, %s\n\n", strip(ctime(&now)), hostname); if(r < 0) goto error; struct rb_node *node = rb_first(&config->proxies); while(node) { struct st_proxy *proxy = container_of(node, struct st_proxy, node); node = rb_next(node); r = write_line(&buf, &buf_sz, "proxy\t%s:%i\n", proxy->host, proxy->port); if(r < 0) goto error; } r = write_line(&buf, &buf_sz, "\n"); if(r < 0) goto error; node = rb_first(&config->servers); while(node) { struct st_server *server = container_of(node, struct st_server, node); node = rb_next(node); r = write_line(&buf, &buf_sz, "server\t%s:%i, %i, %s\n", server->host, server->port, server->weight, encode_hex(server->key, server->key_sz)); if(r < 0) goto error; } return(org_buf_sz - buf_sz); error: log_error("buffer too small"); return(-1); }
static void test_deliver_encode() { struct sms sms; unsigned char *decoded_pdu; long pdu_len; gboolean ret; unsigned char pdu[176]; int encoded_pdu_len; int encoded_tpdu_len; char *encoded_pdu; decoded_pdu = decode_hex(simple_deliver, -1, &pdu_len, 0); g_assert(decoded_pdu); g_assert(pdu_len == (long)strlen(simple_deliver) / 2); ret = sms_decode(decoded_pdu, pdu_len, FALSE, 30, &sms); g_free(decoded_pdu); g_assert(ret); g_assert(sms.type == SMS_TYPE_DELIVER); ret = sms_encode(&sms, &encoded_pdu_len, &encoded_tpdu_len, pdu); if (g_test_verbose()) { int i; for (i = 0; i < encoded_pdu_len; i++) g_print("%02X", pdu[i]); g_print("\n"); } g_assert(ret); g_assert(encoded_tpdu_len == 30); g_assert(encoded_pdu_len == pdu_len); encoded_pdu = encode_hex(pdu, encoded_pdu_len, 0); g_assert(strcmp(simple_deliver, encoded_pdu) == 0); g_free(encoded_pdu); decoded_pdu = decode_hex(alnum_sender, -1, &pdu_len, 0); g_assert(decoded_pdu); g_assert(pdu_len == (long)strlen(alnum_sender) / 2); ret = sms_decode(decoded_pdu, pdu_len, FALSE, 27, &sms); g_free(decoded_pdu); g_assert(ret); g_assert(sms.type == SMS_TYPE_DELIVER); ret = sms_encode(&sms, &encoded_pdu_len, &encoded_tpdu_len, pdu); if (g_test_verbose()) { int i; for (i = 0; i < encoded_pdu_len; i++) g_print("%02X", pdu[i]); g_print("\n"); } g_assert(ret); g_assert(encoded_tpdu_len == 27); g_assert(encoded_pdu_len == pdu_len); encoded_pdu = encode_hex(pdu, encoded_pdu_len, 0); g_assert(strcmp(alnum_sender, encoded_pdu) == 0); g_free(encoded_pdu); }
void setcontent (xmlNodePtr n, CArray data) { CArray d = encode_hex (data); xmlNodeSetContent (n, (const xmlChar *) d.array ()); }
std::ostream& operator<<(std::ostream& stream, const short_hash& hash) { stream << encode_hex(hash); return stream; }
std::ostream& operator<<(std::ostream& stream, const hash_digest& hash) { stream << encode_hex(hash); return stream; }
static int check_send_transdtl() { const int TRANSDTL_SLEEP_TM = 10; const int HEART_SLEEP_TM = 30; char recv_buf[1024] = {0}; int recv_len = 0; int ret =0; LOG((LOG_DEBUG,"进入check_send_transdtl")); while (p16pos.app_running) { memset(recv_buf,0,1024); recv_len = 0; ret = send_rt_transdtl_data(recv_buf,&recv_len); if(ret == 0)//发送实时流水成功的情况 { if(recv_len>0) { p16_recv_rt_transdtl_package recv_package; memset(&recv_package,0,sizeof(recv_package)); parse_recv_data(recv_buf,3,&recv_package); if(recv_package.data.ret_code == 0) { LOG((LOG_DEBUG,"上传实时流水成功")); } else { LOG((LOG_DEBUG,"上传实时流水失败,pos机不再上传流水")); } } LOG((LOG_DEBUG,"=========================sleep %d========================",TRANSDTL_SLEEP_TM)); sleep(TRANSDTL_SLEEP_TM); } else//没有交易流水需要发送 { //发送心跳 send_heart_data(recv_buf,&recv_len); if(recv_len>0) { //分析接收的数据 p16_recv_heart_package recv_heart; parse_recv_data(recv_buf,0,&recv_heart); LOG((LOG_DEBUG,"心跳收到的系统版本号:")); p16dump_hex(LOG_DEBUG,recv_heart.data.cfgverno,4); LOG((LOG_DEBUG,"心跳收到的服务器时间:")); p16dump_hex(LOG_DEBUG,recv_heart.data.server_datetime,6); LOG((LOG_DEBUG,"心跳收到的服务器黑名单版本号:")); p16dump_hex(LOG_DEBUG,recv_heart.data.current_blacklist_version,6); LOG((LOG_DEBUG,"当前系统的黑名单版本号:")); p16dump_hex(LOG_DEBUG,p16pos.pos_blacklist_version, 6); if(memcmp(recv_heart.data.current_blacklist_version,p16pos.pos_blacklist_version, 6)>0) { LOG((LOG_DEBUG,"心跳收到的黑名单版本号大于当前系统的黑名单版本号,执行下载黑名单函数!!")); //下载黑名单 memset(recv_buf,0,1024); recv_len = 0; send_download_blacklist_data(recv_buf,&recv_len); if(recv_len>0) { p16_recv_blacklist_package recv_package; parse_recv_data(recv_buf, 2, &recv_package); if(recv_package.data.list_cnt>0) { //有黑名单 LOG((LOG_DEBUG,"有黑名单%d条",recv_package.data.list_cnt)); ret = save_blackcard_record(recv_package.data.list_cnt, recv_package.data.blacklist_list); if(ret) { //致命错误,联系管理员 disp_msg("操作数据库失败,请联系管理员",10); return -1; } //更新系统黑名单版本号 char pos_blacklist_version[13] = {0}; encode_hex(recv_package.data.sys_list_version, 6, pos_blacklist_version); //更新系统版本号 ret = update_config("dev.pos_blacklist_version",pos_blacklist_version); if(ret) { //致命错误 return -2; } memcpy(p16pos.pos_blacklist_version, recv_package.data.sys_list_version, 6); LOG((LOG_DEBUG,"更新版本号为:%s",pos_blacklist_version)); LOG((LOG_DEBUG,"=======================================================")); } } } } LOG((LOG_DEBUG,"=========================sleep %d========================",HEART_SLEEP_TM)); sleep(HEART_SLEEP_TM); } } return 0; }
static gboolean set_path(GRil *ril, guint app_type, struct parcel *rilp, const int fileid, const guchar *path, const guint path_len) { unsigned char db_path[6] = { 0x00 }; unsigned char *comm_path = db_path; char *hex_path = NULL; int len = 0; if (path_len > 0 && path_len < 7) { memcpy(db_path, path, path_len); len = path_len; } else if (app_type == RIL_APPTYPE_USIM) { len = sim_ef_db_get_path_3g(fileid, db_path); } else if (app_type == RIL_APPTYPE_SIM) { len = sim_ef_db_get_path_2g(fileid, db_path); } else { ofono_error("Unsupported app_type: 0%x", app_type); return FALSE; } /* * db_path contains the ID of the MF, but MediaTek modems return an * error if we do not remove it. Other devices work the other way * around: they need the MF in the path. In fact MTK behaviour seem to * be the right one: to have the MF in the file is forbidden following * ETSI TS 102 221, section 8.4.2 (we are accessing the card in mode * "select by path from MF", see 3gpp 27.007, +CRSM). */ if (g_ril_vendor(ril) == OFONO_RIL_VENDOR_MTK && len >= (int) ROOTMF_SZ && memcmp(db_path, ROOTMF, ROOTMF_SZ) == 0) { comm_path = db_path + ROOTMF_SZ; len -= ROOTMF_SZ; } if (len > 0) { hex_path = encode_hex(comm_path, len, 0); parcel_w_string(rilp, hex_path); g_ril_append_print_buf(ril, "%spath=%s,", print_buf, hex_path); g_free(hex_path); } else { /* * The only known case of this is EFPHASE_FILED (0x6FAE). * The ef_db table ( see /src/simutil.c ) entry for * EFPHASE contains a value of 0x0000 for it's * 'parent3g' member. This causes a NULL path to * be returned. * (EF_PHASE does not exist for USIM) */ parcel_w_string(rilp, NULL); g_ril_append_print_buf(ril, "%spath=(null),", print_buf); } return TRUE; }
static void test_decode_encode() { const char *sms = hex_packed; unsigned char *decoded, *packed; char *utf8, *hex_packed; unsigned char *gsm, *gsm_encoded; long hex_decoded_size; long unpacked_size, packed_size; long gsm_encoded_size; long i; if (g_test_verbose()) g_print("Size of the orig string: %u\n", (unsigned int)strlen(sms)); decoded = decode_hex(sms, -1, &hex_decoded_size, 0); g_assert(decoded != NULL); if (g_test_verbose()) g_print("Decode to %ld bytes\n", hex_decoded_size); if (g_test_verbose()) { g_print("%s\n", sms); for (i = 0; i < hex_decoded_size; i++) g_print("%02X", decoded[i]); g_print("\n"); } gsm = unpack_7bit(decoded, hex_decoded_size, 0, FALSE, reported_text_size, &unpacked_size, 0xff); g_assert(gsm != NULL); if (g_test_verbose()) g_print("String unpacked to %ld bytes\n", unpacked_size); utf8 = convert_gsm_to_utf8(gsm, -1, NULL, NULL, 0xff); g_assert(utf8 != NULL); if (g_test_verbose()) g_print("String is: -->%s<--\n", utf8); g_assert(strcmp(utf8, expected) == 0); gsm_encoded = convert_utf8_to_gsm(utf8, -1, NULL, &gsm_encoded_size, 0xff); g_assert(gsm_encoded != NULL); if (g_test_verbose()) g_print("Converted back to GSM string of %ld bytes\n", gsm_encoded_size); g_assert(gsm_encoded[gsm_encoded_size] == 0xff); g_assert(gsm_encoded_size == unpacked_size); g_assert(memcmp(gsm_encoded, gsm, gsm_encoded_size) == 0); g_free(utf8); g_free(gsm); packed = pack_7bit(gsm_encoded, -1, 0, FALSE, &packed_size, 0xff); g_free(gsm_encoded); g_assert(packed != NULL); if (g_test_verbose()) g_print("Packed GSM to size of %ld bytes\n", packed_size); if (g_test_verbose()) { for (i = 0; i < packed_size; i++) g_print("%02X", packed[i]); g_print("\n"); } g_assert(packed_size == hex_decoded_size); g_assert(memcmp(packed, decoded, packed_size) == 0); g_free(decoded); hex_packed = encode_hex(packed, packed_size, 0); g_assert(hex_packed != NULL); g_free(packed); if (g_test_verbose()) g_print("Hex encoded packed to size %ld bytes\n", (long)strlen(hex_packed)); g_assert(strlen(hex_packed) == strlen(sms)); g_assert(strcmp(hex_packed, sms) == 0); g_free(hex_packed); }
std::string hash(std::string const & input) { std::array<unsigned char, 32> hash{}; gnutls_hash_fast(GNUTLS_DIG_SHA256, input.c_str(), input.length(), hash.data()); return encode_hex({hash.cbegin(), hash.cend()}); }