| 1 | #include <string.h> |
|---|
| 2 | #include <assert.h> |
|---|
| 3 | #include <stddef.h> |
|---|
| 4 | #include <stdio.h> |
|---|
| 5 | #include <stdlib.h> |
|---|
| 6 | |
|---|
| 7 | #include <malloc.h> |
|---|
| 8 | |
|---|
| 9 | typedef struct _CVTDescriptor |
|---|
| 10 | { |
|---|
| 11 | unsigned char descriptor_tag; |
|---|
| 12 | unsigned char descriptor_len; |
|---|
| 13 | unsigned char descriptor_data[128]; |
|---|
| 14 | } CVTDescriptor; |
|---|
| 15 | |
|---|
| 16 | void makefile(char * outputName, unsigned char *header, unsigned char *buff, unsigned char nBytes, int count) |
|---|
| 17 | { |
|---|
| 18 | FILE * pFile; |
|---|
| 19 | pFile = fopen(outputName , "wb" ); |
|---|
| 20 | int i =0; |
|---|
| 21 | for(i=0;i<count;i++) |
|---|
| 22 | { |
|---|
| 23 | fwrite (header , 1 ,3 , pFile ); |
|---|
| 24 | fwrite (buff , 1 ,nBytes , pFile ); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | fclose (pFile); |
|---|
| 28 | |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | int main(int argc, char *argv[]) |
|---|
| 33 | { |
|---|
| 34 | //code_version_table |
|---|
| 35 | unsigned char code_version_table_tag[3] = {0x9F, 0x9C, 0x02}; // 0x9F9C02 fixed |
|---|
| 36 | unsigned char length_field = 0; |
|---|
| 37 | unsigned char number_of_descriptors = 3; // 0: vendor ID, 1: hardware version, 2:software version |
|---|
| 38 | CVTDescriptor descriptors[3]; |
|---|
| 39 | unsigned char download_type = 0; // 0: one-way, 1: always on demand, 2: DOCSIS tftp, 3: Download unsupported, 4: conditional on demand |
|---|
| 40 | unsigned char download_command = 0; // 0: download now, 1: deferred download, 2: no exception |
|---|
| 41 | unsigned short frequency_vector = 0; // frequecny of the download carousel |
|---|
| 42 | unsigned char transport_value = 0; // 0: DOCSIS channel, 1: FAT channelQAM64, 2: FAT channel/QAM256 |
|---|
| 43 | unsigned short PID = 0; //low 13 bits |
|---|
| 44 | unsigned char code_file_name_length = 0; |
|---|
| 45 | unsigned char code_file_name_byte[128] = {0,}; |
|---|
| 46 | unsigned char code_verification_certificate = 0xFF; |
|---|
| 47 | |
|---|
| 48 | unsigned char *pCvt = 0; |
|---|
| 49 | unsigned char pCvtHeader[3] = {0xD9, 0x30, 0x00}; |
|---|
| 50 | unsigned long swMajorversion = 0; |
|---|
| 51 | unsigned long swMinorversion = 0; |
|---|
| 52 | |
|---|
| 53 | char filename[20] = {0,}; |
|---|
| 54 | int i =0; |
|---|
| 55 | |
|---|
| 56 | memset(descriptors, 0 ,sizeof(descriptors)); |
|---|
| 57 | //vendor id |
|---|
| 58 | descriptors[0].descriptor_tag = 0x00; |
|---|
| 59 | descriptors[0].descriptor_len = 3; |
|---|
| 60 | memcpy(descriptors[0].descriptor_data,argv[1],descriptors[0].descriptor_len); |
|---|
| 61 | |
|---|
| 62 | //hardware version |
|---|
| 63 | descriptors[1].descriptor_tag = 0x01; |
|---|
| 64 | descriptors[1].descriptor_len = 4; |
|---|
| 65 | memcpy(descriptors[1].descriptor_data,argv[2],descriptors[1].descriptor_len); |
|---|
| 66 | |
|---|
| 67 | //software version |
|---|
| 68 | swMajorversion = atoi(argv[3]); |
|---|
| 69 | swMinorversion = atoi(argv[4]); |
|---|
| 70 | descriptors[2].descriptor_tag = 0x02; |
|---|
| 71 | descriptors[2].descriptor_len = 4; |
|---|
| 72 | descriptors[2].descriptor_data[0] = (swMajorversion/0x100)%256; |
|---|
| 73 | descriptors[2].descriptor_data[1] = (swMajorversion)%256; |
|---|
| 74 | descriptors[2].descriptor_data[2] = (swMinorversion/0x100)%256; |
|---|
| 75 | descriptors[2].descriptor_data[3] = (swMinorversion)%256; |
|---|
| 76 | |
|---|
| 77 | download_type = 0x00; |
|---|
| 78 | download_command = atoi(argv[5]); |
|---|
| 79 | |
|---|
| 80 | frequency_vector = 4*atoi(argv[6]); |
|---|
| 81 | transport_value = atoi(argv[7]); |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | PID = atoi(argv[8])&0x1FFF; |
|---|
| 85 | |
|---|
| 86 | code_file_name_length = atoi(argv[9]); |
|---|
| 87 | memcpy(code_file_name_byte, argv[10], code_file_name_length); |
|---|
| 88 | |
|---|
| 89 | length_field = 3 /*code_version_table_tag*/ |
|---|
| 90 | + 1 /*length_field*/ |
|---|
| 91 | + 1 /*number_of_descriptors*/ |
|---|
| 92 | + 1 /*descriptors[0].descriptor_tag*/ |
|---|
| 93 | + 1 /*descriptors[0].descriptor_len*/ |
|---|
| 94 | + descriptors[0].descriptor_len/*descriptors[0].descriptor_data*/ |
|---|
| 95 | + 1 /*descriptors[1].descriptor_tag*/ |
|---|
| 96 | + 1 /*descriptors[1].descriptor_len*/ |
|---|
| 97 | + descriptors[1].descriptor_len/*descriptors[1].descriptor_data*/ |
|---|
| 98 | + 1 /*descriptors[2].descriptor_tag*/ |
|---|
| 99 | + 1 /*descriptors[2].descriptor_len*/ |
|---|
| 100 | + descriptors[2].descriptor_len/*descriptors[2].descriptor_data*/ |
|---|
| 101 | + 1 /*download_type 4bits + download_command 4bits*/ |
|---|
| 102 | + 2 /*frequency_vector*/ |
|---|
| 103 | + 1 /*transport_value*/ |
|---|
| 104 | + 2 /*reserved 3bits + PID 13bits*/ |
|---|
| 105 | + 1 /*code_file_name_length*/ |
|---|
| 106 | + code_file_name_length /*code_file_name_byte*/ |
|---|
| 107 | + 1; /*code_verification_certificate*/ |
|---|
| 108 | |
|---|
| 109 | pCvt = (unsigned char *)malloc(length_field); |
|---|
| 110 | memset(pCvt, 0 , length_field); |
|---|
| 111 | |
|---|
| 112 | pCvt[0] = code_version_table_tag[0]; |
|---|
| 113 | pCvt[1] = code_version_table_tag[1]; |
|---|
| 114 | pCvt[2] = code_version_table_tag[2]; |
|---|
| 115 | pCvt[3] = length_field; |
|---|
| 116 | pCvt[4] = number_of_descriptors; |
|---|
| 117 | pCvt[5] = descriptors[0].descriptor_tag; |
|---|
| 118 | pCvt[6] = descriptors[0].descriptor_len; |
|---|
| 119 | pCvt[7] = descriptors[0].descriptor_data[0]; |
|---|
| 120 | pCvt[8] = descriptors[0].descriptor_data[1]; |
|---|
| 121 | pCvt[9] = descriptors[0].descriptor_data[2]; |
|---|
| 122 | pCvt[10] = descriptors[1].descriptor_tag; |
|---|
| 123 | pCvt[11] = descriptors[1].descriptor_len; |
|---|
| 124 | pCvt[12] = descriptors[1].descriptor_data[0]; |
|---|
| 125 | pCvt[13] = descriptors[1].descriptor_data[1]; |
|---|
| 126 | pCvt[14] = descriptors[1].descriptor_data[2]; |
|---|
| 127 | pCvt[15] = descriptors[1].descriptor_data[3]; |
|---|
| 128 | pCvt[16] = descriptors[2].descriptor_tag; |
|---|
| 129 | pCvt[17] = descriptors[2].descriptor_len; |
|---|
| 130 | pCvt[18] = descriptors[2].descriptor_data[0]; |
|---|
| 131 | pCvt[19] = descriptors[2].descriptor_data[1]; |
|---|
| 132 | pCvt[20] = descriptors[2].descriptor_data[2]; |
|---|
| 133 | pCvt[21] = descriptors[2].descriptor_data[3]; |
|---|
| 134 | pCvt[22] = ((download_type&0x0F)<<4) + download_command&0x0F; |
|---|
| 135 | pCvt[23] = (unsigned char)((frequency_vector&0xFF00)>>8); |
|---|
| 136 | pCvt[24] = (unsigned char)(frequency_vector&0x00FF); |
|---|
| 137 | pCvt[25] = transport_value; |
|---|
| 138 | pCvt[26] = (unsigned char)((PID&0xFF00)>>8); |
|---|
| 139 | pCvt[27] = (unsigned char)(PID&0x00FF); |
|---|
| 140 | pCvt[28] = code_file_name_length; |
|---|
| 141 | for(i=29;i<29+code_file_name_length;i++) |
|---|
| 142 | { |
|---|
| 143 | pCvt[i] = code_file_name_byte[i-29]; |
|---|
| 144 | } |
|---|
| 145 | pCvt[29+code_file_name_length] = code_verification_certificate; |
|---|
| 146 | |
|---|
| 147 | pCvtHeader[0] = 0xD9; |
|---|
| 148 | pCvtHeader[1] = 0x30; |
|---|
| 149 | pCvtHeader[2] = length_field; |
|---|
| 150 | |
|---|
| 151 | switch(download_command) |
|---|
| 152 | { |
|---|
| 153 | case 0:sprintf(filename,"cvt_dn_%d.%d", (pCvt[18]<<8)+pCvt[19],(pCvt[20]<<8)+pCvt[21]); break; |
|---|
| 154 | case 1:sprintf(filename,"cvt_df_%d.%d", (pCvt[18]<<8)+pCvt[19],(pCvt[20]<<8)+pCvt[21]); break; |
|---|
| 155 | case 2:sprintf(filename,"cvt_ne_%d.%d", (pCvt[18]<<8)+pCvt[19],(pCvt[20]<<8)+pCvt[21]); break; |
|---|
| 156 | default: break; |
|---|
| 157 | } |
|---|
| 158 | makefile(filename,pCvtHeader,pCvt,length_field,3000); |
|---|
| 159 | |
|---|
| 160 | printf("code_version_table_tag = 0x%6x\n",(pCvt[0]<<16) + (pCvt[1]<<8) + pCvt[2]); |
|---|
| 161 | printf("length_field = 0x%2x\n",pCvt[3]); |
|---|
| 162 | printf("number_of_descriptors = 0x%02x\n",pCvt[4]); |
|---|
| 163 | printf("descriptors[0].descriptor_tag = 0x%02x\n",pCvt[5]); |
|---|
| 164 | printf("descriptors[0].descriptor_len = 0x%02x\n",pCvt[6]); |
|---|
| 165 | printf("descriptors[0].descriptor_data = %c%c%c\n",pCvt[7],pCvt[8],pCvt[9]); |
|---|
| 166 | printf("descriptors[1].descriptor_tag = 0x%02x\n",pCvt[10]); |
|---|
| 167 | printf("descriptors[1].descriptor_len = 0x%02x\n",pCvt[11]); |
|---|
| 168 | printf("descriptors[1].descriptor_data = %c%c%c%c\n",pCvt[12],pCvt[13],pCvt[14],pCvt[15]); |
|---|
| 169 | printf("descriptors[2].descriptor_tag = 0x%02x\n",pCvt[16]); |
|---|
| 170 | printf("descriptors[2].descriptor_len = 0x%02x\n",pCvt[17]); |
|---|
| 171 | printf("descriptors[2].descriptor_data = %02x%02x%02x%02x\n",pCvt[18],pCvt[19],pCvt[20],pCvt[21]); |
|---|
| 172 | printf("download_type = 0x%02x\n",(pCvt[22]&0xF0)>>4); |
|---|
| 173 | printf("download_command = 0x%02x\n",pCvt[22]&0x0F); |
|---|
| 174 | printf("frequency_vector = 0x%04x\n",(pCvt[23]<<8) + pCvt[24]); |
|---|
| 175 | printf("transport_value = 0x%02x\n",pCvt[25]); |
|---|
| 176 | printf("PID = 0x%2x\n",(pCvt[26]<<8) + pCvt[27]); |
|---|
| 177 | printf("code_file_name_length = 0x%02x\n",pCvt[28]); |
|---|
| 178 | printf("code_file_name_byte = "); |
|---|
| 179 | |
|---|
| 180 | for(i=29;i<29+code_file_name_length;i++) |
|---|
| 181 | { |
|---|
| 182 | printf("%c",pCvt[i]); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | printf("\n"); |
|---|
| 186 | printf("code_verification_certificate = 0x%2x\n",pCvt[29+code_file_name_length]); |
|---|
| 187 | free(pCvt); |
|---|
| 188 | |
|---|
| 189 | return 0; |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | |
|---|