Skip to content

[cmis] Fix enter_password to include standard password entry method#724

Open
Junchao-Mellanox wants to merge 2 commits into
sonic-net:masterfrom
Junchao-Mellanox:public/pr-19
Open

[cmis] Fix enter_password to include standard password entry method#724
Junchao-Mellanox wants to merge 2 commits into
sonic-net:masterfrom
Junchao-Mellanox:public/pr-19

Conversation

@Junchao-Mellanox

Copy link
Copy Markdown
Contributor

Why I did it

CdbCmdHandler.enter_password() previously delivered the CMIS host password only via CDB command 0001h. This is not the standard mechanism defined by the CMIS spec and is not honored by all modules — the standard, universally-supported way to unlock password-protected CDB/EEPROM access is to write the 4-byte host password (MSB first) to the Password Entry Area at page 00h bytes 122-125. As a result, password entry would fail on modules that only unlock via the Password Entry Area, blocking protected CDB/EEPROM operations (e.g. firmware/SED-protected access) on those modules.

How I did it

  • cdb.py — Reworked enter_password() to first write the password to the Password Entry Area (page 00h bytes 122-125, MSB first) using write_raw, which is the standard method honored by all CMIS modules. If that write fails, it falls back to the original CDB command 0001h path for modules that rely on it. Input validation (integer in range 0..0xFFFFFFFF) is preserved, and struct is used to pack the 32-bit password big-endian.
  • cdb_consts.py — Added CDB_HOST_PASSWORD_ENTRY_OFFSET = 122 and CDB_HOST_PASSWORD_ENTRY_SIZE = 4 with documentation describing the Password Entry Area register layout.
  • test_cdb.py — Updated existing tests to assert the password is now written MSB-first to the Password Entry Area (and that no CDB command is sent when the register write succeeds), and added test_enter_password_fallback_to_cdb_command to cover the fallback path when the register write fails.

How to verify it

Ran the updated unit tests in tests/sonic_xcvr/test_cdb.py, covering:

  • test_enter_password_valid — password written MSB-first to the Password Entry Area, no CDB command issued.
  • test_enter_password_default — default password (0x00001011) written to the Password Entry Area.
  • test_enter_password_fallback_to_cdb_command — CDB command 0001h used as fallback when the register write returns False.

#### Why I did it
`CdbCmdHandler.enter_password()` previously delivered the CMIS host password only via CDB command `0001h`. This is not the standard mechanism defined by the CMIS spec and is not honored by all modules — the standard, universally-supported way to unlock password-protected CDB/EEPROM access is to write the 4-byte host password (MSB first) to the Password Entry Area at page 00h bytes 122-125. As a result, password entry would fail on modules that only unlock via the Password Entry Area, blocking protected CDB/EEPROM operations (e.g. firmware/SED-protected access) on those modules.

#### How I did it
- `cdb.py` — Reworked `enter_password()` to first write the password to the Password Entry Area (page 00h bytes 122-125, MSB first) using `write_raw`, which is the standard method honored by all CMIS modules. If that write fails, it falls back to the original CDB command `0001h` path for modules that rely on it. Input validation (integer in range `0..0xFFFFFFFF`) is preserved, and `struct` is used to pack the 32-bit password big-endian.
- `cdb_consts.py` — Added `CDB_HOST_PASSWORD_ENTRY_OFFSET = 122` and `CDB_HOST_PASSWORD_ENTRY_SIZE = 4` with documentation describing the Password Entry Area register layout.
- `test_cdb.py` — Updated existing tests to assert the password is now written MSB-first to the Password Entry Area (and that no CDB command is sent when the register write succeeds), and added `test_enter_password_fallback_to_cdb_command` to cover the fallback path when the register write fails.

#### How to verify it
Ran the updated unit tests in `tests/sonic_xcvr/test_cdb.py`, covering:
- `test_enter_password_valid` — password written MSB-first to the Password Entry Area, no CDB command issued.
- `test_enter_password_default` — default password (`0x00001011`) written to the Password Entry Area.
- `test_enter_password_fallback_to_cdb_command` — CDB command `0001h` used as fallback when the register write returns `False`.

Signed-off-by: Junchao Chen <junchao@mellanox.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@Junchao-Mellanox

Copy link
Copy Markdown
Contributor Author

Hi @prgeor , @mihirpat1 , could you please help review this? Thanks!

stephenxs
stephenxs previously approved these changes Jul 21, 2026
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
Signed-off-by: Junchao Chen <junchao@mellanox.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants