chandra
Newbie level 6
I read the firmware by jtag from a working STB with STI5518 chip.I want to add a Uart protocal at the firmware. The protocal is as follows:
int SSSP_DoCommand07(void)
{
char szFront[16];
unsigned char ucaReply[32];
unsigned short wLen;
int i, j, k, nErrorCnt;
DWORD dwWriteSize, dwReadSize;
unsigned char *p;
DWORD ident;
s_dwActiveFrequency = s_dwCurrentFrequency;
s_ucaUARTWriteBuffer[0] = 0x07;
s_ucaUARTWriteBuffer[1] = 0x06;
s_ucaUARTWriteBuffer[2] = (s_wCurrentDegree >> 8) & 0xFF;
s_ucaUARTWriteBuffer[3] = (s_wCurrentDegree >> 0) & 0xFF;
s_ucaUARTWriteBuffer[4] = (s_dwCurrentFrequency >> 8) & 0xFF;
s_ucaUARTWriteBuffer[5] = (s_dwCurrentFrequency >> 0) & 0xFF;
s_ucaUARTWriteBuffer[6] = (s_wCurrentServiceID >> 8) & 0xFF;
s_ucaUARTWriteBuffer[7] = (s_wCurrentServiceID >> 0) & 0xFF;
p = &s_ucaUARTWriteBuffer[0];
s_ucaUARTWriteBuffer[8] = p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4] ^ p[5] ^ p[6] ^ p[7];
STUART_Flush(s_SerialHandle);
STUART_Write(s_SerialHandle, s_ucaUARTWriteBuffer, 9, &dwWriteSize, 500);
for (j = 0;j < 1; j++) {
s_ucWaitStatus = 1;
ucaReply[0] = 0x00;
dwReadSize = 0;
for (k = 0; k < 10; k++) {
STUART_Read(s_SerialHandle, &ucaReply[0], 1, &dwReadSize, 100);
if (dwReadSize == 1) break;
if (s_ucSSSPStatus == 0) break;
}
s_ucWaitStatus = 0;
if (k >= 10) return -2;
if ( (dwReadSize != 1) || (ucaReply[0] != 0xF7)) {
sprintf(szFront, "F%03d", dwReadSize);
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
return -1;
}
STUART_Read(s_SerialHandle, &ucaReply[1], 18, &dwReadSize, 1000);
if (dwReadSize == 18) {
p = &ucaReply[3];
nErrorCnt = 0;
if ((p[3] != ((p[0]+p[1]+p[2]) & 0xFF))) nErrorCnt |= 0x01;
if ((p[7] != ((p[4]+p[5]+p[6]) & 0xFF))) nErrorCnt |= 0x02;
if ((p[11] != ((p[8]+p[9]+p[10]) & 0xFF))) nErrorCnt |= 0x04;
if ((p[15] != ((p[12]+p[13]+p[14]) & 0xFF))) nErrorCnt |= 0x08;
if (nErrorCnt == 0) {
if (memcmp(s_ucaOldCW, &ucaReply[3], 16) != 0) {
sprintf(szFront, "SETK");
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
Descrypt(&ucaReply[3], &ucaReply[3+8], 0);
} else {
sprintf(szFront, "NOSE");
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
}
memcpy(s_ucaOldCW, &ucaReply[3], 16);
return 0;
} else {
sprintf(szFront, "E%d%02d", nErrorCnt, dwReadSize);
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
return -1;
}
} else {
sprintf(szFront, "F%03d", dwReadSize);
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
return -1;
}
}
return -1;
}
=============================
How can I add this.
I have the bin file of this protocal also.
I dissassemble the STB flash bin file.Then where to add?
Anybody can help me.
int SSSP_DoCommand07(void)
{
char szFront[16];
unsigned char ucaReply[32];
unsigned short wLen;
int i, j, k, nErrorCnt;
DWORD dwWriteSize, dwReadSize;
unsigned char *p;
DWORD ident;
s_dwActiveFrequency = s_dwCurrentFrequency;
s_ucaUARTWriteBuffer[0] = 0x07;
s_ucaUARTWriteBuffer[1] = 0x06;
s_ucaUARTWriteBuffer[2] = (s_wCurrentDegree >> 8) & 0xFF;
s_ucaUARTWriteBuffer[3] = (s_wCurrentDegree >> 0) & 0xFF;
s_ucaUARTWriteBuffer[4] = (s_dwCurrentFrequency >> 8) & 0xFF;
s_ucaUARTWriteBuffer[5] = (s_dwCurrentFrequency >> 0) & 0xFF;
s_ucaUARTWriteBuffer[6] = (s_wCurrentServiceID >> 8) & 0xFF;
s_ucaUARTWriteBuffer[7] = (s_wCurrentServiceID >> 0) & 0xFF;
p = &s_ucaUARTWriteBuffer[0];
s_ucaUARTWriteBuffer[8] = p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4] ^ p[5] ^ p[6] ^ p[7];
STUART_Flush(s_SerialHandle);
STUART_Write(s_SerialHandle, s_ucaUARTWriteBuffer, 9, &dwWriteSize, 500);
for (j = 0;j < 1; j++) {
s_ucWaitStatus = 1;
ucaReply[0] = 0x00;
dwReadSize = 0;
for (k = 0; k < 10; k++) {
STUART_Read(s_SerialHandle, &ucaReply[0], 1, &dwReadSize, 100);
if (dwReadSize == 1) break;
if (s_ucSSSPStatus == 0) break;
}
s_ucWaitStatus = 0;
if (k >= 10) return -2;
if ( (dwReadSize != 1) || (ucaReply[0] != 0xF7)) {
sprintf(szFront, "F%03d", dwReadSize);
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
return -1;
}
STUART_Read(s_SerialHandle, &ucaReply[1], 18, &dwReadSize, 1000);
if (dwReadSize == 18) {
p = &ucaReply[3];
nErrorCnt = 0;
if ((p[3] != ((p[0]+p[1]+p[2]) & 0xFF))) nErrorCnt |= 0x01;
if ((p[7] != ((p[4]+p[5]+p[6]) & 0xFF))) nErrorCnt |= 0x02;
if ((p[11] != ((p[8]+p[9]+p[10]) & 0xFF))) nErrorCnt |= 0x04;
if ((p[15] != ((p[12]+p[13]+p[14]) & 0xFF))) nErrorCnt |= 0x08;
if (nErrorCnt == 0) {
if (memcmp(s_ucaOldCW, &ucaReply[3], 16) != 0) {
sprintf(szFront, "SETK");
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
Descrypt(&ucaReply[3], &ucaReply[3+8], 0);
} else {
sprintf(szFront, "NOSE");
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
}
memcpy(s_ucaOldCW, &ucaReply[3], 16);
return 0;
} else {
sprintf(szFront, "E%d%02d", nErrorCnt, dwReadSize);
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
return -1;
}
} else {
sprintf(szFront, "F%03d", dwReadSize);
szFront[4] = (char)(0xff);
FRONT_PrintData(szFront);
return -1;
}
}
return -1;
}
=============================
How can I add this.
I have the bin file of this protocal also.
I dissassemble the STB flash bin file.Then where to add?
Anybody can help me.