📄 cisco_eeprom.c
字号:
static m_uint16_t eeprom_c6k_chassis_6509_data[] = { 0xABAB, 0x0190, 0x0F0D, 0x0100, 0x0002, 0x6001, 0x9002, 0x4369, 0x7363, 0x6F20, 0x5379, 0x7374, 0x656D, 0x7300, 0x0000, 0x0000, 0x0000, 0x5753, 0x2D43, 0x3635, 0x3039, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5343, 0x4130, 0x3333, 0x3730, 0x314A, 0x5500, 0x0000, 0x0000, 0x0000, 0x0000, 0x3733, 0x2D33, 0x3433, 0x382D, 0x3033, 0x0000, 0x0000, 0x0000, 0x4230, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0009, 0x0005, 0x0001, 0x0002, 0x0001, 0x0016, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6001, 0x0124, 0x01AD, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0016, 0x00D0, 0x000F, 0x2000, 0x0400, 0x0009, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};/* Supervisor: SUP1A-2GE */static m_uint16_t eeprom_c6k_sup1a_2ge_data[] = { 0xABAB, 0x0190, 0x138F, 0x0100, 0x0002, 0x6003, 0x00DB, 0x4369, 0x7363, 0x6F20, 0x5379, 0x7374, 0x656D, 0x7300, 0x0000, 0x0000, 0x0000, 0x5753, 0x2D58, 0x364B, 0x2D53, 0x5550, 0x3141, 0x2D32, 0x4745, 0x0000, 0x0000, 0x5341, 0x4430, 0x3333, 0x3431, 0x3639, 0x3800, 0x0000, 0x0000, 0x0000, 0x0000, 0x3733, 0x2D34, 0x3336, 0x382D, 0x3031, 0x0000, 0x0000, 0x0000, 0x4130, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0009, 0x0005, 0x0001, 0x0003, 0x0001, 0x0001, 0x0002, 0x00DB, 0xFF56, 0x0000, 0x0000, 0x6003, 0x0162, 0x0B56, 0x0000, 0x0000, 0x0000, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0014, 0x00D0, 0xBCEE, 0xB920, 0x0002, 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1F02, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0200, 0x4132, 0x8181, 0x8181, 0x4B3C, 0x8080, 0x8080, 0x8080, 0x8080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};/* EARL: PFC1 (aka EARL5) */static m_uint16_t eeprom_c6k_earl_pfc1_data[] = { 0xABAB, 0x0190, 0x117D, 0x0100, 0x0002, 0x6004, 0x0066, 0x4369, 0x7363, 0x6F20, 0x5379, 0x7374, 0x656D, 0x7300, 0x0000, 0x0000, 0x0000, 0x5753, 0x2D46, 0x364B, 0x2D50, 0x4643, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5341, 0x4430, 0x3334, 0x3333, 0x3637, 0x3800, 0x0000, 0x0000, 0x0000, 0x0000, 0x3733, 0x2D34, 0x3037, 0x352D, 0x3033, 0x0000, 0x0000, 0x0000, 0x4130, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0009, 0x0005, 0x0001, 0x0003, 0x0001, 0x0001, 0x0010, 0x0066, 0xFFB0, 0x0000, 0x0000, 0x6004, 0x0148, 0x07B7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000E, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4B3C, 0x4132, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};/* Power Supply: 1000W */static m_uint16_t eeprom_c6k_power_1000w_data[] = { 0xABAB, 0x0190, 0x121C, 0x0100, 0x0002, 0xAB01, 0x0003, 0x4369, 0x7363, 0x6F20, 0x5379, 0x7374, 0x656D, 0x732C, 0x2049, 0x6E63, 0x2E00, 0x5753, 0x2D43, 0x4143, 0x2D31, 0x3030, 0x3057, 0x0000, 0x0000, 0x0000, 0x0000, 0x534F, 0x4E30, 0x3430, 0x3930, 0x3036, 0x3600, 0x0000, 0x0000, 0x0000, 0x0000, 0x3334, 0x2D30, 0x3932, 0x332D, 0x3031, 0x0000, 0x0000, 0x0000, 0x4230, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0009, 0x000C, 0x0003, 0x0001, 0x0006, 0x0003, 0x0000, 0x0000, 0x07EE, 0x0000, 0x0000, 0xAB01, 0x0114, 0x02C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x07EE, 0x07EE, 0x0015, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};/* VTT: Voltage Termination module */static m_uint16_t eeprom_c6k_vtt_data[] = { 0xABAB, 0x0190, 0x0FC4, 0x0100, 0x0002, 0xAB02, 0x0001, 0x4369, 0X7363, 0x6F20, 0x5379, 0x7374, 0x656D, 0x7300, 0x0000, 0x0000, 0x0000, 0x5753, 0x2D43, 0x3630, 0x3030, 0x2D56, 0x5454, 0x0000, 0x0000, 0x0000, 0x0000, 0x534D, 0x5430, 0x3333, 0x3531, 0x3330, 0x3400, 0x0000, 0x0000, 0x0000, 0x0000, 0x3733, 0x2D33, 0x3230, 0x382D, 0x3034, 0x0000, 0x0000, 0x0000, 0x4130, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0009, 0x0005, 0x0001, 0x0002, 0x0012, 0x0001, 0x0002, 0x0003, 0x0000, 0x0000, 0x0000, 0xAB02, 0x0118, 0x00C9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x6455, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};/* Linecard: WS-X6248 */static m_uint16_t eeprom_c6k_lc_wsx6248_data[] = { 0xABAB, 0x0190, 0x1339, 0x0100, 0x0002, 0x6003, 0x00CB, 0x4369, 0x7363, 0x6F20, 0x5379, 0x7374, 0x656D, 0x7300, 0x0000, 0x0000, 0x0000, 0x5753, 0x2D58, 0x3632, 0x3438, 0x2D52, 0x4A2D, 0x3435, 0x0000, 0x0000, 0x0000, 0x5341, 0x4430, 0x3333, 0x3436, 0x3834, 0x3200, 0x0000, 0x0000, 0x0000, 0x0000, 0x3733, 0x2D33, 0x3234, 0x342D, 0x3038, 0x0000, 0x0000, 0x0000, 0x4330, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0009, 0x0005, 0x0001, 0x0003, 0x0001, 0x0001, 0x0002, 0x00CB, 0xFEF3, 0x0000, 0x0000, 0x6003, 0x0162, 0x0B02, 0x0000, 0x0000, 0x0000, 0x0005, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x0030, 0xB6CC, 0x3CC0, 0x0030, 0x0106, 0x0003, 0x0001, 0x0002, 0x0002, 0x0001, 0x0004, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1230, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0200, 0x4B3C, 0x4132, 0x8181, 0x8181, 0x8080, 0x8080, 0x8080, 0x8080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};static const struct cisco_eeprom eeprom_c6k_array[] = { { "C6K-CHASSIS-6509", eeprom_c6k_chassis_6509_data, sizeof(eeprom_c6k_chassis_6509_data)/2 } , { "C6K-SUP-SUP1A-2GE", eeprom_c6k_sup1a_2ge_data, sizeof(eeprom_c6k_sup1a_2ge_data)/2 } , { "C6K-EARL-PFC1", eeprom_c6k_earl_pfc1_data, sizeof(eeprom_c6k_earl_pfc1_data)/2 } , { "C6K-POWER-1000W", eeprom_c6k_power_1000w_data, sizeof(eeprom_c6k_power_1000w_data)/2 } , { "C6K-VTT", eeprom_c6k_vtt_data, sizeof(eeprom_c6k_vtt_data) }, { "C6K-LC-WS-X6248", eeprom_c6k_lc_wsx6248_data, sizeof(eeprom_c6k_lc_wsx6248_data)/2 } , { NULL, NULL, 0 },};/* Find a C6k EEPROM */const struct cisco_eeprom *cisco_eeprom_find_c6k(char *name){ return(cisco_eeprom_find(eeprom_c6k_array,name));}/* ====================================================================== *//* Utility functions *//* ====================================================================== *//* Find an EEPROM in the specified EEPROM array */const struct cisco_eeprom *cisco_eeprom_find(const struct cisco_eeprom *eeproms,char *name){ int i; for(i=0;eeproms[i].name;i++) if (!strcmp(eeproms[i].name,name)) return(&eeproms[i]); return NULL;}/* Copy an EEPROM */int cisco_eeprom_copy(struct cisco_eeprom *dst,const struct cisco_eeprom *src){ m_uint16_t *data; if (!src || !src) return(-1); cisco_eeprom_free(dst); if (!(data = malloc(src->len << 1))) return(-1); memcpy(data,src->data,src->len << 1); dst->name = src->name; dst->data = data; dst->len = src->len; return(0);}/* Free resources used by an EEPROM */void cisco_eeprom_free(struct cisco_eeprom *eeprom){ if (eeprom && eeprom->data) { free(eeprom->data); eeprom->data = NULL; eeprom->len = 0; }}/* Return TRUE if the specified EEPROM contains usable data */int cisco_eeprom_valid(struct cisco_eeprom *eeprom){ return((eeprom && eeprom->data) ? TRUE : FALSE);}/* Get a byte from an EEPROM */int cisco_eeprom_get_byte(struct cisco_eeprom *eeprom, size_t offset,m_uint8_t *val){ m_uint16_t tmp; if (offset >= (eeprom->len << 1)) { *val = 0xFF; return(-1); } tmp = eeprom->data[offset >> 1]; if (!(offset & 1)) tmp >>= 8; *val = tmp & 0xFF; return(0);}/* Set a byte to an EEPROM */int cisco_eeprom_set_byte(struct cisco_eeprom *eeprom, size_t offset,m_uint8_t val){ m_uint16_t tmp; if (offset >= (eeprom->len << 1)) return(-1); tmp = eeprom->data[offset >> 1]; if (offset & 1) tmp = (tmp & 0xFF00) | val; else tmp = (tmp & 0x00FF) | (val << 8); eeprom->data[offset >> 1] = tmp; return(0);}/* Get an EEPROM region */int cisco_eeprom_get_region(struct cisco_eeprom *eeprom,size_t offset, m_uint8_t *data,size_t data_len){ size_t i; for(i=0;i<data_len;i++) { if (cisco_eeprom_get_byte(eeprom,offset+i,&data[i]) == -1) return(-1); } return(0);}/* Set an EEPROM region */int cisco_eeprom_set_region(struct cisco_eeprom *eeprom,size_t offset, m_uint8_t *data,size_t data_len){ size_t i; for(i=0;i<data_len;i++) { if (cisco_eeprom_set_byte(eeprom,offset+i,data[i]) == -1) return(-1); } return(0);}/* Get a field of a Cisco EEPROM v4 */int cisco_eeprom_v4_get_field(struct cisco_eeprom *eeprom,m_uint8_t *type, m_uint8_t *len,size_t *offset){ m_uint8_t tmp; /* Read field type */ if (cisco_eeprom_get_byte(eeprom,(*offset)++,type) == -1) return(-1); /* No more field */ if (*type == 0xFF) return(0); /* Get field length */ tmp = (*type >> 6) & 0x03; if (tmp == 0x03) { /* Variable len */ if (cisco_eeprom_get_byte(eeprom,(*offset)++,&tmp) == -1) return(-1); *len = tmp & 0x0F; } else { /* Fixed len */ *len = 1 << tmp; } return(1);}/* Dump a Cisco EEPROM with format version 4 */void cisco_eeprom_v4_dump(struct cisco_eeprom *eeprom){ m_uint8_t type,len,tmp; size_t i,offset=2; printf("Dumping EEPROM contents:\n"); do { /* Read field */ if (cisco_eeprom_v4_get_field(eeprom,&type,&len,&offset) < 1) break; printf(" Field 0x%2.2x: ",type); for(i=0;i<len;i++) { if (cisco_eeprom_get_byte(eeprom,offset+i,&tmp) == -1) break; printf("%2.2x ",tmp); } printf("\n"); offset += len; }while(offset < (eeprom->len << 1));}/* Returns the offset of the specified field */int cisco_eeprom_v4_find_field(struct cisco_eeprom *eeprom, m_uint8_t field_type, size_t *field_offset){ m_uint8_t type,len; size_t offset=2; do { /* Read field */ if (cisco_eeprom_v4_get_field(eeprom,&type,&len,&offset) < 1) break; if (type == field_type) { *field_offset = offset; return(0); } offset += len; }while(offset < (eeprom->len << 1)); return(-1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -