4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
\r
6 * Contact: Ja-young Gu <jygu@samsung.com>
\r
8 * PROPRIETARY/CONFIDENTIAL
\r
10 * This software is the confidential and proprietary information of SAMSUNG ELECTRONICS ("Confidential Information").
\r
11 * You shall not disclose such Confidential Information and shall
\r
12 * use it only in accordance with the terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
\r
13 * SAMSUNG make no representations or warranties about the suitability
\r
14 * of the software, either express or implied, including but not
\r
15 * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.
\r
16 * SAMSUNG shall not be liable for any damages suffered by licensee as
\r
17 * a result of using, modifying or distributing this software or its derivatives.
\r
27 #include "s_common.h"
\r
32 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
\r
35 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
\r
37 #define bitsize(type) (sizeof(type) * 8)
\r
39 #define copymask(type) ((0xffffffff) >> (32 - bitsize(type)))
\r
41 #define MASK(width, offset, data) \
\r
42 (((width) == bitsize(data)) ? (data) : \
\r
43 ((((copymask(data) << (bitsize(data) - ((width) % bitsize(data)))) & copymask(data)) >> (offset)) & (data))) \
\r
46 #define MASK_AND_SHIFT(width, offset, shift, data) \
\r
47 ((((signed) (shift)) < 0) ? \
\r
48 MASK((width), (offset), (data)) << -(shift) : \
\r
49 MASK((width), (offset), (data)) >> (((unsigned) (shift)))) \
\r
51 char _util_unpackb(const char *src, int pos, int len);
\r
52 char _util_convert_byte_hexChar (char val);
\r
53 gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes);
\r
55 void util_hex_dump(char *pad, int size, const void *data)
\r
57 char buf[255] = {0, };
\r
58 char hex[4] = {0, };
\r
63 msg("%sno data", pad);
\r
67 p = (unsigned char *)data;
\r
69 snprintf(buf, 255, "%s%04X: ", pad, 0);
\r
70 for (i = 0; i<size; i++) {
\r
71 snprintf(hex, 4, "%02X ", p[i]);
\r
74 if ((i + 1) % 8 == 0) {
\r
75 if ((i + 1) % 16 == 0) {
\r
77 memset(buf, 0, 255);
\r
78 snprintf(buf, 255, "%s%04X: ", pad, i + 1);
\r
89 void hook_hex_dump(enum direction_e d, int size, const void *data)
\r
91 msg("=== TX data DUMP =====");
\r
92 util_hex_dump(" ", size, data);
\r
93 msg("=== TX data DUMP =====");
\r
97 unsigned int util_assign_message_sequence_id(TcorePlugin *p)
\r
99 struct global_data *gd;
\r
102 dbg("plugin is NULL");
\r
106 gd = tcore_plugin_ref_user_data(p);
\r
108 dbg("global data is NULL");
\r
112 if (gd->msg_auto_id_current == 0) {
\r
113 gd->msg_auto_id_current = gd->msg_auto_id_start;
\r
114 dbg("pending_auto_id_current is 0, reset to start");
\r
116 else if (gd->msg_auto_id_current >= gd->msg_auto_id_end) {
\r
117 gd->msg_auto_id_current = gd->msg_auto_id_start;
\r
118 dbg("pending_auto_id_current is over, reset to start");
\r
121 gd->msg_auto_id_current++;
\r
124 dbg("message_sequence_id = %d", gd->msg_auto_id_current);
\r
126 return gd->msg_auto_id_current;
\r
129 gboolean util_add_waiting_job(GQueue *queue, unsigned int id, UserRequest *ur)
\r
131 struct work_queue_data *wqd;
\r
136 wqd = calloc(sizeof(struct work_queue_data), 1);
\r
141 wqd->ur = tcore_user_request_ref(ur);
\r
142 g_queue_push_tail(queue, wqd);
\r
144 dbg("id = %d, ur = 0x%x", wqd->id, wqd->ur);
\r
148 UserRequest *util_pop_waiting_job(GQueue *queue, unsigned int id)
\r
152 struct work_queue_data *wqd;
\r
158 dbg("before waiting job count: %d", g_queue_get_length(queue));
\r
161 wqd = g_queue_peek_nth(queue, i);
\r
165 if (wqd->id == id) {
\r
166 wqd = g_queue_pop_nth(queue, i);
\r
171 } while (wqd != NULL);
\r
173 dbg("after waiting job count: %d", g_queue_get_length(queue));
\r
184 unsigned char util_hexCharToInt(char c)
\r
186 if (c >= '0' && c <= '9')
\r
188 else if (c >= 'A' && c <= 'F')
\r
189 return (c - 'A' + 10);
\r
190 else if (c >= 'a' && c <= 'f')
\r
191 return (c - 'a' + 10);
\r
194 dbg("invalid charater!!");
\r
199 char * util_hexStringToBytes(char * s)
\r
210 ret = calloc((sz/2)+1, 1);
\r
212 dbg("Convert String to Binary!!");
\r
214 for (i = 0; i < sz; i += 2) {
\r
215 ret[i / 2] = (char) ((util_hexCharToInt(s[i]) << 4) | util_hexCharToInt(s[i + 1]));
\r
216 dbg("[%02x]", ret[i/2]);
\r
222 char _util_unpackb(const char *src, int pos, int len)
\r
230 rshift = MAX( 8 - (pos + len), 0);
\r
232 if ( rshift > 0 ) {
\r
234 result = MASK_AND_SHIFT(len, pos, rshift, *src);
\r
238 result = MASK(8-pos, pos, *src);
\r
242 if ( len > 0 ) result = ( result<<len ) | (*src >> (8-len)); // if any bits left
\r
248 char _util_convert_byte_hexChar (char val)
\r
254 hex_char = (char)(val+'0');
\r
256 else if (val >= 10 && val <= 15)
\r
258 hex_char = (char)(val-10+'A');
\r
268 gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes)
\r
274 for (i=0; i<num_bytes*2; i++)
\r
276 nibble = _util_unpackb(byte_pdu,buf_pos,4);
\r
278 hex_pdu[i] = _util_convert_byte_hexChar(nibble);
\r