華為EC1308機(jī)頂盒有幾個(gè)版本,本方式只適用于采用海思Hi3560V100芯片,且存在設(shè)備文件/dev/misc/e2prom_24lc16的機(jī)頂盒。
用Telnet登錄機(jī)頂盒,執(zhí)行下面的命令:
ls -l /dev/misc/e2prom_24lc16
修改參數(shù)程序源代碼如下:
#include <fcntl.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>
typedef struct {
unsigned int e2prom_cmd_sub_addr;
unsigned int sub_addr_count;
unsigned char* e2prom_cmd_data;
unsigned int data_count;
} e2prom_s_cmd;
#define E2PROM_CMD_READ 1
#define E2PROM_CMD_WRITE 2
#define E2PROM_DEVICE "/dev/misc/e2prom_24lc16"
static int readparam(unsigned char *mac, unsigned char *stbid)
{
int fd, ret;
e2prom_s_cmd arg;
unsigned char buf[0x18];
fd = open(E2PROM_DEVICE, O_RDWR);
if (fd < 0) {
printf("Device %s open error.\n", E2PROM_DEVICE);
return -1;
}
arg.sub_addr_count = 2;
arg.data_count = 0x18;
arg.e2prom_cmd_sub_addr = 0x290;
arg.e2prom_cmd_data = buf;
ret = ioctl(fd, E2PROM_CMD_READ, &arg);
if (ret != 0) {
printf("Device %s read error.\n", E2PROM_DEVICE);
return -1;
}
memcpy(mac, buf, 6);
memcpy(stbid, &buf[6], 18);
stbid[18] = '\0';
return 0;
}
static int writeparam(unsigned char *mac, unsigned char *stbid)
{
int fd, ret;
e2prom_s_cmd arg;
unsigned char buf[0x18];
memcpy(buf, mac, 6);
memcpy(&buf[6], stbid, 18);
fd = open(E2PROM_DEVICE, O_RDWR);
if (fd < 0) {
printf("Device %s open error.\n", E2PROM_DEVICE);
return -1;
}
arg.sub_addr_count = 2;
arg.data_count = 0x18;
arg.e2prom_cmd_sub_addr = 0x290;
arg.e2prom_cmd_data = buf;
ret = ioctl(fd, E2PROM_CMD_WRITE, &arg);
if (ret != 0) {
printf("Device %s write error.\n", E2PROM_DEVICE);
return -1;
}
return 0;
}
int main()
{
char c;
int i, macs[6];
unsigned char mac[6];
unsigned char stbid[256];
if (readparam(mac, stbid) < 0)
return 1;
printf("Current parameters: \n");
printf(" MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
printf(" STBID: %s\n", stbid);
printf("\nPlease input new MAC (1a:2b:3c:4d:5e:6f): ");
if (scanf("%02x:%02x:%02x:%02x:%02x:%02x", &macs[0], &macs[1], &macs[2], &macs[3], &macs[4], &macs[5]) != 6) {
printf("Input MAC error\n");
return 1;
}
for (i=0; i<6; i++)mac = macs;
printf("\nPlease input new STBID: ");
scanf("%s", stbid);
if (strlen(stbid) != 18) {
printf("Invalid stbid\n");
return 1;
}
printf("\nNew parameters: \n");
printf(" MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
printf(" STBID: %s\n", stbid);
printf("\nDo you want to change paramemters? (y/N) ");
for (;;) {
c = getchar();
if (c == 'y' || c == 'Y')
break;
if (c == 'n' || c == 'N') {
printf("\nAborted.\n");
return 1;
}
}
if (writeparam(mac, stbid) == 0)
printf("Parameters changed.\n");
return 0;
} |