コード例 #1
0
static int
asimcard_ef_update_dedicated( SimFile ef, char* data )
{
    if (data == NULL || (strlen(data) % 2) == 1) {
        D("ERROR: Length of data should be even.\n");
        return -1;
    }

    if (ef == NULL || ef->any.type != SIM_FILE_EF_DEDICATED) {
        D("ERROR: The type of EF is not SIM_FILE_EF_DEDICATED.\n");
        return -1;
    }

    SimFileEFDedicated dedicated = (SimFileEFDedicated) ef;

    if (dedicated->length != (strlen(data) / 2)) {
        if (dedicated->data) {
            free(dedicated->data);
        }

        dedicated->length = strlen(data) / 2;
        dedicated->data   = (cbytes_t) malloc(dedicated->length * sizeof(byte_t));
        memset(dedicated->data, 0xff, dedicated->length * sizeof(byte_t));
    }

    return gsm_hex_to_bytes((cbytes_t) data, strlen(data), dedicated->data);
}
コード例 #2
0
ファイル: sxx-ril-service.c プロジェクト: checko/sxx-ril
/**
 * RIL_UNSOL_ON_USSD
 *
 * Called when a new USSD message is received.
 */
int onUSSDReceived(const char *s, char* sms_pdu)
{
	char *line, *linestart;
	int typeCode, count, err, len;
	char *message;
	char *outputmessage;
	char *responseStr[2];

	linestart=line=strdup(s);
	err = at_tok_start(&line);
	if(err < 0) goto out;

	err = at_tok_nextint(&line, &typeCode);
	if(err < 0) goto out;

	if(at_tok_hasmore(&line)) {

		int format;
		char message[256];
		int n = sscanf(s+6,"%*d,\"%[^\"]\",%d",message,&format);

		LOGD("%s,%d",message,format);

		if(format == 15){
			responseStr[1] = malloc(strlen(message)+1);
			strcpy(responseStr[1],message);    
		}else{
			int len = strlen(message);
			outputmessage = malloc(len/2);
			gsm_hex_to_bytes((cbytes_t)message,len,(bytes_t)outputmessage);

			responseStr[1] = malloc(len);
			len = ucs2_to_utf8((cbytes_t)outputmessage,len/2,(bytes_t)responseStr[1]);
			free(outputmessage);    
		}
		count = 2;
	} else {
		responseStr[1]=NULL;
		count = 1;
	}
	free(linestart);
	asprintf(&responseStr[0], "%d", typeCode);
	RIL_onUnsolicitedResponse (RIL_UNSOL_ON_USSD, responseStr, count*sizeof(char*));
out:
	return UNSOLICITED_SUCCESSED;
}
コード例 #3
0
static int
asimcard_ef_update_linear( SimFile ef, byte_t record_id, char* data )
{
    if (data == NULL || (strlen(data) % 2) == 1) {
        D("ERROR: Length of data should be even.\n");
        return -1;
    }

    if (record_id < 0x00 || record_id > 0xff) {
        D("ERROR: Invaild record id.\n");
        return -1;
    }

    if (ef == NULL || ef->any.type != SIM_FILE_EF_LINEAR) {
        D("ERROR: The type of EF is not SIM_FILE_EF_LINEAR.\n");
        return -1;
    }

    if (ef->linear.rec_len < (strlen(data) / 2)) {
        D("ERROR: Data is too large.\n");
        return -1;
    }

    SimFileEFLinear linear = (SimFileEFLinear) ef;

    if (linear->rec_count < record_id) {
        int      file_size     = linear->rec_len * record_id;
        int      rec_count_old = linear->rec_count;
        cbytes_t records_old   = linear->records;

        linear->rec_count = record_id;
        linear->records   = (cbytes_t) malloc(file_size * sizeof(byte_t));
        memset(linear->records, 0xff, file_size * sizeof(byte_t));

        if (records_old) {
            int size = linear->rec_len * rec_count_old;
            memcpy(linear->records, records_old, size * sizeof(byte_t));
            free(records_old);
        }
    }

    bytes_t record = linear->records + ((record_id - 1) * linear->rec_len);

    return gsm_hex_to_bytes((cbytes_t) data, strlen(data), record);
}