月光光つ 发表于 2016-5-12 16:53

华为EC1308机顶盒更改参数教程

华为EC1308机顶盒有几个版本,本方式只适用于采用海思Hi3560V100芯片,且存在设备文件/dev/misc/e2prom_24lc16的机顶盒。


用Telnet登录机顶盒,执行下面的命令:
ls -l /dev/misc/e2prom_24lc16**** Hidden Message *****
修改参数程序源代码如下:
#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;

      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, 18);
      stbid = '\0';

      return 0;
}

static int writeparam(unsigned char *mac, unsigned char *stbid)
{
      int fd, ret;
      e2prom_s_cmd arg;
      unsigned char buf;

      memcpy(buf, mac, 6);
      memcpy(&buf, 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;
      unsigned char mac;
      unsigned char stbid;

      if (readparam(mac, stbid) < 0)
                return 1;

      printf("Current parameters: \n");
      printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac, mac, mac, mac, mac, mac);
      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, &macs, &macs, &macs, &macs, &macs) != 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, mac, mac, mac, mac, mac);
      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;
}

人见百态 发表于 2016-5-12 17:18

虽不明,但觉厉!这个厉害哦 涨知识了    感谢楼主的分享!{znds8}{znds8}{znds8}

缓缓归矣 发表于 2016-5-13 16:47

感谢分享,ZNDS有你更精彩:)

似水年华 发表于 2016-5-14 10:15

谢谢分享。。。。

我的论坛 发表于 2016-5-14 10:23

谢谢分享。。。。

我的论坛 发表于 2016-5-14 10:25

楼主你说详细点吗?

我的论坛 发表于 2016-5-19 10:30

楼主能不能说详细点

wby 发表于 2016-5-20 15:20

强烈支持楼主ing……

snowsword2016 发表于 2016-5-28 20:26

好东西呀 楼主好人 一会去试试

sxhjzjbllb 发表于 2016-5-31 15:01

强烈支持楼主ing……
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 华为EC1308机顶盒更改参数教程