Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions orchagent/saihelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,6 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)
sai_status_t status;
char fwPath[PATH_MAX];
char hwinfo[HWINFO_MAX_SIZE + 1];
char hwinfoIntf[IFNAMSIZ + 1];
unsigned int hwinfoPhyid;
int ret;

SWSS_LOG_ENTER();

Expand All @@ -377,22 +374,15 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)
attr.value.u32 = 0;
attrs.push_back(attr);

ret = sscanf(phy->hwinfo.c_str(), "%" STR(IFNAMSIZ) "[^/]/%u", hwinfoIntf, &hwinfoPhyid);
if (ret != 2) {
SWSS_LOG_ERROR("BOX: hardware info doesn't match the 'interface_name/phyid' "
"format");
return SAI_STATUS_FAILURE;
if( phy->hwinfo.length() > HWINFO_MAX_SIZE ) {
SWSS_LOG_ERROR( "hwinfo string attribute is too long." );
return SAI_STATUS_FAILURE;
}

if (hwinfoPhyid > std::numeric_limits<uint16_t>::max()) {
SWSS_LOG_ERROR("BOX: phyid is bigger than maximum limit");
return SAI_STATUS_FAILURE;
}

strcpy(hwinfo, phy->hwinfo.c_str());
memset(hwinfo, 0, HWINFO_MAX_SIZE + 1);
strncpy(hwinfo, phy->hwinfo.c_str(), phy->hwinfo.length());

attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO;
attr.value.s8list.count = (uint32_t) phy->hwinfo.length();
attr.value.s8list.count = (uint32_t) phy->hwinfo.length() + 1;
attr.value.s8list.list = (int8_t *) hwinfo;
attrs.push_back(attr);

Expand Down Expand Up @@ -452,17 +442,21 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)

phy->phy_oid = sai_serialize_object_id(phyOid);

attr.id = SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION;
status = sai_switch_api->get_switch_attribute(phyOid, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("BOX: Failed to get firmware major version:%d rtn:%d", phy->phy_id, status);
return status;
}
else
if (phy->firmware.length() != 0)
{
phy->firmware_major_version = string(attr.value.chardata);
attr.id = SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION;
status = sai_switch_api->get_switch_attribute(phyOid, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("BOX: Failed to get firmware major version for hwinfo:%s, phy:%d, rtn:%d",
phy->hwinfo.c_str(), phy->phy_id, status);
return status;
}
else
{
phy->firmware_major_version = string(attr.value.chardata);
}
}

return status;
}