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