--- upstream/dynamips-0.2.6-RC1/cisco_eeprom.c 2007/10/06 16:03:58 2 +++ upstream/dynamips-0.2.6-RC2/cisco_eeprom.c 2007/10/06 16:05:34 3 @@ -15,16 +15,224 @@ #include "utils.h" #include "cisco_eeprom.h" +/* ====================================================================== */ +/* NM-1E: 1 Ethernet Port Network Module EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_nm_1e_data[16] = { + 0x0143, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000, + 0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* NM-4E: 4 Ethernet Port Network Module EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_nm_4e_data[16] = { + 0x0142, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000, + 0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* NM-1FE-TX: 1 FastEthernet Port Network Module EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_nm_1fe_tx_data[16] = { + 0x0144, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000, + 0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* NM-16ESW: 16 FastEthernet Port Switch Network Module EEPROM */ +/* ====================================================================== */ +static m_uint16_t eeprom_nm_16esw_data[] = { + 0x04FF, 0x4002, 0xA941, 0x0100, 0xC046, 0x0320, 0x003B, 0x3401, + 0x4245, 0x3080, 0x0000, 0x0000, 0x0203, 0xC18B, 0x3030, 0x3030, + 0x3030, 0x3030, 0x3030, 0x3003, 0x0081, 0x0000, 0x0000, 0x0400, + 0xCF06, 0x0013, 0x1A1D, 0x0BD1, 0x4300, 0x11FF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* NM-4T: 4 Serial Network Module EEPROM */ +/* ====================================================================== */ +static m_uint16_t eeprom_nm_4t_data[64] = { + 0x0154, 0x0101, 0x009D, 0x2D64, 0x5009, 0x0A02, 0x0000, 0x0000, + 0x5800, 0x0000, 0x9811, 0x0300, 0x0005, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* NM EEPROMs */ +/* ====================================================================== */ + +static const struct cisco_eeprom eeprom_nm_array[] = { + { "NM-1E", (m_uint16_t *)eeprom_nm_1e_data, sizeof(eeprom_nm_1e_data)/2 }, + { "NM-4E", (m_uint16_t *)eeprom_nm_4e_data, sizeof(eeprom_nm_4e_data)/2 }, + { "NM-1FE-TX", (m_uint16_t *)eeprom_nm_1fe_tx_data, + sizeof(eeprom_nm_1fe_tx_data)/2 }, + { "NM-16ESW", (m_uint16_t *)eeprom_nm_16esw_data, + sizeof(eeprom_nm_16esw_data)/2 }, + { "NM-4T", eeprom_nm_4t_data, sizeof(eeprom_nm_4t_data)/2 }, + { NULL, NULL, 0 }, +}; + +/* Find a NM EEPROM */ +const struct cisco_eeprom *cisco_eeprom_find_nm(char *name) +{ + return(cisco_eeprom_find(eeprom_nm_array,name)); +} + +/* ====================================================================== */ +/* PA-FE-TX: 1 FastEthernet Port Adapter EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_pa_fe_tx_data[16] = { + 0x0111, 0x0102, 0xffff, 0xffff, 0x4906, 0x9804, 0x0000, 0x0000, + 0x6000, 0x0000, 0x9812, 0x1700, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* PA-4E: 4 Ethernet Port Adapter EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_pa_4e_data[16] = { + 0x0102, 0x010E, 0xFFFF, 0xFFFF, 0x4906, 0x1404, 0x0000, 0x0000, + 0x5000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* PA-8E: 8 Ethernet Port Adapter EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_pa_8e_data[16] = { + 0x0101, 0x010E, 0xFFFF, 0xFFFF, 0x4906, 0x1404, 0x0000, 0x0000, + 0x5000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* PA-4T+: 4 Serial Port Adapter EEPROM */ +/* ====================================================================== */ +static m_uint16_t eeprom_pa_4t_data[64] = { + 0x010C, 0x010F, 0xffff, 0xffff, 0x4906, 0x2E07, 0x0000, 0x0000, + 0x5000, 0x0000, 0x0010, 0x2400, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* PA-8T: 8 Serial Port Adapter EEPROM */ +/* ====================================================================== */ +static m_uint16_t eeprom_pa_8t_data[64] = { + 0x010E, 0x010F, 0xffff, 0xffff, 0x4906, 0x2E07, 0x0000, 0x0000, + 0x5000, 0x0000, 0x0010, 0x2400, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* PA-A1: 1 ATM Port Adapter EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_pa_a1_data[64] = { + 0x0117, 0x010F, 0xffff, 0xffff, 0x4906, 0x2E07, 0x0000, 0x0000, + 0x5000, 0x0000, 0x0010, 0x2400, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* PA-POS-OC3: 1 POS Port Adapter EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_pa_pos_oc3_data[64] = { + 0x0196, 0x0202, 0xffff, 0xffff, 0x490C, 0x7806, 0x0000, 0x0000, + 0x5000, 0x0000, 0x0208, 0x1900, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* PA-4B: 4 BRI Port Adapter EEPROM */ +/* ====================================================================== */ +static const m_uint16_t eeprom_pa_4b_data[64] = { + 0x013D, 0x0202, 0xffff, 0xffff, 0x490C, 0x7806, 0x0000, 0x0000, + 0x5000, 0x0000, 0x0208, 0x1900, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +/* ====================================================================== */ +/* PA EEPROMs */ +/* ====================================================================== */ + +static const struct cisco_eeprom eeprom_pa_array[] = { + { "PA-FE-TX", (m_uint16_t *)eeprom_pa_fe_tx_data, + sizeof(eeprom_pa_fe_tx_data)/2 }, + { "PA-4E", (m_uint16_t *)eeprom_pa_4e_data, sizeof(eeprom_pa_4e_data)/2 }, + { "PA-8E", (m_uint16_t *)eeprom_pa_8e_data, sizeof(eeprom_pa_8e_data)/2 }, + { "PA-4T+", eeprom_pa_4t_data, sizeof(eeprom_pa_4t_data)/2 }, + { "PA-8T", eeprom_pa_8t_data, sizeof(eeprom_pa_8t_data)/2 }, + { "PA-A1", (m_uint16_t *)eeprom_pa_a1_data, sizeof(eeprom_pa_a1_data)/2 }, + { "PA-POS-OC3", (m_uint16_t *)eeprom_pa_pos_oc3_data, + sizeof(eeprom_pa_pos_oc3_data)/2 }, + { "PA-4B", (m_uint16_t *)eeprom_pa_4b_data, sizeof(eeprom_pa_4b_data)/2 }, + { NULL, NULL, 0 }, +}; + +/* Find a PA EEPROM */ +const struct cisco_eeprom *cisco_eeprom_find_pa(char *name) +{ + return(cisco_eeprom_find(eeprom_pa_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(m_uint16_t *eeprom,size_t eeprom_len, +int cisco_eeprom_get_byte(struct cisco_eeprom *eeprom, size_t offset,m_uint8_t *val) { m_uint16_t tmp; - - if (offset >= eeprom_len) + + if (offset >= (eeprom->len << 1)) return(-1); - tmp = eeprom[offset >> 1]; + tmp = eeprom->data[offset >> 1]; if (!(offset & 1)) tmp >>= 8; @@ -34,33 +242,33 @@ } /* Set a byte to an EEPROM */ -int cisco_eeprom_set_byte(m_uint16_t *eeprom,size_t eeprom_len, +int cisco_eeprom_set_byte(struct cisco_eeprom *eeprom, size_t offset,m_uint8_t val) { m_uint16_t tmp; - if (offset >= eeprom_len) + if (offset >= (eeprom->len << 1)) return(-1); - tmp = eeprom[offset >> 1]; + tmp = eeprom->data[offset >> 1]; if (offset & 1) tmp = (tmp & 0xFF00) | val; else tmp = (tmp & 0x00FF) | (val << 8); - eeprom[offset >> 1] = tmp; + eeprom->data[offset >> 1] = tmp; return(0); } /* Get an EEPROM region */ -int cisco_eeprom_get_region(m_uint16_t *eeprom,size_t eeprom_len, - size_t offset,m_uint8_t *data,size_t data_len) +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;ilen << 1)); } /* Returns the offset of the specified field */ -int cisco_eeprom_v4_find_field(m_uint16_t *eeprom,size_t eeprom_len, - m_uint8_t field_type,size_t *field_offset) +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,eeprom_len,&type,&len,&offset) < 1) + if (cisco_eeprom_v4_get_field(eeprom,&type,&len,&offset) < 1) break; if (type == field_type) { @@ -158,7 +367,7 @@ } offset += len; - }while(offset < eeprom_len); + }while(offset < (eeprom->len << 1)); return(-1); }