Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[orchagent]: Enhance initSaiPhyApi #2367

Merged
merged 4 commits into from
Jul 18, 2022
Merged
Changes from 3 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
33 changes: 13 additions & 20 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,19 +374,11 @@ 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());
strncpy(hwinfo, phy->hwinfo.c_str(), HWINFO_MAX_SIZE);

attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO;
attr.value.s8list.count = (uint32_t) phy->hwinfo.length();
Expand Down Expand Up @@ -454,15 +443,19 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)

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

return status;
}