Example #1
0
File: sms.c Project: AndriusA/ofono
static gboolean compute_incoming_msgid(GSList *sms_list,
						struct ofono_uuid *uuid)
{
	GChecksum *checksum;
	GSList *l;
	const struct sms *s;
	unsigned char buf[176];
	gsize uuid_size = sizeof(uuid->uuid);
	int len;

	checksum = g_checksum_new(G_CHECKSUM_SHA1);
	if (checksum == NULL)
		return FALSE;

	for (l = sms_list; l; l = l->next) {
		s = l->data;

		if (sms_encode(s, &len, NULL, buf) == FALSE) {
			g_checksum_free(checksum);
			return FALSE;
		}

		g_checksum_update(checksum, buf, len);
	}

	g_checksum_get_digest(checksum, uuid->uuid, &uuid_size);
	g_checksum_free(checksum);

	return TRUE;
}
Example #2
0
File: sms.c Project: Conjuror/ofono
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");
}
Example #3
0
File: sms.c Project: AndriusA/ofono
static struct tx_queue_entry *tx_queue_entry_new(GSList *msg_list,
							unsigned int flags)
{
	struct tx_queue_entry *entry;
	int i = 0;
	GSList *l;

	entry = g_try_new0(struct tx_queue_entry, 1);
	if (entry == NULL)
		return NULL;

	entry->num_pdus = g_slist_length(msg_list);

	entry->pdus = g_try_new0(struct pending_pdu, entry->num_pdus);
	if (entry->pdus == NULL)
		goto error;

	if (flags & OFONO_SMS_SUBMIT_FLAG_REQUEST_SR) {
		struct sms *head = msg_list->data;

		memcpy(&entry->receiver, &head->submit.daddr,
				sizeof(entry->receiver));
	}

	entry->flags = flags;

	for (l = msg_list; l; l = l->next) {
		struct pending_pdu *pdu = &entry->pdus[i++];
		struct sms *s = l->data;

		sms_encode(s, &pdu->pdu_len, &pdu->tpdu_len, pdu->pdu);

		DBG("pdu_len: %d, tpdu_len: %d",
				pdu->pdu_len, pdu->tpdu_len);
	}

	if (flags & OFONO_SMS_SUBMIT_FLAG_REUSE_UUID)
		return entry;

	if (sms_uuid_from_pdus(entry->pdus, entry->num_pdus, &entry->uuid))
		return entry;

error:
	g_free(entry->pdus);
	g_free(entry);

	return NULL;
}
Example #4
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);
}
Example #5
0
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);
}