2 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "MsgTextConvert.h"
23 #include "Sms3gpp2Types.h"
24 #include "Sms3gpp2ParamCodec.h"
25 #include "Sms3gpp2Codec.h"
28 Sms3gpp2MsgCodec* Sms3gpp2MsgCodec::pInstance = NULL;
30 Sms3gpp2MsgCodec::Sms3gpp2MsgCodec()
35 Sms3gpp2MsgCodec::~Sms3gpp2MsgCodec()
40 Sms3gpp2MsgCodec* Sms3gpp2MsgCodec::instance()
43 pInstance = new Sms3gpp2MsgCodec();
50 void _shiftNBit(unsigned char *src, unsigned int n_bytes, unsigned int n_shift_bit)
54 for (unsigned int index = 1; index < n_bytes; index++) {
55 tmp = src[index] >> (8 - n_shift_bit);
57 src[index] = src[index] << n_shift_bit;
62 void _shiftNBit_for_decode(unsigned char *src, unsigned int n_bytes, unsigned int n_shift_bit)
64 for (unsigned int index = 0; index < n_bytes; index++) {
65 src[index]<<=n_shift_bit;
66 src[index] |= (src[index+1] >> (8 - n_shift_bit));
71 void _copy_short_to_char(unsigned char *dest, const unsigned short *src)
73 dest[0] = (0xff00 & *src) >> 8;
74 dest[1] = 0x00ff & *src;
78 void _copy_char_to_short(unsigned short *dest, const unsigned char *src)
80 *dest = src[0]*256 + src[1];
84 unsigned char _convert_to_BCD(unsigned char val)
86 unsigned char ret = 0x00;
87 ret = ((val/10) << 4) | (val%10);
92 int UnpackGSM7bitData(unsigned char *src, unsigned char *dest, unsigned int dataLen)
94 unsigned int srcIdx = 0, dstIdx = 0, shift = 0;
96 MSG_DEBUG("dataLen = %d", dataLen);
98 for (; dstIdx < dataLen; dstIdx++) {
100 dest[dstIdx] = src[srcIdx] & 0x7F;
106 if (dstIdx >= dataLen)
111 dest[dstIdx] = (src[srcIdx-1] >> shift) + (src[srcIdx] << (8 - shift));
113 dest[dstIdx] &= 0x7F;
126 int PackGSM7bitData(const unsigned char *pUserData, unsigned char *pPackData, int dataLen)
128 int srcIdx = 0, dstIdx = 0, shift = 0;
130 while (srcIdx < dataLen) {
132 pPackData[dstIdx] = pUserData[srcIdx];
138 if (srcIdx >= dataLen)
143 pPackData[dstIdx-1] |= pUserData[srcIdx] << shift;
144 pPackData[dstIdx] = pUserData[srcIdx] >> (8-shift);
149 } else if (shift == 1) {
150 pPackData[dstIdx-1] |= pUserData[srcIdx] << shift;
162 bool Sms3gpp2MsgCodec::checkInvalidPDU(const unsigned char *p_pkg_str, const int p_pkg_len)
167 if (!(p_pkg_str[offset] == 0x00 || p_pkg_str[offset] == 0x01 || p_pkg_str[offset] == 0x02)) {
168 MSG_WARN("Invalid PDU : Message Type [%2x]", p_pkg_str[offset]);
174 while (offset < p_pkg_len) {
175 switch (p_pkg_str[offset]) {
185 offset += (p_pkg_str[offset+1]+2);
188 MSG_WARN("Invalid PDU : Parameter ID [%2x], offset [%d]", p_pkg_str[offset], offset);
193 if (offset != p_pkg_len)
201 int Sms3gpp2MsgCodec::encodeMsg(const sms_3gpp2_trans_msg_s *p_msg, unsigned char *p_pkg_str)
207 switch (p_msg->type) {
208 case SMS_TRANS_P2P_MSG:
209 encode_size = encodeP2PMsg(&(p_msg->data.p2p_msg), p_pkg_str);
211 case SMS_TRANS_BROADCAST_MSG:
212 encode_size = encodeCBMsg(&(p_msg->data.cb_msg), p_pkg_str);
214 case SMS_TRANS_ACK_MSG:
215 encode_size = encodeAckMsg(&(p_msg->data.ack_msg), p_pkg_str);
227 int Sms3gpp2MsgCodec::encodeP2PMsg(const sms_3gpp2_trans_p2p_msg_s *p_msg, unsigned char *p_pkg_str)
231 int offset = 0, encode_size = 0;
233 int index = 0, len_index = 0;
235 p_pkg_str[offset++] = SMS_TRANS_P2P_MSG;
237 /* 1. teleservice id */
238 p_pkg_str[offset++] = SMS_TRANS_PARAM_TELESVC_IDENTIFIER;
239 p_pkg_str[offset++] = 2;
241 /* memcpy(p_pkg_str+offset, &(p_msg->telesvc_id), sizeof(sms_trans_telesvc_id_t)); */
242 _copy_short_to_char(p_pkg_str+offset, &(p_msg->telesvc_id));
243 offset += sizeof(sms_3gpp2_trans_telesvc_id_t);
245 /* 2. Service category */
246 if (p_msg->svc_ctg < SMS_TRANS_SVC_CTG_UNDEFINED) {
247 p_pkg_str[offset++] = SMS_TRANS_PARAM_SERVICE_CATEGORY;
248 p_pkg_str[offset++] = 0x02;
250 _copy_short_to_char(&p_pkg_str[offset], &(p_msg->svc_ctg));
254 p_pkg_str[offset++] = SMS_TRANS_PARAM_DEST_ADDRESS;
256 /* Will be set to param length */
257 len_index = offset++;
259 p_pkg_str[offset] = p_msg->address.digit_mode ? 0x80 : 0x00;
260 p_pkg_str[offset] |= (p_msg->address.number_mode ? 0x40 : 0x00);
262 if (p_msg->address.digit_mode == false) {
264 p_pkg_str[offset++] = p_msg->address.addr_len;
266 addr_len = Sms3gpp2ParamCodec::instance()->convertDigitToDTMF(p_msg->address.szData, p_msg->address.addr_len, 0, p_pkg_str+offset);
268 for (int j=0; j < addr_len; j++) {
269 MSG_DEBUG("ADDRESS 4BIT DTMF [%d] = [%02x]", j, p_pkg_str[offset+j]);
274 _shiftNBit(&p_pkg_str[index], offset-index+1, 6);
275 } else if (p_msg->address.digit_mode == true) {
276 p_pkg_str[offset] |= p_msg->address.number_type << 3;
278 if (p_msg->address.number_mode == false) {
279 p_pkg_str[offset++] |= p_msg->address.number_plan >> 1;
280 p_pkg_str[offset++] |= p_msg->address.number_plan << 7;
282 p_pkg_str[offset++] = p_msg->address.addr_len;
284 memcpy(p_pkg_str+offset, p_msg->address.szData, p_msg->address.addr_len);
286 offset += p_msg->address.addr_len;
288 _shiftNBit(&p_pkg_str[index], offset-index+1, 7);
289 } else if (p_msg->address.number_mode == true) {
291 p_pkg_str[offset++] = p_msg->address.addr_len;
292 memcpy(p_pkg_str+offset, p_msg->address.szData, p_msg->address.addr_len);
294 offset += p_msg->address.addr_len;
296 _shiftNBit(&p_pkg_str[index], offset-index+1, 3);
300 p_pkg_str[len_index] = offset - len_index - 1 ;
301 MSG_DEBUG("Address subparam length field = [%d]", p_pkg_str[len_index]);
303 /* 4. Sub address (optional) */
304 if (p_msg->sub_address.addr_len > 0) {
305 p_pkg_str[offset++] = SMS_TRANS_PARAM_ORG_SUB_ADDRESS;
306 p_pkg_str[offset] = p_msg->sub_address.addr_len + 2;
308 p_pkg_str[offset] |= p_msg->sub_address.type << 5;
309 p_pkg_str[offset++] |= (p_msg->sub_address.odd ? 0x10 : 0x00);
310 p_pkg_str[offset++] = p_msg->sub_address.addr_len;
311 memcpy(p_pkg_str+offset, p_msg->sub_address.szData, p_msg->sub_address.addr_len);
313 offset += p_msg->sub_address.addr_len;
315 _shiftNBit(&p_pkg_str[index], offset-index+1, 4);
318 /* 5. Bearer reply option (optional) */
319 if (p_msg->reply_seq > 0) {
320 p_pkg_str[offset++] = SMS_TRANS_PARAM_BEARER_REPLY_OPTION;
321 p_pkg_str[offset++] = 1;
322 p_pkg_str[offset++] = (unsigned char)(p_msg->reply_seq << 2);
323 MSG_DEBUG("Reply sequnce number = [%d]", p_msg->reply_seq);
327 p_pkg_str[offset++] = SMS_TRANS_PARAM_BEARER_DATA;
328 /* PARAMETER_LEN field should be filled at the last part. */
331 unsigned char *encode_data = &p_pkg_str[offset];
333 encode_size = encodeTelesvcMsg(&(p_msg->telesvc_msg), encode_data);
335 p_pkg_str[index] = encode_size;
337 offset += encode_size;
345 int Sms3gpp2MsgCodec::encodeCBMsg(const sms_3gpp2_trans_broadcast_msg_s *p_msg, unsigned char *p_pkg_str)
349 int offset = 0, encode_size = 0;
352 /* 1. Service Category(Mandatory) */
353 p_pkg_str[offset++] = SMS_TRANS_PARAM_SERVICE_CATEGORY;
354 p_pkg_str[offset++] = 0x02;
355 _copy_short_to_char(&p_pkg_str[offset], &p_msg->svc_ctg);
358 /* 2. Bearer Data(Optional) */
359 /* TODO: give condition */
360 p_pkg_str[offset++] = SMS_TRANS_PARAM_BEARER_DATA;
361 /* PARAMETER_LEN field should be filled at the last part. */
362 len_index = offset++;
364 unsigned char *encode_data = &p_pkg_str[offset];
366 encode_size = encodeTelesvcMsg(&(p_msg->telesvc_msg), encode_data);
368 p_pkg_str[len_index] = encode_size;
370 offset += encode_size;
378 int Sms3gpp2MsgCodec::encodeAckMsg(const sms_3gpp2_trans_ack_msg_s *p_msg, unsigned char *p_pkg_str)
383 int addr_len = 0, len_index = 0;
387 p_pkg_str[offset++] = SMS_TRANS_PARAM_DEST_ADDRESS;
389 /* Will be set to param length */
390 len_index = offset++;
392 p_pkg_str[offset] = p_msg->address.digit_mode ? 0x80 : 0x00;
393 p_pkg_str[offset] |= (p_msg->address.number_mode ? 0x40 : 0x00);
397 if (p_msg->address.digit_mode == false) {
398 p_pkg_str[offset++] = p_msg->address.addr_len;
400 addr_len = Sms3gpp2ParamCodec::instance()->convertDigitToDTMF(p_msg->address.szData, p_msg->address.addr_len, 0, p_pkg_str+offset);
402 for (int j=0; j < addr_len; j++) {
403 MSG_DEBUG("ADDRESS 4BIT DTMF [%d] = [%02x]", j, p_pkg_str[offset+j]);
408 _shiftNBit(&p_pkg_str[index], offset-index+1, 6);
409 } else if (p_msg->address.digit_mode == true) {
410 p_pkg_str[offset] |= p_msg->address.number_type << 3;
412 if (p_msg->address.number_mode == false) {
413 p_pkg_str[offset++] |= p_msg->address.number_plan >> 1;
414 p_pkg_str[offset++] |= p_msg->address.number_plan << 7;
416 p_pkg_str[offset++] = p_msg->address.addr_len;
418 memcpy(p_pkg_str+offset, p_msg->address.szData, p_msg->address.addr_len);
420 offset += p_msg->address.addr_len;
422 _shiftNBit(&p_pkg_str[index], offset-index+1, 7);
423 } else if (p_msg->address.number_mode == true) {
424 p_pkg_str[++offset] = p_msg->address.addr_len;
426 memcpy(p_pkg_str+offset, p_msg->address.szData, p_msg->address.addr_len);
428 offset += p_msg->address.addr_len;
430 _shiftNBit(&p_pkg_str[index], offset-index+1, 3);
434 p_pkg_str[len_index] = offset - len_index - 1 ;
435 MSG_DEBUG("Address subparam length field = [%d]", p_pkg_str[len_index]);
438 if (p_msg->sub_address.addr_len > 0) {
439 p_pkg_str[offset++] = SMS_TRANS_PARAM_ORG_SUB_ADDRESS;
440 p_pkg_str[offset] = p_msg->sub_address.addr_len + 2;
442 p_pkg_str[offset] |= p_msg->sub_address.type << 5;
443 p_pkg_str[offset++] |= (p_msg->sub_address.odd ? 0x10 : 0x00);
444 p_pkg_str[offset++] = p_msg->sub_address.addr_len;
445 memcpy(p_pkg_str+offset, p_msg->sub_address.szData, p_msg->sub_address.addr_len);
447 offset += p_msg->sub_address.addr_len;
449 _shiftNBit(&p_pkg_str[index], offset-index+1, 4);
453 p_pkg_str[offset++] = SMS_TRANS_PARAM_CAUSE_CODES;
455 p_pkg_str[offset] |= p_msg->cause_code.reply_seq << 2;
456 p_pkg_str[offset] |= p_msg->cause_code.error_class;
457 if (p_msg->cause_code.error_class != 0x0) {
458 p_pkg_str[++offset] = p_msg->cause_code.cause_code;
460 p_pkg_str[index] = offset - index;
468 int Sms3gpp2MsgCodec::encodeTelesvcMsg(const sms_3gpp2_telesvc_msg_s *p_msg, unsigned char *p_pkg_str)
473 MSG_DEBUG("Teleservice msg type = [%d]", p_msg->type);
475 switch (p_msg->type) {
476 /* case SMS_TYPE_DELIVER:
477 encode_size = encodeTelesvcDeliverMsg(&(p_msg->data.delever), p_pkg_str);
479 case SMS_TYPE_SUBMIT:
480 encode_size = encodeTelesvcSubmitMsg(&(p_msg->data.submit), p_pkg_str);
482 case SMS_TYPE_CANCEL:
483 encode_size = encodeTelesvcCancelMsg(&(p_msg->data.cancel), p_pkg_str);
485 case SMS_TYPE_USER_ACK:
486 encode_size = encodeTelesvcUserAckMsg(&(p_msg->data.user_ack), p_pkg_str);
488 case SMS_TYPE_READ_ACK:
489 encode_size = encodeTelesvcReadAckMsg(&(p_msg->data.read_ack), p_pkg_str);
491 case SMS_TYPE_DELIVER_REPORT:
492 encode_size = encodeTelesvcDeliverReportMsg(&(p_msg->data.report), p_pkg_str);
495 MSG_DEBUG("No matching type for [%d]", p_msg->type);
505 int Sms3gpp2MsgCodec::encodeTelesvcDeliverMsg(const sms_3gpp2_telesvc_read_ack_s *p_msg, char *p_pkg_str)
512 int Sms3gpp2MsgCodec::encodeTelesvcReadAckMsg(const sms_3gpp2_telesvc_read_ack_s *p_msg, unsigned char *p_pkg_str)
524 int Sms3gpp2MsgCodec::encodeTelesvcUserAckMsg(const sms_3gpp2_telesvc_user_ack_s *p_msg, unsigned char *p_pkg_str)
536 int Sms3gpp2MsgCodec::encodeTelesvcDeliverReportMsg(const sms_3gpp2_telesvc_report_s *p_msg, unsigned char *p_pkg_str)
540 int offset = 0, len_index = 0, encode_size = 0;
541 bool delReservedBit = false;
543 /* 1. Message Identifier (Mandatory) */
544 p_pkg_str[offset++] = SMS_BEARER_MESSAGE_IDENTIFIER;
545 p_pkg_str[offset++] = 3;
546 _copy_short_to_char(p_pkg_str+offset+1, &(p_msg->msg_id.msg_id));
547 _shiftNBit(&p_pkg_str[offset], 3, 4);
548 p_pkg_str[offset] |= SMS_TYPE_SUBMIT << 4;
550 p_pkg_str[offset++] |= (p_msg->msg_id.header_ind ? 0x08 : 0x00);
552 /* 2. TP-Failure Cause (Conditional) */
553 if (p_msg->tp_fail_cause >= 0x80) {
554 p_pkg_str[offset++] = SMS_BEARER_TP_FAILURE_CAUSE;
555 p_pkg_str[offset++] = 1;
556 p_pkg_str[offset++] = p_msg->tp_fail_cause;
559 /* 3. User Data (Optional) */
560 if (p_msg->user_data.data_len > 0) {
561 p_pkg_str[offset++] = SMS_BEARER_USER_DATA;
564 if (p_msg->user_data.encode_type == 0x01 || p_msg->user_data.encode_type == 0x0a)
565 p_pkg_str[offset++] = p_msg->user_data.msg_type;
567 p_pkg_str[offset++] = p_msg->user_data.encode_type << 3;
568 p_pkg_str[offset++] = p_msg->user_data.data_len;
570 if (p_msg->user_data.encode_type == SMS_ENCODE_7BIT_ASCII || p_msg->user_data.encode_type == SMS_ENCODE_GSM7BIT) {
571 encode_size = encodeUserData(p_msg->user_data.user_data, &p_pkg_str[offset], p_msg->user_data.data_len);
572 offset += encode_size;
573 if (p_msg->user_data.data_len % 8 > 4)
574 delReservedBit = true;
576 memcpy(p_pkg_str+offset, p_msg->user_data.user_data, p_msg->user_data.data_len);
577 offset += p_msg->user_data.data_len;
579 _shiftNBit(&p_pkg_str[len_index+1], offset-len_index-1, 3);
581 if (delReservedBit == true)
584 p_pkg_str[len_index] = offset - len_index - 1;
587 /* 4. Language Indicator (Optional) */
588 /* TODO : give condition */
590 p_pkg_str[offset++] = SMS_BEARER_ALERT_ON_MSG_DELIVERY;
591 p_pkg_str[offset++] = 1;
592 p_pkg_str[offset++] = p_msg->language;
595 /* 5. Multiple Encoding User Data (Optional) */
604 int Sms3gpp2MsgCodec::encodeTelesvcCancelMsg(const sms_3gpp2_telesvc_cancel_s *p_msg, unsigned char *p_pkg_str)
610 /* 1. Message Identifier */
611 p_pkg_str[offset++] = SMS_BEARER_MESSAGE_IDENTIFIER;
612 p_pkg_str[offset++] = 3;
613 _copy_short_to_char(p_pkg_str+offset+1, &(p_msg->msg_id.msg_id));
614 _shiftNBit(&p_pkg_str[offset], 3, 4);
615 p_pkg_str[offset] |= SMS_TYPE_SUBMIT << 4;
617 p_pkg_str[offset++] |= (p_msg->msg_id.header_ind ? 0x08 : 0x00);
625 int Sms3gpp2MsgCodec::encodeTelesvcSubmitMsg(const sms_3gpp2_telesvc_submit_s *p_msg, unsigned char *p_pkg_str)
629 int offset = 0, len_index = 0;
631 bool delReservedBit = false;
633 /* 1. Message Identifier */
634 p_pkg_str[offset++] = SMS_BEARER_MESSAGE_IDENTIFIER;
635 p_pkg_str[offset++] = 3;
636 _copy_short_to_char(p_pkg_str+offset+1, &(p_msg->msg_id.msg_id));
637 _shiftNBit(&p_pkg_str[offset], 3, 4);
638 p_pkg_str[offset] |= SMS_TYPE_SUBMIT << 4;
640 p_pkg_str[offset++] |= (p_msg->msg_id.header_ind ? 0x08 : 0x00);
643 if (p_msg->user_data.data_len > 0) {
644 p_pkg_str[offset++] = SMS_BEARER_USER_DATA;
647 if (p_msg->user_data.encode_type == 0x01 || p_msg->user_data.encode_type == 0x0a)
648 p_pkg_str[offset++] = p_msg->user_data.msg_type;
650 p_pkg_str[offset++] = p_msg->user_data.encode_type << 3;
651 p_pkg_str[offset++] = p_msg->user_data.data_len;
653 if (p_msg->user_data.encode_type == SMS_ENCODE_7BIT_ASCII) {
654 encode_size = encodeUserData(p_msg->user_data.user_data, &p_pkg_str[offset], p_msg->user_data.data_len);
655 offset += encode_size;
656 if (p_msg->user_data.data_len % 8 > 4)
657 delReservedBit = true;
658 } else if (p_msg->user_data.encode_type == SMS_ENCODE_GSM7BIT) {
659 encode_size = PackGSM7bitData(p_msg->user_data.user_data, &p_pkg_str[offset], p_msg->user_data.data_len);
660 offset += encode_size;
661 if (p_msg->user_data.data_len % 8 > 4)
662 delReservedBit = true;
663 } else if (p_msg->user_data.encode_type == SMS_ENCODE_UNICODE) {
664 MsgTextConvert *textCvt = MsgTextConvert::instance();
665 encode_size = textCvt->convertUTF8ToUCS2(&p_pkg_str[offset], SMS_MAX_USER_DATA_LEN, p_msg->user_data.user_data, p_msg->user_data.data_len);
666 p_pkg_str[offset-1] = encode_size / 2;
667 offset += encode_size;
669 memcpy(p_pkg_str+offset, p_msg->user_data.user_data, p_msg->user_data.data_len);
670 offset += p_msg->user_data.data_len;
672 _shiftNBit(&p_pkg_str[len_index+1], offset-len_index-1, 3);
674 if (delReservedBit == true)
677 p_pkg_str[len_index] = offset - len_index - 1;
679 /* Sprint and Verizon issue */
680 /* 3. Validity Period */
682 if (p_msg->val_period.format == SMS_3GPP2_TIME_RELATIVE) {
683 p_pkg_str[offset++] = SMS_BEARER_VALIDITY_PERIOD_RELATIVE;
684 p_pkg_str[offset++] = 1;
685 p_pkg_str[offset++] = p_msg->val_period.time.rel_time.rel_time;
687 } else if (p_msg->val_period.format == SMS_3GPP2_TIME_ABSOLUTE){
688 p_pkg_str[offset++] = SMS_BEARER_VALIDITY_PERIOD_ABSOLUTE;
689 p_pkg_str[offset++] = 6;
690 p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.year);
691 p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.month);
692 p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.day);
693 p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.hours);
694 p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.minutes);
695 p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.seconds);
699 /* 4. Deferred Delivery Time */
700 if (p_msg->defer_val_period.format == SMS_3GPP2_TIME_RELATIVE) {
701 p_pkg_str[offset++] = SMS_BEARER_DEFERRED_DELIVERY_TIME_RELATIVE;
702 p_pkg_str[offset++] = 1;
703 p_pkg_str[offset++] = p_msg->defer_val_period.time.rel_time.rel_time;
705 } else if (p_msg->defer_val_period.format == SMS_3GPP2_TIME_ABSOLUTE) {
706 p_pkg_str[offset++] = SMS_BEARER_DEFERRED_DELIVERY_TIME_ABSOLUTE;
707 p_pkg_str[offset++] = 6;
708 p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.year);
709 p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.month);
710 p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.day);
711 p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.hours);
712 p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.minutes);
713 p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.seconds);
716 /* 5. Priority Indicator */
717 if (p_msg->priority >= SMS_PRIORITY_NORMAL && p_msg->priority <= SMS_PRIORITY_EMERGENCY) {
718 p_pkg_str[offset++] = SMS_BEARER_PRIORITY_INDICATOR;
719 p_pkg_str[offset++] = 1;
720 p_pkg_str[offset++] = p_msg->priority << 6;
723 /* Sprint and Verizon issue */
724 /* 6. Privacy Indicator */
726 if (p_msg->privacy >= SMS_PRIVACY_NOT_RESTRICTED && p_msg->privacy <= SMS_PRIVACY_SECRET) {
727 p_pkg_str[offset++] = SMS_BEARER_PRIVACY_INDICATOR;
728 p_pkg_str[offset++] = 1;
729 p_pkg_str[offset++] = p_msg->privacy << 6;
733 /* 7. Reply Option */
734 if (p_msg->reply_opt.user_ack_req | p_msg->reply_opt.deliver_ack_req | p_msg->reply_opt.read_ack_req | p_msg->reply_opt.report_req) {
735 p_pkg_str[offset++] = SMS_BEARER_REPLY_OPTION;
736 p_pkg_str[offset++] = 1;
737 p_pkg_str[offset] |= p_msg->reply_opt.user_ack_req << 7;
738 p_pkg_str[offset] |= p_msg->reply_opt.deliver_ack_req << 6;
739 p_pkg_str[offset] |= p_msg->reply_opt.read_ack_req << 5;
740 p_pkg_str[offset++] |= p_msg->reply_opt.report_req << 4;
743 /* 8. Alert on Message Delivery */
744 /* TODO : give condition */
746 p_pkg_str[offset++] = SMS_BEARER_ALERT_ON_MSG_DELIVERY;
747 p_pkg_str[offset++] = 1;
748 p_pkg_str[offset++] = p_msg->alert_priority << 6;
751 /* 9. Language Indicator */
752 /* TODO : give condition */
754 p_pkg_str[offset++] = SMS_BEARER_ALERT_ON_MSG_DELIVERY;
755 p_pkg_str[offset++] = 1;
756 p_pkg_str[offset++] = p_msg->language;
759 /* 10. Call-back Number */
760 if (p_msg->callback_number.addr_len > 0) {
761 p_pkg_str[offset++] = SMS_BEARER_CALLBACK_NUMBER;
763 int len_index = offset++;
765 p_pkg_str[offset] |= p_msg->callback_number.digit_mode << 7;
767 if (p_msg->callback_number.digit_mode == false) {
768 p_pkg_str[offset++] |= (p_msg->callback_number.addr_len & 0xfe) >> 1;
769 p_pkg_str[offset] |= (p_msg->callback_number.addr_len & 0x01) << 7;
770 int addr_len = Sms3gpp2ParamCodec::instance()->convertDigitToDTMF(p_msg->callback_number.szData, p_msg->callback_number.addr_len, 1, p_pkg_str+offset);
772 } else if (p_msg->callback_number.digit_mode == true) {
773 p_pkg_str[offset] |= p_msg->callback_number.number_type << 6;
774 p_pkg_str[offset++] |= p_msg->callback_number.number_plan;
775 p_pkg_str[offset++] = p_msg->callback_number.addr_len;
776 memcpy(p_pkg_str+offset, p_msg->callback_number.szData, p_msg->callback_number.addr_len);
777 offset += p_msg->callback_number.addr_len;
780 p_pkg_str[len_index] = offset- len_index - 1;
783 /* 11. Multiple Encoding User Data */
786 /* 12. Message Deposit Index */
789 /* 13. Service Category Program Results */
797 int Sms3gpp2MsgCodec::decodeMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_msg_s *p_msg)
803 char mti = p_pkg_str[0] & 0xff;
806 case SMS_TRANS_P2P_MSG:
807 p_msg->type = SMS_TRANS_P2P_MSG;
808 decodelen = decodeP2PMsg(p_pkg_str+1, pkg_len-1, &(p_msg->data.p2p_msg));
810 case SMS_TRANS_BROADCAST_MSG:
811 p_msg->type = SMS_TRANS_BROADCAST_MSG;
812 decodelen = decodeCBMsg(p_pkg_str+1, pkg_len-1, &(p_msg->data.cb_msg));
814 case SMS_TRANS_ACK_MSG:
815 p_msg->type = SMS_TRANS_ACK_MSG;
816 decodelen = decodeAckMsg(p_pkg_str+1, pkg_len-1, &(p_msg->data.ack_msg));
819 p_msg->type = SMS_TRANS_TYPE_RESERVED;
829 int Sms3gpp2MsgCodec::decodeP2PMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_p2p_msg_s *p_p2p)
833 int offset = 0, tmp_len = 0;
835 while (offset < pkg_len) {
836 switch (p_pkg_str[offset]) {
838 /* Teleservice Identifier */
839 offset += decodeTeleId(p_pkg_str+offset, pkg_len, &(p_p2p->telesvc_id));
842 /* Service Category */
843 offset += decodeSvcCtg(p_pkg_str+offset, pkg_len, &(p_p2p->svc_ctg));
848 offset += decodeAddress(p_pkg_str+offset, pkg_len, &(p_p2p->address));
853 offset += decodeSubAddress(p_pkg_str+offset, pkg_len, &(p_p2p->sub_address));
856 /* Bearer Reply Option*/
858 p_p2p->reply_seq = (sms_3gpp2_trans_reply_seq_t)(p_pkg_str[offset] >> 2);
863 tmp_len = p_pkg_str[++offset];
864 decodeP2PTelesvcMsg(p_pkg_str+offset+1, tmp_len, &p_p2p->telesvc_msg);
865 offset += (tmp_len+1);
878 int Sms3gpp2MsgCodec::decodeCBMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_broadcast_msg_s *p_cb)
882 int offset = 0, tmp_len = 0;
884 while (offset < pkg_len) {
885 if (p_pkg_str[offset] == 0x01) {
886 /* Service Category */
887 offset += decodeTeleId(p_pkg_str+offset, pkg_len, &(p_cb->svc_ctg));
888 } else if (p_pkg_str[offset] == 0x08) {
890 tmp_len = p_pkg_str[++offset];
891 if (p_cb->svc_ctg >= SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL && p_cb->svc_ctg <= SMS_TRANS_SVC_CTG_CMAS_TEST) {
892 decodeCBBearerData(p_pkg_str+offset+1, tmp_len, &(p_cb->telesvc_msg), true);
894 decodeCBBearerData(p_pkg_str+offset+1, tmp_len, &(p_cb->telesvc_msg), false);
897 offset += (tmp_len+1);
907 int Sms3gpp2MsgCodec::decodeAckMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_ack_msg_s *p_ack)
913 while (offset < pkg_len) {
914 if (p_pkg_str[offset] == 0x04) {
915 /* Destination Address */
916 offset += decodeAddress(p_pkg_str+offset, pkg_len, &(p_ack->address));
917 } else if (p_pkg_str[offset] == 0x05) {
918 /* Destination Subaddress */
919 offset += decodeSubAddress(p_pkg_str+offset, pkg_len, &(p_ack->sub_address));
920 } else if (p_pkg_str[offset] == 0x07) {
923 p_ack->cause_code.reply_seq = (sms_3gpp2_trans_reply_seq_t)p_pkg_str[offset] >> 2;
924 switch (p_pkg_str[offset++] & 0x03) {
926 p_ack->cause_code.error_class = SMS_TRANS_ERR_CLASS_NONE;
932 p_ack->cause_code.error_class = SMS_TRANS_ERR_CLASS_TEMPORARY;
935 p_ack->cause_code.error_class = SMS_TRANS_ERR_CLASS_PERMANENT;
939 if (p_ack->cause_code.error_class != SMS_TRANS_ERR_CLASS_NONE) {
940 p_ack->cause_code.cause_code = (sms_3gpp2_trans_cause_code_t)p_pkg_str[offset++];
951 void Sms3gpp2MsgCodec::decodeP2PTelesvcMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_msg_s *p_telesvc)
955 p_telesvc->type = findMsgType(p_pkg_str, pkg_len);
957 MSG_DEBUG("Msg Type = [%d]", p_telesvc->type);
959 switch (p_telesvc->type) {
960 case SMS_TYPE_DELIVER:
961 decodeP2PDeliverMsg(p_pkg_str, pkg_len, &p_telesvc->data.deliver);
963 case SMS_TYPE_SUBMIT:
964 decodeP2PSubmitMsg(p_pkg_str, pkg_len, &p_telesvc->data.submit);
966 case SMS_TYPE_DELIVERY_ACK:
967 decodeP2PDeliveryAckMsg(p_pkg_str, pkg_len, &p_telesvc->data.delivery_ack);
969 case SMS_TYPE_USER_ACK:
970 decodeP2PUserAckMsg(p_pkg_str, pkg_len, &p_telesvc->data.user_ack);
972 case SMS_TYPE_READ_ACK:
973 decodeP2PReadAckMsg(p_pkg_str, pkg_len, &p_telesvc->data.read_ack);
975 case SMS_TYPE_SUBMIT_REPORT:
976 /* decodeP2PSubmitReportMsg(p_pkg_str, pkg_len, &p_telesvc->data.report); */
986 void Sms3gpp2MsgCodec::decodeP2PDeliverMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_deliver_s *p_del)
990 int offset = 0, tmp_len, tmp_off;
991 unsigned short tmp_param_s;
992 unsigned char tmp_str[pkg_len+1];
994 while (offset < pkg_len) {
995 MSG_DEBUG("current offset = [%d] [%x]", offset, p_pkg_str[offset]);
997 switch (p_pkg_str[offset]) {
999 /* Message Identifier */
1000 offset += decodeMsgId(p_pkg_str+offset, 5, &(p_del->msg_id));
1005 tmp_len = p_pkg_str[offset-1];
1006 memset(tmp_str, 0x00, sizeof(tmp_str));
1007 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1008 decodeUserData(tmp_str, tmp_len, &(p_del->user_data));
1012 /* Message Center Time Stamp */
1014 offset += decodeAbsTime(p_pkg_str+offset, &(p_del->time_stamp));
1017 /* Validity Period - Absolute */
1019 p_del->val_period.format = SMS_3GPP2_TIME_ABSOLUTE;
1020 offset += decodeAbsTime(p_pkg_str+offset, &(p_del->val_period.time.abs_time));
1023 /* Validity Period - Relative */
1025 p_del->val_period.format = SMS_3GPP2_TIME_RELATIVE;
1026 p_del->val_period.time.rel_time.rel_time = (sms_3gpp2_relative_time_t)p_pkg_str[offset++];
1029 /* Priority Indicator */
1031 p_del->priority = (sms_3gpp2_priority_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1034 /* Privacy Indicator */
1036 p_del->privacy = (sms_3gpp2_privacy_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1042 if (p_pkg_str[offset] & 0x80)
1043 p_del->reply_opt.user_ack_req = true;
1045 p_del->reply_opt.user_ack_req = false;
1047 if (p_pkg_str[offset] & 0x40)
1048 p_del->reply_opt.deliver_ack_req = true;
1050 p_del->reply_opt.deliver_ack_req = false;
1052 if (p_pkg_str[offset] & 0x20)
1053 p_del->reply_opt.read_ack_req = true;
1055 p_del->reply_opt.read_ack_req = false;
1057 if (p_pkg_str[offset] & 0x10)
1058 p_del->reply_opt.report_req = true;
1060 p_del->reply_opt.report_req = false;
1065 /* Number of Message */
1067 p_del->num_msg = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
1071 /* Alert on Message Delivery */
1073 tmp_len = p_pkg_str[offset-1];
1075 p_del->alert_priority = (sms_3gpp2_alert_priority_t)((p_pkg_str[offset] & 0xc0) >> 6);
1079 /* Language Indicator */
1081 p_del->language = (sms_3gpp2_language_type_t)p_pkg_str[offset++];
1084 /* Call-Back Number */
1086 tmp_len = p_pkg_str[offset-1];
1088 decodeCallBackNum(&p_pkg_str[offset], tmp_len, &(p_del->callback_number));
1093 /* Message Display Mode */
1096 p_del->display_mode = (sms_3gpp2_display_mode_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1099 /* Multiple Encoding User Data */
1101 tmp_len = p_pkg_str[offset-1];
1108 /* Message Deposit Index */
1111 memset(&tmp_param_s, 0x00, sizeof(unsigned short));
1112 _copy_char_to_short(&tmp_param_s, p_pkg_str+offset);
1113 p_del->deposit_id = tmp_param_s;
1120 tmp_len = p_pkg_str[offset++];
1121 memset(tmp_str, 0x00, sizeof(tmp_str));
1122 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1125 p_del->enhanced_vmn.priority = (sms_3gpp2_priority_indicator_t)(p_pkg_str[offset] >> 6);
1126 p_del->enhanced_vmn.password_req = p_pkg_str[offset] & 0x20 ? true : false;
1127 p_del->enhanced_vmn.setup_req = p_pkg_str[offset] & 0x10 ? true : false;
1128 p_del->enhanced_vmn.pw_change_req = p_pkg_str[offset] & 0x08 ? true : false;
1129 _shiftNBit_for_decode(tmp_str, tmp_len, 5);
1131 if (p_del->enhanced_vmn.setup_req || p_del->enhanced_vmn.pw_change_req) {
1132 p_del->enhanced_vmn.min_pw_len = tmp_str[tmp_off] >> 4;
1133 p_del->enhanced_vmn.max_pw_len = tmp_str[tmp_off++] & 0x0f;
1136 p_del->enhanced_vmn.vm_num_unheard_msg = tmp_str[tmp_off++];
1137 p_del->enhanced_vmn.vm_mailbox_alm_full = tmp_str[tmp_off] & 0x80 ? true : false;
1138 p_del->enhanced_vmn.vm_mailbox_full = tmp_str[tmp_off] & 0x40 ? true : false;
1139 p_del->enhanced_vmn.reply_allowed = tmp_str[tmp_off] & 0x20 ? true : false;
1140 p_del->enhanced_vmn.fax_included = tmp_str[tmp_off] & 0x10 ? true : false;
1141 p_del->enhanced_vmn.vm_len = ((tmp_str[tmp_off] & 0x0f) << 8) | tmp_str[tmp_off+1];
1143 p_del->enhanced_vmn.vm_ret_day = tmp_str[tmp_off] >> 1;
1144 _shiftNBit_for_decode(tmp_str, tmp_len, 7);
1145 p_del->enhanced_vmn.vm_msg_id = (tmp_str[tmp_off] << 8) | tmp_str[tmp_off+1];
1147 p_del->enhanced_vmn.vm_mailbox_id = (tmp_str[tmp_off] << 8) | tmp_str[tmp_off+1];
1150 p_del->enhanced_vmn.an_digit_mode = (sms_3gpp2_digit_mode_t)(tmp_str[tmp_off] & 0x80 ? true : false);
1151 p_del->enhanced_vmn.an_number_type = (sms_3gpp2_number_type_t)((tmp_str[tmp_off] & 0x70) >> 4);
1152 if (p_del->enhanced_vmn.an_digit_mode) {
1153 p_del->enhanced_vmn.an_number_plan = (sms_3gpp2_number_plan_t)(tmp_str[tmp_off++] & 0x0f);
1154 p_del->enhanced_vmn.an_num_field = tmp_str[tmp_off++];
1155 for (int i = 0; i < p_del->enhanced_vmn.an_num_field; i++) {
1156 switch (tmp_str[tmp_off] & 0xf0) {
1166 p_del->enhanced_vmn.an_char[i] = ((tmp_str[tmp_off] & 0xf0) >> 4) + '0';
1169 p_del->enhanced_vmn.an_char[i] = '0';
1172 p_del->enhanced_vmn.an_char[i] = '*';
1175 p_del->enhanced_vmn.an_char[i] = '#';
1181 _shiftNBit_for_decode(tmp_str, tmp_len, 4);
1184 _shiftNBit_for_decode(tmp_str, tmp_len, 4);
1185 p_del->enhanced_vmn.an_num_field = tmp_str[tmp_off++];
1186 memset(p_del->enhanced_vmn.an_char, 0x00, sizeof(p_del->enhanced_vmn.an_char));
1187 memcpy(p_del->enhanced_vmn.an_char, tmp_str+tmp_off, p_del->enhanced_vmn.an_num_field);
1188 tmp_off += p_del->enhanced_vmn.an_num_field;
1191 p_del->enhanced_vmn.cli_digit_mode = (sms_3gpp2_digit_mode_t)(tmp_str[offset] & 0x80 ? true : false);
1192 p_del->enhanced_vmn.cli_number_type = (sms_3gpp2_number_type_t)(tmp_str[offset] & 0x70 >> 4);
1193 if (p_del->enhanced_vmn.cli_digit_mode) {
1194 p_del->enhanced_vmn.cli_number_plan = (sms_3gpp2_number_plan_t)(tmp_str[tmp_off++] & 0x0f);
1195 p_del->enhanced_vmn.cli_num_field = tmp_str[tmp_off++];
1196 for (int i = 0; i < p_del->enhanced_vmn.cli_num_field; i++) {
1197 switch (tmp_str[tmp_off] & 0xf0) {
1207 p_del->enhanced_vmn.cli_char[i] = ((tmp_str[tmp_off] & 0xf0) >> 4) + '0';
1210 p_del->enhanced_vmn.cli_char[i] = '0';
1213 p_del->enhanced_vmn.cli_char[i] = '*';
1216 p_del->enhanced_vmn.cli_char[i] = '#';
1222 _shiftNBit_for_decode(tmp_str, tmp_len, 4);
1225 _shiftNBit_for_decode(tmp_str, tmp_len, 4);
1226 p_del->enhanced_vmn.cli_num_field = tmp_str[tmp_off++];
1227 memset(p_del->enhanced_vmn.cli_char, 0x00, sizeof(p_del->enhanced_vmn.cli_char));
1228 memcpy(p_del->enhanced_vmn.cli_char, tmp_str+tmp_off, p_del->enhanced_vmn.cli_num_field);
1229 tmp_off += p_del->enhanced_vmn.cli_num_field;
1235 /* Enhanced VMN Ack */
1237 tmp_len = p_pkg_str[offset++];
1238 memset(tmp_str, 0x00, sizeof(tmp_str));
1239 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1240 p_del->enhanced_vmn_ack.vm_mailbox_id = tmp_str[offset] << 8 | tmp_str[offset+1];
1242 p_del->enhanced_vmn_ack.vm_num_unheard_msg = tmp_str[offset++];
1243 p_del->enhanced_vmn_ack.num_delete_ack = tmp_str[offset] >> 5;
1244 p_del->enhanced_vmn_ack.num_play_ack = (tmp_str[offset] & 0x1c) >> 2;
1245 _shiftNBit_for_decode(tmp_str, tmp_len, 6);
1246 for (int i = 0; i < p_del->enhanced_vmn_ack.num_delete_ack; i++) {
1247 p_del->enhanced_vmn_ack.da_vm_msg_id[i] = tmp_str[offset] << 8 | tmp_str[offset+1];
1250 for (int i = 0; i < p_del->enhanced_vmn_ack.num_play_ack; i++) {
1251 p_del->enhanced_vmn_ack.pa_vm_msg_id[i] = tmp_str[offset] << 8 | tmp_str[offset+1];
1256 /* skip unrecognized sub parameters */
1258 tmp_len = p_pkg_str[offset++];
1268 void Sms3gpp2MsgCodec::decodeP2PSubmitMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_submit_s *p_sub)
1270 int offset = 0, tmp_len;
1271 unsigned short tmp_param_s;
1272 unsigned char tmp_str[pkg_len+1];
1274 while (offset < pkg_len) {
1275 if (p_pkg_str[offset] == 0x00) {
1276 /* Message Identifier */
1277 offset += decodeMsgId(p_pkg_str+offset, 5, &(p_sub->msg_id));
1278 } else if (p_pkg_str[offset] == 0x01) {
1281 tmp_len = p_pkg_str[offset-1];
1282 memset(tmp_str, 0x00, sizeof(tmp_str));
1283 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1285 decodeUserData(tmp_str, tmp_len, &(p_sub->user_data));
1288 } else if (p_pkg_str[offset] == 0x04) {
1289 /* Validity Period - Absolute */
1291 p_sub->val_period.format = SMS_3GPP2_TIME_ABSOLUTE;
1292 offset += decodeAbsTime(p_pkg_str+offset, &(p_sub->val_period.time.abs_time));
1293 } else if (p_pkg_str[offset] == 0x05) {
1294 /* Validity Period - Relative */
1296 p_sub->val_period.format = SMS_3GPP2_TIME_RELATIVE;
1297 p_sub->val_period.time.rel_time.rel_time = (sms_3gpp2_relative_time_t)p_pkg_str[offset++];
1298 } else if (p_pkg_str[offset] == 0x06) {
1299 /* Deferred Delivery Time - Absolute */
1301 p_sub->defer_val_period.format = SMS_3GPP2_TIME_ABSOLUTE;
1302 offset += decodeAbsTime(p_pkg_str+offset, &(p_sub->defer_val_period.time.abs_time));
1303 } else if (p_pkg_str[offset] == 0x07) {
1304 /* Deferred Delivery Time - Relative */
1306 p_sub->defer_val_period.format = SMS_3GPP2_TIME_RELATIVE;
1307 p_sub->defer_val_period.time.rel_time.rel_time = (sms_3gpp2_relative_time_t)p_pkg_str[offset++];
1308 } else if (p_pkg_str[offset] == 0x08) {
1309 /* Priority indicator */
1311 p_sub->priority = (sms_3gpp2_priority_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1312 } else if (p_pkg_str[offset] == 0x09) {
1313 /* Privacy indicator */
1315 p_sub->privacy = (sms_3gpp2_privacy_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1316 } else if (p_pkg_str[offset] == 0x0a) {
1320 if (p_pkg_str[offset] & 0x80)
1321 p_sub->reply_opt.user_ack_req = true;
1323 p_sub->reply_opt.user_ack_req = false;
1325 if (p_pkg_str[offset] & 0x40)
1326 p_sub->reply_opt.deliver_ack_req = true;
1328 p_sub->reply_opt.deliver_ack_req = false;
1330 if (p_pkg_str[offset] & 0x20)
1331 p_sub->reply_opt.read_ack_req = true;
1333 p_sub->reply_opt.read_ack_req = false;
1335 if (p_pkg_str[offset] & 0x10)
1336 p_sub->reply_opt.report_req = true;
1338 p_sub->reply_opt.report_req = false;
1341 } else if (p_pkg_str[offset] == 0x0c) {
1342 /* Alert on Message Delivery */
1345 p_sub->alert_priority = (sms_3gpp2_alert_priority_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1346 } else if (p_pkg_str[offset] == 0x0d) {
1347 /* Language Indicator */
1350 p_sub->language = (sms_3gpp2_language_type_t)p_pkg_str[offset++];
1351 } else if (p_pkg_str[offset] == 0x0e) {
1352 /* Call-Back Number */
1354 tmp_len = p_pkg_str[offset-1];
1356 decodeCallBackNum(&p_pkg_str[offset], tmp_len, &(p_sub->callback_number));
1359 } else if (p_pkg_str[offset] == 0x10) {
1360 /* Multiple Encoding User Data */
1362 tmp_len = p_pkg_str[offset-1];
1367 } else if (p_pkg_str[offset] == 0x11) {
1368 /* Message Deposit Index */
1371 memset(&tmp_param_s, 0x00, sizeof(unsigned short));
1372 _copy_char_to_short(&tmp_param_s, p_pkg_str+offset);
1373 p_sub->deposit_id = tmp_param_s;
1381 void Sms3gpp2MsgCodec::decodeP2PUserAckMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_user_ack_s *p_user_ack)
1385 int offset = 0, tmp_len;
1386 unsigned short tmp_param_s;
1387 unsigned char tmp_str[pkg_len+1];
1389 while (offset < pkg_len) {
1390 if (p_pkg_str[offset] == 0x00) {
1391 /* Message Identifier */
1392 offset += decodeMsgId(p_pkg_str+offset, 5, &(p_user_ack->msg_id));
1393 } else if (p_pkg_str[offset] == 0x01) {
1396 tmp_len = p_pkg_str[offset-1];
1397 memset(tmp_str, 0x00, sizeof(tmp_str));
1398 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1400 decodeUserData(tmp_str, tmp_len, &(p_user_ack->user_data));
1403 } else if (p_pkg_str[offset] == 0x02) {
1404 /* User Response Code */
1406 p_user_ack->resp_code = p_pkg_str[offset++];
1407 } else if (p_pkg_str[offset] == 0x03) {
1408 /* Message Center Time Stamp */
1410 offset += decodeAbsTime(p_pkg_str+offset, &(p_user_ack->time_stamp));
1411 } else if (p_pkg_str[offset] == 0x10) {
1412 /* Multiple Encoding User Data */
1414 tmp_len = p_pkg_str[offset-1];
1419 } else if (p_pkg_str[offset] == 0x11) {
1420 /* Message Deposit Index */
1423 memset(&tmp_param_s, 0x00, sizeof(unsigned short));
1424 _copy_char_to_short(&tmp_param_s, p_pkg_str+offset);
1425 p_user_ack->deposit_id = tmp_param_s;
1435 void Sms3gpp2MsgCodec::decodeP2PReadAckMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_read_ack_s *p_read_ack)
1439 int offset = 0, tmp_len;
1440 unsigned short tmp_param_s;
1441 unsigned char tmp_str[pkg_len+1];
1443 while (offset < pkg_len) {
1444 if (p_pkg_str[offset] == 0x00) {
1445 /* Message Identifier */
1446 offset += decodeMsgId(p_pkg_str+offset, 5, &(p_read_ack->msg_id));
1447 } else if (p_pkg_str[offset] == 0x01) {
1450 tmp_len = p_pkg_str[offset-1];
1451 memset(tmp_str, 0x00, sizeof(tmp_str));
1452 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1454 decodeUserData(tmp_str, tmp_len, &(p_read_ack->user_data));
1457 } else if (p_pkg_str[offset] == 0x03) {
1458 /* Message Center Time Stamp */
1460 offset += decodeAbsTime(p_pkg_str+offset, &(p_read_ack->time_stamp));
1461 } else if (p_pkg_str[offset] == 0x10) {
1462 /* Multiple Encoding User Data */
1464 tmp_len = p_pkg_str[offset-1];
1469 } else if (p_pkg_str[offset] == 0x11) {
1470 /* Message Deposit Index */
1473 memset(&tmp_param_s, 0x00, sizeof(unsigned short));
1474 _copy_char_to_short(&tmp_param_s, p_pkg_str+offset);
1475 p_read_ack->deposit_id = tmp_param_s;
1485 void Sms3gpp2MsgCodec::decodeP2PSubmitReportMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_report_s *p_sub_report)
1489 int offset = 0, tmp_len;
1490 unsigned char tmp_str[pkg_len+1];
1492 while (offset < pkg_len) {
1493 switch (p_pkg_str[offset]) {
1495 /* Message Identifier */
1496 offset += decodeMsgId(p_pkg_str+offset, 5, &(p_sub_report->msg_id));
1501 tmp_len = p_pkg_str[offset-1];
1502 memset(tmp_str, 0x00, sizeof(tmp_str));
1503 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1504 decodeUserData(tmp_str, tmp_len, &(p_sub_report->user_data));
1508 /* Language Indicator */
1510 p_sub_report->language = (sms_3gpp2_language_type_t)p_pkg_str[offset++];
1513 /* Multiple Encoding User Data */
1515 tmp_len = p_pkg_str[offset-1];
1522 /* TP-Failure Cause */
1524 p_sub_report->tp_fail_cause = p_pkg_str[offset++];
1535 void Sms3gpp2MsgCodec::decodeP2PDeliveryAckMsg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_deliver_ack_s *p_del_ack)
1539 int offset = 0, tmp_len;
1540 unsigned char tmp_str[pkg_len+1];
1542 while (offset < pkg_len) {
1543 switch (p_pkg_str[offset]) {
1545 /* Message Identifier */
1546 offset += decodeMsgId(p_pkg_str+offset, 5, &(p_del_ack->msg_id));
1551 tmp_len = p_pkg_str[offset-1];
1552 memset(tmp_str, 0x00, sizeof(tmp_str));
1553 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1555 decodeUserData(tmp_str, tmp_len, &(p_del_ack->user_data));
1560 /* Message Center Time Stamp */
1562 offset += decodeAbsTime(p_pkg_str+offset, &(p_del_ack->time_stamp));
1565 /* Multiple Encoding User Data */
1567 tmp_len = p_pkg_str[offset-1];
1574 /* Message Status */
1576 p_del_ack->msg_status = (sms_3gpp2_status_code_t)p_pkg_str[offset++];
1587 void Sms3gpp2MsgCodec::decodeCBBearerData(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_msg_s *p_telesvc, bool isCMAS)
1591 int offset = 0, tmp_len;
1592 unsigned char tmp_str[pkg_len+1];
1594 while (offset < pkg_len) {
1595 if (p_pkg_str[offset] == 0x00) {
1596 /* Message Identifier */
1597 p_telesvc->type = SMS_TYPE_DELIVER;
1598 offset += decodeMsgId(p_pkg_str+offset, 5, &(p_telesvc->data.deliver.msg_id));
1599 } else if (p_pkg_str[offset] == 0x01) {
1602 tmp_len = p_pkg_str[offset-1];
1603 memset(tmp_str, 0x00, sizeof(tmp_str));
1604 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
1607 decodeCMASData(tmp_str, tmp_len, &(p_telesvc->data.deliver.cmas_data));
1609 decodeUserData(tmp_str, tmp_len, &(p_telesvc->data.deliver.user_data));
1612 } else if (p_pkg_str[offset] == 0x03) {
1613 /* Message Center Time Stamp */
1615 offset += decodeAbsTime(p_pkg_str+offset, &(p_telesvc->data.deliver.time_stamp));
1616 } else if (p_pkg_str[offset] == 0x04) {
1617 /* Validity Period - Absolute */
1619 p_telesvc->data.deliver.val_period.format = SMS_3GPP2_TIME_ABSOLUTE;
1620 offset += decodeAbsTime(p_pkg_str+offset, &(p_telesvc->data.deliver.val_period.time.abs_time));
1621 } else if (p_pkg_str[offset] == 0x05) {
1622 /* Validity Period - Relative */
1624 p_telesvc->data.deliver.val_period.format = SMS_3GPP2_TIME_RELATIVE;
1625 p_telesvc->data.deliver.val_period.time.rel_time.rel_time = (sms_3gpp2_relative_time_t)p_pkg_str[offset++];
1626 } else if (p_pkg_str[offset] == 0x08) {
1627 /* Priority indicator */
1629 p_telesvc->data.deliver.priority = (sms_3gpp2_priority_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1630 } else if (p_pkg_str[offset] == 0x0c) {
1631 /* Alert on Message Delivery */
1634 p_telesvc->data.deliver.alert_priority = (sms_3gpp2_alert_priority_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1635 } else if (p_pkg_str[offset] == 0x0d) {
1636 /* Language Indicator */
1639 p_telesvc->data.deliver.language = (sms_3gpp2_language_type_t)p_pkg_str[offset++];
1640 } else if (p_pkg_str[offset] == 0x0e) {
1641 /* Call-Back Number */
1643 tmp_len = p_pkg_str[offset-1];
1645 decodeCallBackNum(&p_pkg_str[offset], tmp_len, &(p_telesvc->data.deliver.callback_number));
1648 } else if (p_pkg_str[offset] == 0x0f) {
1649 /* Message Display Mode */
1652 p_telesvc->data.deliver.display_mode = (sms_3gpp2_display_mode_t)((p_pkg_str[offset++] & 0xc0) >> 6);
1653 } else if (p_pkg_str[offset] == 0x10) {
1654 /* Multiple Encoding User Data */
1656 tmp_len = p_pkg_str[offset-1];
1668 int Sms3gpp2MsgCodec::decodeTeleId(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_telesvc_id_t *tele_id)
1671 unsigned short tmp_param_s;
1675 _copy_char_to_short(&tmp_param_s, &p_pkg_str[offset]);
1677 switch (tmp_param_s) {
1678 case SMS_TRANS_TELESVC_CMT_91:
1679 *tele_id = SMS_TRANS_TELESVC_CMT_91;
1681 case SMS_TRANS_TELESVC_CPT_95:
1682 *tele_id = SMS_TRANS_TELESVC_CPT_95;
1684 case SMS_TRANS_TELESVC_CMT_95:
1685 *tele_id = SMS_TRANS_TELESVC_CMT_95;
1687 case SMS_TRANS_TELESVC_VMN_95:
1688 *tele_id = SMS_TRANS_TELESVC_VMN_95;
1690 case SMS_TRANS_TELESVC_WAP:
1691 *tele_id = SMS_TRANS_TELESVC_WAP;
1693 case SMS_TRANS_TELESVC_WEMT:
1694 *tele_id = SMS_TRANS_TELESVC_WEMT;
1696 case SMS_TRANS_TELESVC_SCPT:
1697 *tele_id = SMS_TRANS_TELESVC_SCPT;
1699 case SMS_TRANS_TELESVC_CATPT:
1700 *tele_id = SMS_TRANS_TELESVC_CATPT;
1703 *tele_id = SMS_TRANS_TELESVC_RESERVED;
1711 int Sms3gpp2MsgCodec::decodeSvcCtg(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_svc_ctg_t *svc_ctg)
1714 unsigned short tmp_param_s;
1718 _copy_char_to_short(&tmp_param_s, &p_pkg_str[offset]);
1719 if ((tmp_param_s >= SMS_TRANS_SVC_CTG_UNKNOWN && tmp_param_s <= SMS_TRANS_SVC_CTG_KDDI_CORP_MAX1)
1720 || (tmp_param_s >= SMS_TRANS_SVC_CTG_KDDI_CORP_MIN2 && tmp_param_s <= SMS_TRANS_SVC_CTG_KDDI_CORP_MAX2)
1721 || (tmp_param_s >= SMS_TRANS_SVC_CTG_KDDI_CORP_MIN3 && tmp_param_s <= SMS_TRANS_SVC_CTG_KDDI_CORP_MAX3)) {
1722 *svc_ctg = (sms_3gpp2_trans_svc_ctg_t)tmp_param_s;
1724 *svc_ctg = SMS_TRANS_SVC_CTG_RESERVED;
1731 int Sms3gpp2MsgCodec::decodeAddress(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_addr_s *addr)
1733 int offset = 0, tmp_len = 0;
1734 unsigned char tmp_str[pkg_len+1];
1736 tmp_len = p_pkg_str[++offset];
1738 memset(tmp_str, 0x00, sizeof(tmp_str));
1739 memcpy(tmp_str, p_pkg_str+offset+1, tmp_len);
1741 offset += (tmp_len+1);
1743 if (tmp_str[0] & 0x80)
1744 addr->digit_mode = true;
1746 addr->digit_mode = false;
1748 if (tmp_str[0] & 0x40)
1749 addr->number_mode = true;
1751 addr->number_mode = false;
1753 _shiftNBit_for_decode(tmp_str, tmp_len, 2);
1755 if (addr->digit_mode == false) {
1756 addr->addr_len = tmp_str[0];
1758 memset(addr->szData, 0x00, sizeof(addr->szData));
1760 for (unsigned int i = 0; i < addr->addr_len; i++) {
1761 switch (tmp_str[1] & 0xf0) {
1771 addr->szData[i] = ((tmp_str[1] & 0xf0) >> 4) + '0';
1776 addr->szData[i] = '0';
1779 addr->szData[i] = '*';
1782 addr->szData[i] = '#';
1788 _shiftNBit_for_decode(tmp_str, tmp_len, 4);
1790 } else if (addr->digit_mode == true) {
1791 if (addr->number_mode == false) {
1792 /* digit mode = 1, number mode = 0 */
1793 switch (tmp_str[0] & 0xe0) {
1795 addr->number_type = SMS_NUMBER_TYPE_UNKNOWN;
1798 addr->number_type = SMS_NUMBER_TYPE_INTERNATIONAL;
1801 addr->number_type = SMS_NUMBER_TYPE_NATIONAL;
1804 addr->number_type = SMS_NUMBER_TYPE_NETWORK_SPECIFIC;
1807 addr->number_type = SMS_NUMBER_TYPE_SUBSCRIBER;
1810 addr->number_type = SMS_NUMBER_TYPE_RESERVED_5;
1813 addr->number_type = SMS_NUMBER_TYPE_ABBREVIATED;
1816 addr->number_type = SMS_NUMBER_TYPE_RESERVED_7;
1820 _shiftNBit_for_decode(tmp_str, tmp_len, 3);
1822 switch (tmp_str[0] & 0xf0) {
1824 addr->number_plan = SMS_3GPP2_NPI_UNKNOWN;
1827 addr->number_plan = SMS_3GPP2_NPI_ISDN;
1830 addr->number_plan = SMS_3GPP2_NPI_DATA;
1833 addr->number_plan = SMS_3GPP2_NPI_TELEX;
1836 addr->number_plan = SMS_3GPP2_NPI_PRIVATE;
1839 addr->number_plan = SMS_3GPP2_NPI_RESERVED;
1843 _shiftNBit_for_decode(tmp_str, tmp_len, 4);
1844 } else if (addr->number_mode == true) {
1845 /* digit mode = 1, number mode = 1 */
1846 switch (tmp_str[0] & 0xe0) {
1848 addr->number_type = SMS_TRANS_DNET_UNKNOWN;
1851 addr->number_type = SMS_TRANS_DNET_INTERNET_PROTOCOL;
1854 addr->number_type = SMS_TRANS_DNET_INTERNET_MAIL_ADDR;
1857 addr->number_type = SMS_TRANS_DNET_RESERVED;
1861 _shiftNBit_for_decode(tmp_str, tmp_len, 3);
1864 addr->addr_len = tmp_str[0];
1866 memset(addr->szData, 0x00, sizeof(addr->szData));
1867 memcpy(addr->szData, &tmp_str[1], addr->addr_len);
1874 int Sms3gpp2MsgCodec::decodeSubAddress(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_sub_addr_s *sub_addr)
1876 int offset = 0, tmp_len = 0;
1877 unsigned char tmp_str[pkg_len+1];
1879 tmp_len = p_pkg_str[++offset];
1880 memset(tmp_str, 0x00, sizeof(tmp_str));
1881 memcpy(tmp_str, p_pkg_str+offset+1, tmp_len);
1883 offset += (tmp_len+1);
1885 switch (tmp_str[0] & 0xe0) {
1887 sub_addr->type = SMS_TRANS_SUB_ADDR_NSAP;
1890 sub_addr->type = SMS_TRANS_SUB_ADDR_USER;
1893 sub_addr->type = SMS_TRANS_SUB_ADDR_RESERVED;
1897 if (tmp_str[0] & 0x10)
1898 sub_addr->odd = true;
1900 sub_addr->odd = false;
1902 _shiftNBit_for_decode(tmp_str, tmp_len, 4);
1903 memset(sub_addr->szData, 0x00, sizeof(sub_addr->szData));
1904 memcpy(sub_addr->szData, tmp_str+1, tmp_str[0]);
1910 int Sms3gpp2MsgCodec::decodeMsgId(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_trans_msg_id_s *p_msg_id)
1913 unsigned short tmp_param_s;
1914 unsigned char tmp_str[pkg_len+1];
1916 memset(tmp_str, 0x00, sizeof(tmp_str));
1917 memcpy(tmp_str, &p_pkg_str[offset+2], 3);
1919 _shiftNBit_for_decode(tmp_str, 3, 4);
1921 memset(&tmp_param_s, 0x00, sizeof(unsigned short));
1922 _copy_char_to_short(&tmp_param_s, tmp_str);
1924 p_msg_id->msg_id = tmp_param_s;
1925 if (tmp_str[2] & 0x80)
1926 p_msg_id->header_ind = true;
1928 p_msg_id->header_ind = false;
1936 void Sms3gpp2MsgCodec::decodeCallBackNum(const unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_addr_s *p_callback)
1939 unsigned char tmp_str[pkg_len+1];
1941 if (p_pkg_str[offset] & 0x80) {
1942 p_callback->digit_mode = true;
1944 switch (p_pkg_str[offset] & 0x70) {
1946 p_callback->number_type = SMS_NUMBER_TYPE_UNKNOWN;
1949 p_callback->number_type = SMS_NUMBER_TYPE_INTERNATIONAL;
1952 p_callback->number_type = SMS_NUMBER_TYPE_NATIONAL;
1955 p_callback->number_type = SMS_NUMBER_TYPE_NETWORK_SPECIFIC;
1958 p_callback->number_type = SMS_NUMBER_TYPE_SUBSCRIBER;
1961 p_callback->number_type = SMS_NUMBER_TYPE_RESERVED_5;
1964 p_callback->number_type = SMS_NUMBER_TYPE_ABBREVIATED;
1967 p_callback->number_type = SMS_NUMBER_TYPE_RESERVED_7;
1973 switch (p_pkg_str[offset++] & 0x0f) {
1975 p_callback->number_plan = SMS_3GPP2_NPI_UNKNOWN;
1978 p_callback->number_plan = SMS_3GPP2_NPI_ISDN;
1981 p_callback->number_plan = SMS_3GPP2_NPI_DATA;
1984 p_callback->number_plan = SMS_3GPP2_NPI_TELEX;
1987 p_callback->number_plan = SMS_3GPP2_NPI_PRIVATE;
1991 p_callback->number_plan = SMS_3GPP2_NPI_RESERVED;
1995 p_callback->addr_len = p_pkg_str[offset++];
1996 memset(p_callback->szData, 0x00, sizeof(p_callback->szData));
1998 if (p_callback->number_type == SMS_NUMBER_TYPE_INTERNATIONAL) {
1999 memcpy(&(p_callback->szData[1]), p_pkg_str+offset, p_callback->addr_len);
2000 if (p_callback->szData[1] != '\0') {
2001 p_callback->szData[0] = '+';
2004 memcpy(p_callback->szData, p_pkg_str+offset, p_callback->addr_len);
2007 p_callback->digit_mode = false;
2009 memset(tmp_str, 0x00, sizeof(tmp_str));
2010 memcpy(tmp_str, p_pkg_str+offset, pkg_len);
2012 _shiftNBit_for_decode(tmp_str, pkg_len, 1);
2014 p_callback->addr_len = tmp_str[0];
2016 memset(p_callback->szData, 0x00, sizeof(p_callback->szData));
2018 for (unsigned int i = 0; i < p_callback->addr_len; i++) {
2019 switch (tmp_str[1] & 0xf0) {
2029 p_callback->szData[i] = ((tmp_str[1] & 0xf0) >> 4) + '0';
2032 p_callback->szData[i] = '0';
2035 p_callback->szData[i] = '*';
2038 p_callback->szData[i] = '#';
2044 _shiftNBit_for_decode(tmp_str, pkg_len, 4);
2050 int Sms3gpp2MsgCodec::decodeAbsTime(const unsigned char *p_pkg_str, sms_3gpp2_time_abs_s *p_time_abs)
2054 p_time_abs->year = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
2056 p_time_abs->month = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
2058 p_time_abs->day = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
2060 p_time_abs->hours = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
2062 p_time_abs->minutes = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
2064 p_time_abs->seconds = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
2071 int Sms3gpp2MsgCodec::encodeUserData(const unsigned char* src, unsigned char *dest, int src_size)
2076 unsigned char *tmp = (unsigned char *)calloc(1, src_size+1);
2077 for (i = 0; i < src_size; i++) {
2078 tmp[i] = src[i] << 1;
2082 MSG_ERR("failed to allocate memory");
2086 for (i = 0; i < src_size; i++) {
2088 dest[j++] = (tmp[i] << shift) + (tmp[i+1] >> (7-shift));
2104 void Sms3gpp2MsgCodec::decodeCMASData(unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_cmasdata_s *p_cmas)
2108 int offset = 0, tmp_len = 0;
2109 unsigned char tmp_str[pkg_len+1];
2111 if ((p_pkg_str[offset] & 0xf8) != 0x00) {
2112 MSG_ERR("Wrong Encode Type = [%d]!! The type must be 0", (p_pkg_str[offset]&0xf8)>>3);
2115 _shiftNBit_for_decode(p_pkg_str, pkg_len, 5);
2119 if (p_pkg_str[offset++] != 0x00) {
2120 MSG_ERR("Wrong protocol version = [%d]!! This field must be 0", p_pkg_str[offset-1]);
2121 p_cmas->is_wrong_recode_type = TRUE;
2125 while (offset < pkg_len - 1) {
2126 if (p_pkg_str[offset] == 0x00) {
2127 MSG_DEBUG("Type 0 Decode!");
2129 tmp_len = p_pkg_str[offset++];
2130 MSG_DEBUG("Type 0 length = [%d]", tmp_len);
2131 memset(tmp_str, 0x00, sizeof(tmp_str));
2132 memcpy(tmp_str, p_pkg_str+offset, tmp_len);
2134 switch (tmp_str[0] & 0xf8) {
2136 p_cmas->encode_type = SMS_ENCODE_OCTET;
2139 p_cmas->encode_type = SMS_ENCODE_EPM;
2142 p_cmas->encode_type = SMS_ENCODE_7BIT_ASCII;
2145 p_cmas->encode_type = SMS_ENCODE_IA5;
2148 p_cmas->encode_type = SMS_ENCODE_UNICODE;
2151 p_cmas->encode_type = SMS_ENCODE_SHIFT_JIS;
2154 p_cmas->encode_type = SMS_ENCODE_KOREAN;
2157 p_cmas->encode_type = SMS_ENCODE_LATIN_HEBREW;
2160 p_cmas->encode_type = SMS_ENCODE_LATIN;
2163 p_cmas->encode_type = SMS_ENCODE_GSM7BIT;
2166 p_cmas->encode_type = SMS_ENCODE_GSMDCS;
2169 /* reserved value, but SKT use this value for KSC5601 */
2170 p_cmas->encode_type = SMS_ENCODE_EUCKR;
2173 p_cmas->encode_type = SMS_ENCODE_RESERVED;
2176 _shiftNBit_for_decode(tmp_str, tmp_len, 5);
2178 switch (p_cmas->encode_type) {
2179 case SMS_ENCODE_7BIT_ASCII:
2180 case SMS_ENCODE_IA5:
2181 case SMS_ENCODE_GSM7BIT:
2182 memset(p_cmas->alert_text, 0x00, sizeof(p_cmas->alert_text));
2183 p_cmas->data_len = (tmp_len*8-5) / 7;
2184 for (unsigned int i = 0; i < p_cmas->data_len; i++) {
2185 p_cmas->alert_text[i] = tmp_str[0] >> 1;
2186 _shiftNBit_for_decode(tmp_str, tmp_len, 7);
2189 case SMS_ENCODE_EPM:
2191 case SMS_ENCODE_GSMDCS:
2194 p_cmas->data_len = tmp_len - 1;
2195 memset(p_cmas->alert_text, 0x00, sizeof(p_cmas->alert_text));
2196 memcpy(p_cmas->alert_text, tmp_str+offset, tmp_len-1);
2201 } else if (p_pkg_str[offset] == 0x01) {
2202 MSG_DEBUG("Type 1 Decode!");
2204 tmp_len = p_pkg_str[offset-1];
2205 MSG_DEBUG("Type 1 length = [%d]", tmp_len);
2206 p_cmas->category = (sms_3gpp2_cmae_category_t)p_pkg_str[offset++];
2207 p_cmas->response_type = (sms_3gpp2_cmae_response_type_t)p_pkg_str[offset++];
2208 p_cmas->severity = (sms_3gpp2_cmae_severity_t)(p_pkg_str[offset] >> 4);
2209 p_cmas->urgency = (sms_3gpp2_cmae_urgency_t)(p_pkg_str[offset++] & 0x0f);
2210 p_cmas->certainty = (sms_3gpp2_cmae_certainty_t)(p_pkg_str[offset++] >> 4);
2211 } else if (p_pkg_str[offset] == 0x02) {
2212 MSG_DEBUG("Type 2 Decode!");
2214 tmp_len = p_pkg_str[offset-1];
2215 MSG_DEBUG("Type 2 length = [%d]", tmp_len);
2216 _copy_char_to_short(&(p_cmas->id), p_pkg_str+offset);
2218 p_cmas->alert_handle = (sms_3gpp2_cmae_alert_handle_t)p_pkg_str[offset++];
2219 offset += decodeAbsTime(p_pkg_str+offset, &(p_cmas->expires));
2220 p_cmas->language = (sms_3gpp2_language_type_t)p_pkg_str[offset++];
2223 MSG_DEBUG("offset = [%d], pkg_len = [%d]", offset, pkg_len);
2231 void Sms3gpp2MsgCodec::decodeUserData(unsigned char *p_pkg_str, int pkg_len, sms_3gpp2_telesvc_userdata_s *p_user)
2233 switch (p_pkg_str[0] & 0xf8) {
2235 p_user->encode_type = SMS_ENCODE_OCTET;
2238 p_user->encode_type = SMS_ENCODE_EPM;
2241 p_user->encode_type = SMS_ENCODE_7BIT_ASCII;
2244 p_user->encode_type = SMS_ENCODE_IA5;
2247 p_user->encode_type = SMS_ENCODE_UNICODE;
2250 p_user->encode_type = SMS_ENCODE_SHIFT_JIS;
2253 p_user->encode_type = SMS_ENCODE_KOREAN;
2256 p_user->encode_type = SMS_ENCODE_LATIN_HEBREW;
2259 p_user->encode_type = SMS_ENCODE_LATIN;
2262 p_user->encode_type = SMS_ENCODE_GSM7BIT;
2265 p_user->encode_type = SMS_ENCODE_GSMDCS;
2268 /* reserved value, but SKT use this value for KSC5601 */
2269 p_user->encode_type = SMS_ENCODE_EUCKR;
2272 p_user->encode_type = SMS_ENCODE_RESERVED;
2276 _shiftNBit_for_decode(p_pkg_str, pkg_len, 5);
2278 if (p_user->encode_type == SMS_ENCODE_EPM || p_user->encode_type == SMS_ENCODE_GSMDCS) {
2279 p_user->msg_type = p_pkg_str[0];
2280 _shiftNBit_for_decode(p_pkg_str, pkg_len, 8);
2283 p_user->data_len = p_pkg_str[0];
2284 switch (p_user->encode_type) {
2285 case SMS_ENCODE_7BIT_ASCII:
2286 case SMS_ENCODE_IA5:
2287 memset(p_user->user_data, 0x00, sizeof(p_user->user_data));
2288 for (unsigned int i = 0; i < p_user->data_len; i++) {
2289 p_user->user_data[i] = p_pkg_str[1] >> 1;
2290 _shiftNBit_for_decode(p_pkg_str, pkg_len, 7);
2293 case SMS_ENCODE_GSM7BIT:
2294 memset(p_user->user_data, 0x00, sizeof(p_user->user_data));
2295 UnpackGSM7bitData(&(p_pkg_str[1]), p_user->user_data, p_user->data_len);
2297 case SMS_ENCODE_EPM:
2299 case SMS_ENCODE_GSMDCS:
2301 case SMS_ENCODE_UNICODE:
2302 p_user->data_len*=2;
2303 memset(p_user->user_data, 0x00, sizeof(p_user->user_data));
2304 memcpy(p_user->user_data, p_pkg_str+1, p_user->data_len);
2307 memset(p_user->user_data, 0x00, sizeof(p_user->user_data));
2308 memcpy(p_user->user_data, p_pkg_str+1, p_user->data_len);
2314 sms_3gpp2_message_type_t Sms3gpp2MsgCodec::findMsgType(const unsigned char *p_pkg_str, int pkg_len)
2317 while (offset < pkg_len) {
2318 if (p_pkg_str[offset] == 0x00) {
2319 return (sms_3gpp2_message_type_t)((p_pkg_str[offset + 2] & 0xf0) >> 4);
2321 offset += (p_pkg_str[offset+1]+2);
2324 return SMS_TYPE_MAX_VALUE;