summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tvsetting/TvKeyData.cpp (plain)
blob: 846ea85707bf7f738d833912192470db6ed8936e
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <errno.h>
7#include <sys/stat.h>
8#include <sys/wait.h>
9#include <cutils/properties.h>
10
11#include <netinet/ether.h>
12#include <netinet/if_ether.h>
13
14#include <netutils/ifc.h>
15#include <netutils/dhcp.h>
16
17#include "tvconfig/tvconfig.h"
18#include "CTvSettingCfg.h"
19#include "TvKeyData.h"
20
21
22static unsigned char mHDCPKeyDefHeaderBuf[CC_HDCP_KEY_HEAD_SIZE] = {
23 //40 bytes
24 0x53, 0x4B, 0x59, 0x01, 0x00, 0x10, 0x0D, 0x15, 0x3A, 0x8E, // 000~009
25 0x99, 0xEE, 0x2A, 0x55, 0x58, 0xEE, 0xED, 0x4B, 0xBE, 0x00, // 010~019
26 0x74, 0xA9, 0x00, 0x10, 0x0A, 0x21, 0xE3, 0x30, 0x66, 0x34, // 020~029
27 0xCE, 0x9C, 0xC7, 0x8B, 0x51, 0x27, 0xF9, 0x0B, 0xAD, 0x09, // 030~039
28};
29
30static unsigned char mDefHDCPKeyContentBuf[CC_HDCP_KEY_CONTENT_SIZE] = {
31 //328 bytes
32 0x5F, 0x4D, 0xC2, 0xCA, 0xA2, 0x13, 0x06, 0x18, 0x8D, 0x34, // 000~009
33 0x82, 0x46, 0x2D, 0xC9, 0x4B, 0xB0, 0x1C, 0xDE, 0x3D, 0x49, // 010~019
34 0x39, 0x58, 0xEF, 0x2B, 0x68, 0x39, 0x71, 0xC9, 0x4D, 0x25, // 020~029
35 0xE9, 0x75, 0x4D, 0xAC, 0x62, 0xF5, 0xF5, 0x87, 0xA0, 0xB2, // 030~039
36 0x4A, 0x60, 0xD3, 0xF1, 0x09, 0x3A, 0xB2, 0x3E, 0x19, 0x4F, // 040~049
37 0x3B, 0x1B, 0x2F, 0x85, 0x14, 0x28, 0x44, 0xFC, 0x69, 0x6F, // 050~059
38 0x50, 0x42, 0x81, 0xBF, 0x7C, 0x2B, 0x3A, 0x17, 0x2C, 0x15, // 060~069
39 0xE4, 0x93, 0x77, 0x74, 0xE8, 0x1F, 0x1C, 0x38, 0x54, 0x49, // 070~079
40 0x10, 0x64, 0x5B, 0x7D, 0x90, 0x3D, 0xA0, 0xE1, 0x8B, 0x67, // 080~089
41 0x5C, 0x19, 0xE6, 0xCA, 0x9D, 0xE9, 0x68, 0x5A, 0xB5, 0x62, // 090~099
42 0xDF, 0xA1, 0x28, 0xBC, 0x68, 0x82, 0x9A, 0x22, 0xC4, 0xDC, // 100~109
43 0x48, 0x85, 0x0F, 0xF1, 0x3E, 0x05, 0xDD, 0x1B, 0x2D, 0xF5, // 120~119
44 0x49, 0x3A, 0x15, 0x29, 0xE7, 0xB6, 0x0B, 0x2A, 0x40, 0xE3, // 120~129
45 0xB0, 0x89, 0xD5, 0x75, 0x84, 0x2E, 0x76, 0xE7, 0xBC, 0x63, // 130~139
46 0x67, 0xE3, 0x57, 0x67, 0x86, 0x81, 0xF4, 0xD7, 0xEA, 0x4D, // 140~149
47 0x89, 0x8E, 0x37, 0x95, 0x59, 0x1C, 0x8A, 0xCD, 0x79, 0xF8, // 150~159
48 0x4F, 0x82, 0xF2, 0x6C, 0x7E, 0x7F, 0x79, 0x8A, 0x6B, 0x90, // 160~169
49 0xC0, 0xAF, 0x4C, 0x8D, 0x43, 0x47, 0x1F, 0x9A, 0xF1, 0xBB, // 170~179
50 0x88, 0x64, 0x49, 0x14, 0x50, 0xD1, 0xC3, 0xDF, 0xA6, 0x87, // 180~189
51 0xA0, 0x15, 0x98, 0x51, 0x81, 0xF5, 0x97, 0x55, 0x10, 0x4A, // 190~199
52 0x99, 0x30, 0x54, 0xA4, 0xFC, 0xDA, 0x0E, 0xAC, 0x6A, 0xFA, // 200~209
53 0x90, 0xEE, 0x12, 0x70, 0x69, 0x74, 0x63, 0x46, 0x63, 0xFB, // 210~219
54 0xE6, 0x1F, 0x72, 0xEC, 0x43, 0x5D, 0x50, 0xFF, 0x03, 0x4F, // 220~229
55 0x05, 0x33, 0x88, 0x36, 0x93, 0xE4, 0x72, 0xD5, 0xCC, 0x34, // 230~239
56 0x52, 0x96, 0x15, 0xCE, 0xD0, 0x32, 0x52, 0x41, 0x4F, 0xBC, // 240~249
57 0x2D, 0xDF, 0xC5, 0xD6, 0x7F, 0xD5, 0x74, 0xCE, 0x51, 0xDC, // 250~259
58 0x10, 0x5E, 0xF7, 0xAA, 0x4A, 0x2D, 0x20, 0x9A, 0x17, 0xDD, // 260~269
59 0x30, 0x89, 0x71, 0x82, 0x36, 0x50, 0x09, 0x1F, 0x7C, 0xF3, // 270~279
60 0x12, 0xE9, 0x43, 0x10, 0x5F, 0x51, 0xBF, 0xB8, 0x45, 0xA8, // 280~289
61 0x5A, 0x8D, 0x3F, 0x77, 0xE5, 0x96, 0x73, 0x68, 0xAB, 0x73, // 290~299
62 0xE5, 0x4C, 0xFB, 0xE5, 0x98, 0xB9, 0xAE, 0x74, 0xEB, 0x51, // 300~309
63 0xDB, 0x91, 0x07, 0x7B, 0x66, 0x02, 0x9B, 0x79, 0x03, 0xC5, // 310~319
64 0x34, 0x1C, 0x58, 0x13, 0x31, 0xD2, 0x4A, 0xEC, // 320~327
65};
66
67
68static int TransStringToHex(int data_cnt, char data_buf[],
69 unsigned char hex_buf[])
70{
71 int i = 0, j = 0, tmp_val = 0;
72 char tmp_buf[3] = { 0, 0, 0 };
73
74 while (i < data_cnt) {
75 tmp_val = 0;
76 tmp_buf[0] = data_buf[i];
77 tmp_buf[1] = data_buf[i + 1];
78 tmp_val = strtoul(tmp_buf, NULL, 16);
79 hex_buf[j] = tmp_val;
80 //LOGD("%s, hex_buf[%d] = 0x%x\n", __FUNCTION__, j, hex_buf[j]);
81 i += 2;
82 j += 1;
83 }
84
85 return j;
86}
87
88static int TransToHexString(int hex_cnt, char data_buf[],
89 unsigned char hex_buf[])
90{
91 int i = 0, j = 0;
92 char tmp_buf[17] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
93
94 data_buf[0] = 0;
95 for (i = 0; i < hex_cnt; i++) {
96 sprintf(tmp_buf, "%02X", (unsigned char) hex_buf[i]);
97 strcat(data_buf, tmp_buf);
98 }
99
100 return 2 * hex_cnt;
101}
102
103int ReadKeyData(const char *key_name, unsigned char data_buf[])
104{
105 FILE *dev_fp = NULL;
106 int i = 0, rd_cnt = 0;
107
108 dev_fp = fopen(CS_KEY_DATA_NAME_DEV_PATH, "w");
109 if (dev_fp == NULL) {
110 LOGE("%s, open %s ERROR(%s)!!\n", __FUNCTION__,
111 CS_KEY_DATA_NAME_DEV_PATH, strerror(errno));
112 return -1;
113 }
114
115 fprintf(dev_fp, "%s", key_name);
116
117 fclose(dev_fp);
118 dev_fp = NULL;
119
120 dev_fp = fopen(CS_KEY_DATA_READ_DEV_PATH, "r");
121 if (dev_fp == NULL) {
122 LOGE("%s, open %s ERROR(%s)!!\n", __FUNCTION__,
123 CS_KEY_DATA_READ_DEV_PATH, strerror(errno));
124 return -1;
125 }
126
127 fscanf(dev_fp, "%s", data_buf);
128
129 rd_cnt = strlen((char *)data_buf);
130
131 fclose(dev_fp);
132 dev_fp = NULL;
133
134 return rd_cnt;
135}
136
137int WriteKeyData(const char *key_name, int wr_size, char data_buf[])
138{
139 FILE *dev_fp = NULL;
140 int wr_cnt = 0;
141
142 dev_fp = fopen(CS_KEY_DATA_NAME_DEV_PATH, "w");
143 if (dev_fp == NULL) {
144 LOGE("%s, open %s ERROR(%s)!!\n", __FUNCTION__,
145 CS_KEY_DATA_NAME_DEV_PATH, strerror(errno));
146 return -1;
147 }
148
149 fprintf(dev_fp, "%s", key_name);
150
151 fclose(dev_fp);
152 dev_fp = NULL;
153
154 dev_fp = fopen(CS_KEY_DATA_WRITE_DEV_PATH, "w");
155 if (dev_fp == NULL) {
156 LOGE("%s, open %s ERROR(%s)!!\n", __FUNCTION__,
157 CS_KEY_DATA_WRITE_DEV_PATH, strerror(errno));
158 return -1;
159 }
160
161 wr_cnt = fwrite(data_buf, 1, wr_size, dev_fp);
162
163 fclose(dev_fp);
164 dev_fp = NULL;
165
166 return wr_cnt;
167}
168
169int KeyData_GetMacAddressDataLen()
170{
171 return CC_MAC_LEN;
172}
173
174int KeyData_ReadMacAddress(unsigned char data_buf[])
175{
176 int i = 0, rd_size = 0;
177 int data_i_buf[CC_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
178 unsigned char rd_buf[128] = { 0 };
179 unsigned char tmp_buf[128] = { 0 };
180
181 memset((void *)rd_buf, 0 , 128);
182 rd_size = ReadKeyData(CS_MAC_KEY_NAME, rd_buf);
183 LOGD("%s, rd_size = %d\n", __FUNCTION__, rd_size);
184
185#if ANDROID_PLATFORM_SDK_VERSION == 19
186 memcpy((void *)tmp_buf, (void *)rd_buf, 128);
187 rd_size = TransStringToHex(rd_size, (char *)rd_buf, tmp_buf);
188#endif
189
190#if ANDROID_PLATFORM_SDK_VERSION >= 21
191 memcpy((void *)tmp_buf, (void *)rd_buf, 128);
192#endif
193
194 if (rd_size == 17) {
195 sscanf((char *) tmp_buf, "%02x:%02x:%02x:%02x:%02x:%02x",
196 &data_i_buf[0], &data_i_buf[1], &data_i_buf[2], &data_i_buf[3],
197 &data_i_buf[4], &data_i_buf[5]);
198 for (i = 0; i < CC_MAC_LEN; i++) {
199 data_buf[i] = data_i_buf[i] & 0xFF;
200 }
201
202 return KeyData_GetMacAddressDataLen();
203 }
204
205 return 0;
206}
207
208int KeyData_SaveMacAddress(unsigned char data_buf[])
209{
210 int tmp_ret = 0, wr_size = 0;
211 unsigned char hex_buf[128] = { 0 };
212 char tmp_buf[128] = { 0 };
213
214 sprintf((char *) hex_buf, "%02x:%02x:%02x:%02x:%02x:%02x", data_buf[0],
215 data_buf[1], data_buf[2], data_buf[3], data_buf[4], data_buf[5]);
216
217#if ANDROID_PLATFORM_SDK_VERSION == 19
218 memset((void *)tmp_buf, 0, 128);
219 TransToHexString(strlen((char *) hex_buf), tmp_buf, hex_buf);
220#endif
221
222#if ANDROID_PLATFORM_SDK_VERSION >= 21
223 memset((void *)tmp_buf, 0, 128);
224 memcpy(tmp_buf, (const char *)hex_buf, strlen((char *) hex_buf));
225#endif
226
227 wr_size = strlen(tmp_buf);
228 tmp_ret = WriteKeyData(CS_MAC_KEY_NAME, wr_size, tmp_buf);
229 if (tmp_ret != wr_size) {
230 return -1;
231 }
232
233 CreateMacAddressStartWorkThread();
234
235 return 0;
236}
237
238static int gSSMBarCodeLen = -1;
239int KeyData_GetBarCodeDataLen()
240{
241 const char *config_value;
242
243 if (gSSMBarCodeLen <= 0) {
244 config_value = config_get_str(CFG_SECTION_TV, CS_BARCODE_LEN_CFG, "null");
245 if (strcmp(config_value, "null") == 0) {
246 gSSMBarCodeLen = 32;
247 } else {
248 gSSMBarCodeLen = strtol(config_value, NULL, 10);
249 }
250 }
251
252 return gSSMBarCodeLen;
253}
254
255int KeyData_ReadBarCode(unsigned char data_buf[])
256{
257 int rd_size = 0, tmp_len = 0;
258 unsigned char rd_buf[CC_MAX_KEY_DATA_SIZE] = { 0 };
259
260 tmp_len = KeyData_GetBarCodeDataLen();
261 rd_size = ReadKeyData(CS_BARCODE_KEY_NAME, rd_buf);
262 LOGD("%s, rd_size = %d\n", __FUNCTION__, rd_size);
263
264#if ANDROID_PLATFORM_SDK_VERSION == 19
265 unsigned char tmp_buf[CC_MAX_KEY_DATA_SIZE] = { 0 };
266
267 memcpy((void *)tmp_buf, (void *)rd_buf, CC_MAX_KEY_DATA_SIZE);
268 rd_size = TransStringToHex(rd_size, (char *)rd_buf, tmp_buf);
269
270 if (rd_size == tmp_len) {
271 memcpy(data_buf, tmp_buf, rd_size);
272 return rd_size;
273 }
274#endif
275
276#if ANDROID_PLATFORM_SDK_VERSION >= 21
277 if (rd_size == tmp_len) {
278 memcpy(data_buf, rd_buf, rd_size);
279 return rd_size;
280 }
281#endif
282
283 return 0;
284}
285
286int KeyData_SaveBarCode(unsigned char data_buf[])
287{
288 int tmp_len = 0, wr_size = 0;
289 char tmp_buf[CC_MAX_KEY_DATA_SIZE] = { 0 };
290
291 tmp_len = KeyData_GetBarCodeDataLen();
292
293#if ANDROID_PLATFORM_SDK_VERSION == 19
294 memset((void *)tmp_buf, 0, CC_MAX_KEY_DATA_SIZE);
295 TransToHexString(tmp_len, tmp_buf, data_buf);
296#endif
297
298#if ANDROID_PLATFORM_SDK_VERSION >= 21
299 memset((void *)tmp_buf, 0, CC_MAX_KEY_DATA_SIZE);
300 memcpy(tmp_buf, (const char *)data_buf, strlen((char *) data_buf));
301#endif
302
303 wr_size = strlen(tmp_buf);
304 tmp_len = WriteKeyData(CS_BARCODE_KEY_NAME, wr_size, tmp_buf);
305 if (tmp_len != wr_size) {
306 return -1;
307 }
308
309 return 0;
310}
311
312int SSMReadHDCPKey(unsigned char hdcp_key_buf[])
313{
314 int tmp_ret = 0, rd_size = 0;
315 unsigned char rd_buf[CC_MAX_KEY_DATA_SIZE] = { 0 };
316 unsigned char tmp_buf[CC_MAX_KEY_DATA_SIZE] = { 0 };
317
318 tmp_ret = GetHDCPKeyFromFile(0, CC_HDCP_KEY_TOTAL_SIZE, hdcp_key_buf);
319 if (tmp_ret < 0) {
320 rd_size = ReadKeyData(CS_RX_HDCP_KEY_NAME, rd_buf);
321 LOGD("%s, rd_size = %d\n", __FUNCTION__, rd_size);
322
323 memcpy((void *)tmp_buf, (void *)rd_buf, CC_MAX_KEY_DATA_SIZE);
324 rd_size = TransStringToHex(rd_size, (char *)rd_buf, tmp_buf);
325
326 if (rd_size == CC_HDCP_KEY_TOTAL_SIZE) {
327 memcpy(hdcp_key_buf, tmp_buf, CC_HDCP_KEY_TOTAL_SIZE);
328 return rd_size;
329 }
330
331 return 0;
332 }
333
334 return CC_HDCP_KEY_TOTAL_SIZE;
335}
336
337
338
339int SSMSaveHDCPKey(unsigned char hdcp_key_buf[])
340{
341 int tmp_ret = 0, wr_size = 0;
342 char tmp_buf[CC_MAX_KEY_DATA_SIZE] = { 0 };
343
344 tmp_ret = SaveHDCPKeyToFile(0, CC_HDCP_KEY_TOTAL_SIZE, hdcp_key_buf);
345 if (tmp_ret < 0) {
346 memset((void *)tmp_buf, 0, CC_MAX_KEY_DATA_SIZE);
347 TransToHexString(CC_HDCP_KEY_TOTAL_SIZE, tmp_buf, hdcp_key_buf);
348
349 wr_size = strlen(tmp_buf);
350 tmp_ret = WriteKeyData(CS_RX_HDCP_KEY_NAME, wr_size, tmp_buf);
351 if (tmp_ret != wr_size) {
352 tmp_ret = -1;
353 } else {
354 tmp_ret = 0;
355 }
356 }
357
358 return tmp_ret;
359}
360
361int SSMSetHDCPKey()
362{
363
364 int i = 0;
365 unsigned char hdcp_key_buf[CC_HDCP_KEY_TOTAL_SIZE];
366
367 if (GetSSMHandleHDCPKeyEnableCFG() == 1) {
368 if (GetSSMHandleHDCPKeyDemoEnableCFG() == 1) {
369 return SSMSetDefaultHDCPKey(hdcp_key_buf);
370 } else {
371 if (SSMReadHDCPKey(hdcp_key_buf) == CC_HDCP_KEY_TOTAL_SIZE) {
372 LOGD("%s, using ssm's hdcp key.\n", __FUNCTION__);
373 return RealHandleHDCPKey(hdcp_key_buf);
374 }
375 }
376 }
377
378 return -1;
379}
380
381int SSMRefreshHDCPKey()
382{
383 int ret = -1;
384 ret = SSMSetHDCPKey();
385 system ( "/system/bin/dec" );
386 return ret;
387}
388
389int SSMGetHDCPKeyDataLen()
390{
391 return CC_HDCP_KEY_TOTAL_SIZE;
392}
393
394//hdmi edid
395int SSMSetHDMIEdid(int port)
396{
397 int i = 0;
398 unsigned char customer_hdmi_edid_buf[CC_CUSTOMER_HDMI_EDID_TOTAL_SIZE];
399 unsigned char hdmi_edid_buf[SSM_HDMI_EDID_SIZE];
400
401 if (port < 1 && port > SSM_HDMI_PORT_MAX) {
402 LOGD("%s, hdmi port error.%d\n", __FUNCTION__, port);
403 return -1;
404 }
405
406 if (GetSSMHandleHDMIEdidByCustomerEnableCFG() == 1) {
407 if (SSMReadHDMIEdid(port, hdmi_edid_buf) == 0) {
408 LOGD("%s, using ssm's hdmi edid.\n", __FUNCTION__);
409 LOGD("%s, begin to write hdmi edid:0x%x, 0x%x, 0x%x, 0x%x.\n",
410 __FUNCTION__, hdmi_edid_buf[8], hdmi_edid_buf[9],
411 hdmi_edid_buf[10], hdmi_edid_buf[255]);
412 if ( AppendEdidPrefixCode(customer_hdmi_edid_buf, hdmi_edid_buf) == 0 )
413 return RealHandleHDMIEdid(customer_hdmi_edid_buf);
414 }
415 }
416
417 return -1;
418}
419
420int SSMReadHDMIEdid(int port, unsigned char hdmi_edid_buf[])
421{
422 int tmp_ret = 0;
423 LOGD("%s, read hdmi edid from bin file.\n", __FUNCTION__);
424 tmp_ret = GetHDMIEdidFromFile(0, SSM_HDMI_EDID_SIZE, port, hdmi_edid_buf);
425 if (tmp_ret < 0) {
426 LOGD("%s, read hdmi edid error.\n", __FUNCTION__);
427 } else {
428 LOGD("%s, 0x%x, 0x%x, 0x%x, 0x%x.\n", __FUNCTION__, hdmi_edid_buf[8],
429 hdmi_edid_buf[9], hdmi_edid_buf[10], hdmi_edid_buf[255]);
430 }
431 return tmp_ret;
432}
433
434int KeyData_SaveProjectID(int rw_val)
435{
436 int tmp_ret = 0, wr_size = 0;
437 char tmp_buf[64] = { 0 };
438
439 sprintf(tmp_buf, "%08X", rw_val);
440
441 wr_size = strlen(tmp_buf);
442 tmp_ret = WriteKeyData(CS_PROJECT_ID_KEY_NAME, wr_size, tmp_buf);
443 if (tmp_ret != wr_size) {
444 return -1;
445 }
446
447 return 0;
448}
449
450int KeyData_ReadProjectID()
451{
452 int rd_size = 0, tmp_val = 0;
453 unsigned char tmp_buf[64] = { 0 };
454
455 rd_size = ReadKeyData(CS_PROJECT_ID_KEY_NAME, tmp_buf);
456 LOGD("%s, rd_size = %d\n", __FUNCTION__, rd_size);
457 if (rd_size == 4) {
458 tmp_val = 0;
459 tmp_val |= tmp_buf[0] << 24;
460 tmp_val |= tmp_buf[1] << 16;
461 tmp_val |= tmp_buf[2] << 8;
462 tmp_val |= tmp_buf[3] << 0;
463 }
464
465 return tmp_val;
466}
467
468int SSMSaveRGBOGOValue(int offset, int size, unsigned char data_buf[])
469{
470 return SaveRGBOGOToFile(offset, size, data_buf);
471}
472
473int SSMReadRGBOGOValue(int offset, int size, unsigned char data_buf[])
474{
475 return GetRGBOGOFromFile(offset, size, data_buf);
476}
477
478int SSMSaveAudioNoLinePoints(int offset, int size, unsigned char tmp_buf[])
479{
480 return SaveAudioNoLinePointsDataToFile(offset, size, tmp_buf);
481}
482
483int SSMReadAudioNoLinePoints(int offset, int size, unsigned char tmp_buf[])
484{
485 return GetAudioNoLinePointsDataFromFile(offset, size, tmp_buf);
486}
487
488/**************************** start mac address static functions ****************************/
489#define CC_ERR_THREAD_ID (0)
490
491static pthread_t mMacAddressStartWorkThreadID = CC_ERR_THREAD_ID;
492
493static volatile unsigned int mMacAddressLow = -1;
494static volatile unsigned int mMacAddressHigh = -1;
495static volatile int mMacAddressStartWorkThreadExecFlag = -1;
496static volatile int mMacAddressStartWorkThreadTurnOnFlag = -1;
497
498static pthread_mutex_t mac_address_low_mutex = PTHREAD_MUTEX_INITIALIZER;
499static pthread_mutex_t mac_address_high_mutex = PTHREAD_MUTEX_INITIALIZER;
500static pthread_mutex_t mac_address_exec_mutex = PTHREAD_MUTEX_INITIALIZER;
501static pthread_mutex_t mac_address_turnon_mutex = PTHREAD_MUTEX_INITIALIZER;
502
503static int GetSSMMacAddressStartWorkEnableCFG()
504{
505 const char *config_value;
506
507 config_value = config_get_str(CFG_SECTION_TV, CS_MAC_ADDRESS_STARTWRK_EN_CFG, "null");
508 if (strcmp(config_value, "null") == 0) {
509 LOGD(
510 "%s, get config is \"%s\", return 0 to not enable mac address start work.\n",
511 __FUNCTION__, config_value);
512 return 0;
513 }
514
515 return strtoul(config_value, NULL, 10);
516}
517
518static unsigned int SetMacAddressLow(unsigned int low_val)
519{
520 unsigned int tmp_val;
521
522 pthread_mutex_lock(&mac_address_low_mutex);
523
524 tmp_val = mMacAddressLow;
525
526 mMacAddressLow = low_val;
527
528 pthread_mutex_unlock(&mac_address_low_mutex);
529
530 return tmp_val;
531}
532
533static unsigned int GetMacAddressLow()
534{
535 unsigned int tmp_val = 0;
536
537 pthread_mutex_lock(&mac_address_low_mutex);
538
539 tmp_val = mMacAddressLow;
540
541 pthread_mutex_unlock(&mac_address_low_mutex);
542
543 return tmp_val;
544}
545
546static unsigned int SetMacAddressHigh(unsigned int high_val)
547{
548 unsigned int tmp_val;
549
550 pthread_mutex_lock(&mac_address_high_mutex);
551
552 tmp_val = mMacAddressHigh;
553
554 mMacAddressHigh = high_val;
555
556 pthread_mutex_unlock(&mac_address_high_mutex);
557
558 return tmp_val;
559}
560
561static unsigned int GetMacAddressHigh()
562{
563 int tmp_val = 0;
564
565 pthread_mutex_lock(&mac_address_high_mutex);
566
567 tmp_val = mMacAddressHigh;
568
569 pthread_mutex_unlock(&mac_address_high_mutex);
570
571 return tmp_val;
572}
573
574static int SetMacAddressStartWorkThreadExecFlag(int tmp_flag)
575{
576 int tmp_val;
577
578 pthread_mutex_lock(&mac_address_exec_mutex);
579
580 tmp_val = mMacAddressStartWorkThreadExecFlag;
581
582 mMacAddressStartWorkThreadExecFlag = tmp_flag;
583
584 pthread_mutex_unlock(&mac_address_exec_mutex);
585
586 return tmp_val;
587}
588
589static int GetMacAddressStartWorkThreadExecFlag()
590{
591 int tmp_val = 0;
592
593 pthread_mutex_lock(&mac_address_exec_mutex);
594
595 tmp_val = mMacAddressStartWorkThreadExecFlag;
596
597 pthread_mutex_unlock(&mac_address_exec_mutex);
598
599 return tmp_val;
600}
601
602static int SetMacAddressStartWorkThreadTurnOnFlag(int tmp_flag)
603{
604 int tmp_val;
605
606 pthread_mutex_lock(&mac_address_turnon_mutex);
607
608 tmp_val = mMacAddressStartWorkThreadTurnOnFlag;
609
610 mMacAddressStartWorkThreadTurnOnFlag = tmp_flag;
611
612 pthread_mutex_unlock(&mac_address_turnon_mutex);
613
614 return tmp_val;
615}
616
617static int GetMacAddressStartWorkThreadTurnOnFlag()
618{
619 int tmp_val = 0;
620
621 pthread_mutex_lock(&mac_address_turnon_mutex);
622
623 tmp_val = mMacAddressStartWorkThreadTurnOnFlag;
624
625 pthread_mutex_unlock(&mac_address_turnon_mutex);
626
627 return tmp_val;
628}
629
630static void *SSMMacAddressStartWorkMainApp(void *data)
631{
632 unsigned int curMacAddrLow = 0, curMacAddrHigh = 0;
633 int p_status;
634 char ssm_addr_str[128];
635 const char *iname = "eth0";
636 pid_t pid;
637
638 LOGD("%s, entering...\n", __FUNCTION__);
639
640 if (GetSSMMacAddressStartWorkEnableCFG() == 0) {
641 LOGE("%s, ssm mac address start work is not enable.\n", CFG_SECTION_TV);
642 return NULL;
643 }
644
645 curMacAddrLow = GetMacAddressLow();
646 curMacAddrHigh = GetMacAddressHigh();
647
648 while (GetMacAddressStartWorkThreadTurnOnFlag() == 1) {
649 pid = fork();
650 if (pid == 0) {
651 if (execl("/system/bin/stop", "stop_eth_dhcpcd", "eth_dhcpcd", NULL)
652 < 0) {
653 _exit(-1);
654 }
655 _exit(0);
656 }
657 waitpid(pid, &p_status, 0);
658
659 ifc_init();
660
661 ifc_down(iname);
662
663 sprintf(ssm_addr_str, "%02x:%02x:%02x:%02x:%02x:%02x",
664 ((curMacAddrLow >> 0) & 0xFF), ((curMacAddrLow >> 8) & 0xFF),
665 ((curMacAddrLow >> 16) & 0xFF), ((curMacAddrLow >> 24) & 0xFF),
666 ((curMacAddrHigh >> 0) & 0xFF), ((curMacAddrHigh >> 8) & 0xFF));
667 struct ether_addr *addr = ether_aton(ssm_addr_str);
668 if (addr) {
669 ifc_set_hwaddr(iname, addr->ether_addr_octet);
670 }
671
672 ifc_up(iname);
673
674 ifc_close();
675
676 if (curMacAddrLow == GetMacAddressLow()
677 && curMacAddrHigh == GetMacAddressHigh()) {
678 break;
679 }
680
681 curMacAddrLow = GetMacAddressLow();
682 curMacAddrHigh = GetMacAddressHigh();
683 }
684
685 return NULL;
686}
687
688static void *SSMMacAddressStartWorkThreadMain(void *data)
689{
690 void *tmp_ret = NULL;
691
692 SetMacAddressStartWorkThreadExecFlag(1);
693
694 tmp_ret = SSMMacAddressStartWorkMainApp(NULL);
695
696 SetMacAddressStartWorkThreadExecFlag(0);
697
698 return tmp_ret;
699}
700
701static int KillMacAddressStartWorkThread()
702{
703 int i = 0, tmp_timeout_count = 600;
704
705 SetMacAddressStartWorkThreadTurnOnFlag(0);
706 while (1) {
707 if (GetMacAddressStartWorkThreadExecFlag() == 0) {
708 break;
709 }
710
711 if (i >= tmp_timeout_count) {
712 break;
713 }
714
715 i++;
716
717 usleep(100 * 1000);
718 }
719
720 if (i == tmp_timeout_count) {
721 LOGE(
722 "%s, we have try %d times, but the mac address start work thread's exec flag is still(%d)!!!\n",
723 CFG_SECTION_TV, tmp_timeout_count,
724 GetMacAddressStartWorkThreadExecFlag());
725 return -1;
726 }
727
728 pthread_join(mMacAddressStartWorkThreadID, NULL);
729 mMacAddressStartWorkThreadID = CC_ERR_THREAD_ID;
730
731 LOGD("%s, kill the mac address start work thread sucess.\n", __FUNCTION__);
732
733 return 0;
734}
735
736int CreateMacAddressStartWorkThread()
737{
738 unsigned int macAddrLow = 0, macAddrHigh = 0;
739 pthread_attr_t attr;
740 struct sched_param param;
741 unsigned char ssm_addr_buf[16] = { 0, 0, 0, 0, 0, 0 };
742
743 if (KeyData_ReadMacAddress(ssm_addr_buf) < 0) {
744 return -1;
745 }
746
747 macAddrLow = 0;
748 macAddrLow |= ((ssm_addr_buf[0] & 0xFF) << 0);
749 macAddrLow |= ((ssm_addr_buf[1] & 0xFF) << 8);
750 macAddrLow |= ((ssm_addr_buf[2] & 0xFF) << 16);
751 macAddrLow |= ((ssm_addr_buf[3] & 0xFF) << 24);
752
753 macAddrHigh = 0;
754 macAddrHigh |= ((ssm_addr_buf[4] & 0xFF) << 0);
755 macAddrHigh |= ((ssm_addr_buf[5] & 0xFF) << 8);
756
757 if (mMacAddressStartWorkThreadID != CC_ERR_THREAD_ID) {
758 if (GetMacAddressStartWorkThreadExecFlag() == 1) {
759 SetMacAddressLow(macAddrLow);
760 SetMacAddressHigh(macAddrHigh);
761 return 0;
762 } else {
763 KillMacAddressStartWorkThread();
764 }
765 }
766
767 SetMacAddressLow(macAddrLow);
768 SetMacAddressHigh(macAddrHigh);
769 SetMacAddressStartWorkThreadTurnOnFlag(1);
770
771 pthread_attr_init(&attr);
772 pthread_attr_setschedpolicy(&attr, SCHED_RR);
773 param.sched_priority = 20;
774 pthread_attr_setschedparam(&attr, &param);
775
776 if (pthread_create(&mMacAddressStartWorkThreadID, &attr,
777 SSMMacAddressStartWorkThreadMain, NULL) < 0) {
778 pthread_attr_destroy(&attr);
779 mMacAddressStartWorkThreadID = CC_ERR_THREAD_ID;
780 return -1;
781 }
782
783 pthread_attr_destroy(&attr);
784
785 LOGD("%s, create channel select thread sucess.\n", __FUNCTION__);
786
787 return 0;
788}
789/**************************** end mac address static functions ****************************/
790
791/**************************** start hdcp key static functions ****************************/
792int GetSSMHandleHDCPKeyEnableCFG()
793{
794 const char *config_value;
795
796 config_value = config_get_str(CFG_SECTION_TV, CS_HDCP_KEY_EN_CFG, "null");
797#if 0
798 LOGD("%s, get \"%s\" is \"%s\".\n", __FUNCTION__, CS_HDCP_KEY_EN_CFG,
799 config_value);
800#endif
801 if (strcmp(config_value, "null") == 0) {
802 LOGD(
803 "%s, get config \"%s\" is \"%s\", return 0 to not enable handle hdcp key.\n",
804 __FUNCTION__, CS_HDCP_KEY_EN_CFG, config_value);
805 return 0;
806 }
807
808 return strtoul(config_value, NULL, 10);
809}
810
811int GetSSMHandleHDCPKeyDemoEnableCFG()
812{
813 const char *config_value;
814
815 config_value = config_get_str(CFG_SECTION_TV, CS_HDCP_KEY_DEMO_EN_CFG, "null");
816#if 0
817 LOGD("%s, get \"%s\" is \"%s\".\n", __FUNCTION__, CS_HDCP_KEY_DEMO_EN_CFG,
818 config_value);
819#endif
820 if (strcmp(config_value, "null") == 0) {
821 LOGD(
822 "%s, get config \"%s\" is \"%s\", return 0 to not enable handle hdcp key demo.\n",
823 __FUNCTION__, CS_HDCP_KEY_DEMO_EN_CFG, config_value);
824 return 0;
825 }
826
827 return strtoul(config_value, NULL, 10);
828}
829
830
831int SSMSetDefaultHDCPKey(unsigned char hdcp_key_buf[])
832{
833 int i = 0;
834
835 for (i = 0; i < CC_HDCP_KEY_HEAD_SIZE; i++) {
836 hdcp_key_buf[i] = mHDCPKeyDefHeaderBuf[i];
837 }
838
839 for (i = 0; i < CC_HDCP_KEY_CONTENT_SIZE; i++) {
840 hdcp_key_buf[i + CC_HDCP_KEY_HEAD_SIZE] = mDefHDCPKeyContentBuf[i];
841 }
842
843 LOGD("%s, using default hdcp key.\n", __FUNCTION__);
844
845 return RealHandleHDCPKey(hdcp_key_buf);
846}
847
848int RealHandleHDCPKey(unsigned char hdcp_key_buf[])
849{
850 int i = 0, dev_fd = -1;
851
852 if (hdcp_key_buf == NULL) {
853 return -1;
854 }
855
856 dev_fd = open("/sys/class/hdmirx/hdmirx0/edid", O_RDWR);
857 if (dev_fd < 0) {
858 LOGE("%s, open edid file ERROR(%s)!!\n", CFG_SECTION_TV, strerror(errno));
859 return -1;
860 }
861
862 if (write(dev_fd, hdcp_key_buf, CC_HDCP_KEY_TOTAL_SIZE) < 0) {
863 close(dev_fd);
864 dev_fd = -1;
865 LOGE("%s, write edid file ERROR(%s)!!\n", CFG_SECTION_TV, strerror(errno));
866
867 return -1;
868 }
869
870 close(dev_fd);
871 dev_fd = -1;
872 return 0;
873}
874
875/**************************** end hdcp key static functions ****************************/
876
877/**************************** start hdmi edid static functions ****************************/
878int GetSSMHandleHDMIEdidByCustomerEnableCFG()
879{
880 const char *config_value;
881
882 config_value = config_get_str(CFG_SECTION_TV, CS_HDMI_EDID_EN_CFG, "null");
883#if 0
884 LOGD("%s, get \"%s\" is \"%s\".\n", __FUNCTION__, CS_HDMI_EDID_EN_CFG,
885 config_value);
886#endif
887 if (strcmp(config_value, "null") == 0) {
888 LOGD(
889 "%s, get config \"%s\" is \"%s\", return 0 to not enable handle hdmi edid by customer.\n",
890 __FUNCTION__, CS_HDMI_EDID_EN_CFG, config_value);
891 return 0;
892 }
893
894 return strtoul(config_value, NULL, 10);
895}
896int RealHandleHDMIEdid(unsigned char customer_hdmi_edid_buf[])
897{
898 int i = 0, dev_fd = -1;
899
900 if (customer_hdmi_edid_buf == NULL) {
901 return -1;
902 }
903
904 dev_fd = open("/sys/class/hdmirx/hdmirx0/edid", O_RDWR);
905 if (dev_fd < 0) {
906 LOGE("%s, open edid file ERROR(%s)!!\n", CFG_SECTION_TV, strerror(errno));
907 return -1;
908 }
909
910 if (write(dev_fd, customer_hdmi_edid_buf, CC_CUSTOMER_HDMI_EDID_TOTAL_SIZE)
911 < 0) {
912 close(dev_fd);
913 dev_fd = -1;
914 LOGE("%s, write edid file ERROR(%s)!!\n", CFG_SECTION_TV, strerror(errno));
915
916 return -1;
917 }
918
919 close(dev_fd);
920 dev_fd = -1;
921 return 0;
922}
923
924int AppendEdidPrefixCode(unsigned char customer_hdmi_edid_buf[],
925 unsigned char hdmi_edid_buf[])
926{
927 if (customer_hdmi_edid_buf == NULL || hdmi_edid_buf == NULL) {
928 LOGE("%s, Append hdmi edid's prefixCode ERROR(%s)!!\n", CFG_SECTION_TV,
929 strerror(errno));
930 return -1;
931 }
932 memset(customer_hdmi_edid_buf, 0,
933 sizeof(char) * CC_CUSTOMER_HDMI_EDID_TOTAL_SIZE);
934 customer_hdmi_edid_buf[0] = 'E';
935 customer_hdmi_edid_buf[1] = 'D';
936 customer_hdmi_edid_buf[2] = 'I';
937 customer_hdmi_edid_buf[3] = 'D';
938 memcpy(customer_hdmi_edid_buf + 4, hdmi_edid_buf,
939 CC_CUSTOMER_HDMI_EDID_TOTAL_SIZE - 4);
940 /*
941 LOGD("%s, customer_hdmi_edid_buf: %c,%c,%c,%c,%x,%x,%x,%x.\n", __FUNCTION__,
942 customer_hdmi_edid_buf[0],customer_hdmi_edid_buf[1],customer_hdmi_edid_buf[2],customer_hdmi_edid_buf[3],
943 customer_hdmi_edid_buf[12],customer_hdmi_edid_buf[13],customer_hdmi_edid_buf[14],customer_hdmi_edid_buf[15]);*/
944 /*
945 LOGD("%s, customer_hdmi_edid_buf: \n", __FUNCTION__);
946 int i, j;
947 for (i = 0; i < 16; i++) {
948 LOGD("[%2d] ", i);
949 for (j = 0; j < 16; j++) {
950 LOGD("0x%02lx, ", customer_hdmi_edid_buf[4 + (i*16 + j)]);
951 }
952 LOGD("\n");
953 }*/
954 return 0;
955}
956
957/**************************** end hdmi edid static functions ****************************/
958
959/**************************** start critical data op functions ****************************/
960#define CC_OP_TYPE_READ (0)
961#define CC_OP_TYPE_SAVE (1)
962#define CC_DATA_TYPE_CHAR (0)
963#define CC_DATA_TYPE_INT (1)
964
965typedef int (*op_fun_ptr)(char *, int, int, unsigned char *);
966
967typedef struct tagRWDataInfo {
968 int op_type;
969 int data_type;
970 int max_size;
971 int rw_off;
972 int rw_size;
973 void *data_buf;
974 char *path_cfg_name;
975 char *off_cfg_name;
976 op_fun_ptr op_cb;
977} RWDataInfo;
978
979static int GetFilePathCFG(char *key_str, char path_buf[])
980{
981 int tmp_ret = 0;
982 const char *cfg_value;
983
984 path_buf[0] = '\0';
985 cfg_value = config_get_str(CFG_SECTION_TV, key_str, "");
986 strcpy(path_buf, cfg_value);
987#if 0
988 LOGD("%s, get \"%s\" is \"%s\".\n", CFG_SECTION_TV, key_str, path_buf);
989#endif
990 return tmp_ret;
991}
992
993static int GetFileOffsetCFG(char *key_str)
994{
995 const char *cfg_value;
996
997 cfg_value = config_get_str(CFG_SECTION_TV, key_str, "null");
998#if 0
999 LOGD("%s, get \"%s\" is \"%s\".\n", CFG_SECTION_TV, key_str, cfg_value);
1000#endif
1001 if (strcmp(cfg_value, "null") == 0) {
1002 LOGD("%s, get config \"%s\" is \"%s\", return 0 for default.\n", CFG_SECTION_TV,
1003 key_str, cfg_value);
1004 return 0;
1005 }
1006
1007 return strtol(cfg_value, NULL, 10);
1008}
1009
1010static int handleDataFilePath(char *file_name, int offset, int nsize,
1011 char file_path[])
1012{
1013 if (file_name == NULL) {
1014 LOGE("%s, file_name is NULL!!!\n", CFG_SECTION_TV);
1015 return -1;
1016 }
1017
1018 return 0;
1019}
1020
1021static int ReadDataFromFile(char *file_name, int offset, int nsize,
1022 unsigned char data_buf[])
1023{
1024 int device_fd = -1;
1025 int tmp_ret = 0;
1026 char *tmp_ptr = NULL;
1027 char file_path[512] = { '\0' };
1028
1029 if (data_buf == NULL) {
1030 LOGE("%s, data_buf is NULL!!!\n", CFG_SECTION_TV);
1031 return -1;
1032 }
1033
1034 tmp_ret = handleDataFilePath(file_name, offset, nsize, file_path);
1035 if (tmp_ret < 0) {
1036 tmp_ptr = NULL;
1037 } else if (tmp_ret == 0) {
1038 tmp_ptr = file_name;
1039 } else if (tmp_ret == 1) {
1040 tmp_ptr = file_path;
1041 }
1042
1043 if (tmp_ptr == NULL) {
1044 return -1;
1045 }
1046
1047 device_fd = open(tmp_ptr, O_RDONLY);
1048 if (device_fd < 0) {
1049 LOGE("%s: open file \"%s\" error(%s).\n", CFG_SECTION_TV, file_name,
1050 strerror(errno));
1051 return -1;
1052 }
1053
1054 lseek(device_fd, offset, SEEK_SET);
1055 read(device_fd, data_buf, nsize);
1056
1057 close(device_fd);
1058 device_fd = -1;
1059
1060 return 0;
1061}
1062
1063static int SaveDataToFile(char *file_name, int offset, int nsize,
1064 unsigned char data_buf[])
1065{
1066 int device_fd = -1;
1067 int i = 0, tmp_ret = 0;
1068 char *tmp_ptr = NULL;
1069 char file_path[512] = { '\0' };
1070
1071 if (data_buf == NULL) {
1072 LOGE("%s, data_buf is NULL!!!\n", CFG_SECTION_TV);
1073 return -1;
1074 }
1075
1076 tmp_ret = handleDataFilePath(file_name, offset, nsize, file_path);
1077 if (tmp_ret < 0) {
1078 tmp_ptr = NULL;
1079 } else if (tmp_ret == 0) {
1080 tmp_ptr = file_name;
1081 } else if (tmp_ret == 1) {
1082 tmp_ptr = file_path;
1083 }
1084
1085 if (tmp_ptr == NULL) {
1086 return -1;
1087 }
1088
1089 device_fd = open(tmp_ptr, O_RDWR | O_SYNC);
1090 if (device_fd < 0) {
1091 LOGE("%s: open file \"%s\" error(%s).\n", CFG_SECTION_TV, file_name,
1092 strerror(errno));
1093 return -1;
1094 }
1095
1096 lseek(device_fd, offset, SEEK_SET);
1097 write(device_fd, data_buf, nsize);
1098 fsync(device_fd);
1099
1100 close(device_fd);
1101 device_fd = -1;
1102
1103 return 0;
1104}
1105
1106static int RealRWData(RWDataInfo *data_info)
1107{
1108 int i = 0, file_off = 0;
1109 char file_name[256] = { '\0' };
1110
1111 memset(file_name, '\0', 256);
1112 GetFilePathCFG(data_info->path_cfg_name, file_name);
1113#if 0
1114 LOGD("%s, file_name is %s.\n", __FUNCTION__, file_name);
1115#endif
1116 if (strlen(file_name) == 0) {
1117 LOGE("%s, length of file_name is 0!!!\n", CFG_SECTION_TV);
1118 return -2;
1119 }
1120
1121 if (data_info->rw_off < 0) {
1122 LOGE("%s, data_info->rw_off (%d) is less than 0!!!\n", CFG_SECTION_TV,
1123 data_info->rw_off);
1124 return -1;
1125 }
1126
1127 if (data_info->rw_off + data_info->rw_size > data_info->max_size) {
1128 LOGE(
1129 "%s, data_info->rw_off + data_info->rw_size (%d) is more than data_info->max_size(%d) !!!\n",
1130 CFG_SECTION_TV, data_info->rw_off + data_info->rw_size,
1131 data_info->max_size);
1132 return -1;
1133 }
1134
1135 file_off = GetFileOffsetCFG(data_info->off_cfg_name);
1136 if (file_off < 0) {
1137 LOGE("%s, file_off (%d) is less than 0!!!\n", CFG_SECTION_TV, file_off);
1138 return -1;
1139 }
1140
1141 file_off += data_info->rw_off;
1142
1143 if (data_info->op_cb(file_name, file_off, data_info->rw_size,
1144 (unsigned char *) data_info->data_buf) < 0) {
1145 return -1;
1146 }
1147
1148 return 0;
1149}
1150
1151static int HandleRWData(RWDataInfo *data_info)
1152{
1153 int i = 0, tmp_ret = 0;
1154 int *tmp_iptr = NULL;
1155 unsigned char *tmp_cptr = NULL;
1156 RWDataInfo tmpInfo;
1157
1158 if (data_info == NULL) {
1159 return -1;
1160 }
1161
1162 tmpInfo = *data_info;
1163
1164 if (data_info->data_type == CC_DATA_TYPE_INT) {
1165 tmp_cptr = new unsigned char[data_info->rw_size];
1166 if (tmp_cptr != NULL) {
1167 tmpInfo.data_buf = tmp_cptr;
1168
1169 if (tmpInfo.op_type == CC_OP_TYPE_SAVE) {
1170 tmp_iptr = (int *) data_info->data_buf;
1171 for (i = 0; i < data_info->rw_size; i++) {
1172 tmp_cptr[i] = tmp_iptr[i];
1173 }
1174
1175 tmp_ret |= RealRWData(&tmpInfo);
1176 } else {
1177 tmp_ret |= RealRWData(&tmpInfo);
1178
1179 tmp_iptr = (int *) data_info->data_buf;
1180 for (i = 0; i < data_info->rw_size; i++) {
1181 tmp_iptr[i] = tmp_cptr[i];
1182 }
1183 }
1184
1185 delete tmp_cptr;
1186 tmp_cptr = NULL;
1187
1188 return tmp_ret;
1189 }
1190 }
1191
1192 return RealRWData(&tmpInfo);
1193}
1194
1195int GetRGBOGOFromFile(int rd_off, int rd_size,
1196 unsigned char data_buf[])
1197{
1198 RWDataInfo tmpInfo;
1199
1200 tmpInfo.op_type = CC_OP_TYPE_READ;
1201 tmpInfo.data_type = CC_DATA_TYPE_CHAR;
1202 tmpInfo.max_size = SSM_CR_RGBOGO_LEN + SSM_CR_RGBOGO_CHKSUM_LEN;
1203 tmpInfo.rw_off = rd_off;
1204 tmpInfo.rw_size = rd_size;
1205 tmpInfo.data_buf = data_buf;
1206 tmpInfo.path_cfg_name = (char *) CS_RGBOGO_FILE_PATH_CFG;
1207 tmpInfo.off_cfg_name = (char *) CS_RGBOGO_FILE_OFFSET_CFG;
1208 tmpInfo.op_cb = ReadDataFromFile;
1209
1210 return HandleRWData(&tmpInfo);
1211}
1212
1213int SaveRGBOGOToFile(int wr_off, int wr_size, unsigned char data_buf[])
1214{
1215 RWDataInfo tmpInfo;
1216
1217 tmpInfo.op_type = CC_OP_TYPE_SAVE;
1218 tmpInfo.data_type = CC_DATA_TYPE_CHAR;
1219 tmpInfo.max_size = SSM_CR_RGBOGO_LEN + SSM_CR_RGBOGO_CHKSUM_LEN;
1220 tmpInfo.rw_off = wr_off;
1221 tmpInfo.rw_size = wr_size;
1222 tmpInfo.data_buf = data_buf;
1223 tmpInfo.path_cfg_name = (char *) CS_RGBOGO_FILE_PATH_CFG;
1224 tmpInfo.off_cfg_name = (char *) CS_RGBOGO_FILE_OFFSET_CFG;
1225 tmpInfo.op_cb = SaveDataToFile;
1226
1227 return HandleRWData(&tmpInfo);
1228}
1229
1230int GetAudioNoLinePointsDataFromFile(int rd_off, int rd_size,
1231 unsigned char data_buf[])
1232{
1233 RWDataInfo tmpInfo;
1234
1235 tmpInfo.op_type = CC_OP_TYPE_READ;
1236 tmpInfo.data_type = CC_DATA_TYPE_CHAR;
1237 tmpInfo.max_size = 256;
1238 tmpInfo.rw_off = rd_off;
1239 tmpInfo.rw_size = rd_size;
1240 tmpInfo.data_buf = data_buf;
1241 tmpInfo.path_cfg_name = (char *) CS_AUDIO_NOLINEPOINTS_FILE_PATH_CFG;
1242 tmpInfo.off_cfg_name = (char *) CS_AUDIO_NOLINEPOINTS_FILE_OFFSET_CFG;
1243 tmpInfo.op_cb = ReadDataFromFile;
1244
1245 return HandleRWData(&tmpInfo);
1246}
1247
1248int SaveAudioNoLinePointsDataToFile(int wr_off, int wr_size,
1249 unsigned char data_buf[])
1250{
1251 RWDataInfo tmpInfo;
1252
1253 tmpInfo.op_type = CC_OP_TYPE_SAVE;
1254 tmpInfo.data_type = CC_DATA_TYPE_CHAR;
1255 tmpInfo.max_size = 256;
1256 tmpInfo.rw_off = wr_off;
1257 tmpInfo.rw_size = wr_size;
1258 tmpInfo.data_buf = data_buf;
1259 tmpInfo.path_cfg_name = (char *) CS_AUDIO_NOLINEPOINTS_FILE_PATH_CFG;
1260 tmpInfo.off_cfg_name = (char *) CS_AUDIO_NOLINEPOINTS_FILE_OFFSET_CFG;
1261 tmpInfo.op_cb = SaveDataToFile;
1262
1263 return HandleRWData(&tmpInfo);
1264}
1265
1266int GetHDCPKeyFromFile(int rd_off, int rd_size,
1267 unsigned char data_buf[])
1268{
1269 RWDataInfo tmpInfo;
1270
1271 tmpInfo.op_type = CC_OP_TYPE_READ;
1272 tmpInfo.data_type = CC_DATA_TYPE_CHAR;
1273 tmpInfo.max_size = CC_HDCP_KEY_TOTAL_SIZE;
1274 tmpInfo.rw_off = rd_off;
1275 tmpInfo.rw_size = rd_size;
1276 tmpInfo.data_buf = data_buf;
1277 tmpInfo.path_cfg_name = (char *) CS_HDCP_KEY_FILE_PATH_CFG;
1278 tmpInfo.off_cfg_name = (char *) CS_HDCP_KEY_FILE_OFFSET_CFG;
1279 tmpInfo.op_cb = ReadDataFromFile;
1280
1281 return HandleRWData(&tmpInfo);
1282}
1283
1284int SaveHDCPKeyToFile(int wr_off, int wr_size,
1285 unsigned char data_buf[])
1286{
1287 RWDataInfo tmpInfo;
1288
1289 tmpInfo.op_type = CC_OP_TYPE_SAVE;
1290 tmpInfo.data_type = CC_DATA_TYPE_CHAR;
1291 tmpInfo.max_size = CC_HDCP_KEY_TOTAL_SIZE;
1292 tmpInfo.rw_off = wr_off;
1293 tmpInfo.rw_size = wr_size;
1294 tmpInfo.data_buf = data_buf;
1295 tmpInfo.path_cfg_name = (char *) CS_HDCP_KEY_FILE_PATH_CFG;
1296 tmpInfo.off_cfg_name = (char *) CS_HDCP_KEY_FILE_OFFSET_CFG;
1297 tmpInfo.op_cb = SaveDataToFile;
1298
1299 return HandleRWData(&tmpInfo);
1300}
1301
1302int GetHDMIEdidFromFile(int rd_off, int rd_size, int port,
1303 unsigned char data_buf[])
1304{
1305 RWDataInfo tmpInfo;
1306
1307 tmpInfo.op_type = CC_OP_TYPE_READ;
1308 tmpInfo.data_type = CC_DATA_TYPE_CHAR;
1309 tmpInfo.max_size = SSM_HDMI_EDID_SIZE;
1310 tmpInfo.rw_off = rd_off;
1311 tmpInfo.rw_size = rd_size;
1312 tmpInfo.data_buf = data_buf;
1313 switch (port) {
1314 case 1:
1315 tmpInfo.path_cfg_name = (char *) CS_HDMI_PORT1_EDID_FILE_PATH_CFG;
1316 break;
1317 case 2:
1318 tmpInfo.path_cfg_name = (char *) CS_HDMI_PORT2_EDID_FILE_PATH_CFG;
1319 break;
1320 case 3:
1321 tmpInfo.path_cfg_name = (char *) CS_HDMI_PORT3_EDID_FILE_PATH_CFG;
1322 break;
1323 default:
1324 LOGE("%s, port is error, =%d\n", CFG_SECTION_TV, port);
1325 tmpInfo.path_cfg_name = (char *) CS_HDMI_EDID_FILE_PATH_CFG;
1326 break;
1327 }
1328 tmpInfo.off_cfg_name = (char *) CS_HDMI_EDID_FILE_OFFSET_CFG;
1329 tmpInfo.op_cb = ReadDataFromFile;
1330
1331 return HandleRWData(&tmpInfo);
1332}
1333
1334/**************************** end critical data op functions ****************************/
1335