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

realtek-poe: Add PSE ID quirk for Zyxel GS1900-24HP-v1 #6

Merged
merged 3 commits into from
Jul 3, 2022

Commits on Jun 28, 2022

  1. realtek-poe: Fix expression expansion in GET_STR() macro

    What does GET_STR() expand to? For simple cases, it's trivial.
    Operator precedence in C can result in unexpected behavior when
    "a" or "b" are complex expressions:
    
        GET_STR(i + 2, array)
          ==> (i + 2 < ARRAY_SIZE() ? array[i + 2] : NULL);
        GET_STR(1, array + i)
          ==> (1 < ARRAY_SIZE() ? array + i[1] : NULL)
    
    The former incorrectly checks the array size against the second term,
    but dereferences a higher index. It can result in out-of-bounds reads.
    The latter results in nonsense code
    
    Macro expansions can be fixed by enclosing expresions in parentheses.
    This ensures expressions get evaluated in the expected order. Add
    parentheses in GET_STR(), where appropriate.
    
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
    mrnuke committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    7e6bfe3 View commit details
    Browse the repository at this point in the history
  2. realtek-poe: Fix status for devices with more than 8 PoE ports

    Only status data for the first 8 ports was requested. Most devices
    have 8 ports, and the reply packet has room for 8 ports. It was the
    perfect match!
    
    People quickly figured out realtek-poe works for unicorn switches with
    more than 8 PoE ports. And so they did. And they increased MAX_PORT
    without regards to the out-of-bounds access problem they created. And
    realtek-poe refused to crash!
    
    Command 0x2a has proven to be unreliable for devices with more than
    8 ports. It returns garbage for ports > 8, even on switchea with more
    than 8 PoE ports.
    
    Command 0x28 is more reliable. It only sends 4 port statuses per
    packet, but returns correct data. If the port number exceeds the total
    ports on the device, it correctly returns 0xff.
    
    Replace port status query with command 0x28.
    
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
    mrnuke committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    5579790 View commit details
    Browse the repository at this point in the history
  3. realtek-poe: Add PSE ID quirk for Zyxel GS1900-24HP-v1

    The "set global power budget" command contains a PSE controller in its
    argument list. This was hardcoded to 0. On some switches, commands to
    PSE 0 do nothing. In those cases, the set budget command won't stick.
    The power budget remains at its default value, usually 0. Because of
    this, ports remain stuck in the "Requesting power" state.
    
    To solve this, send the budget command to the correct PSE ID or set of
    IDs. Use a mask to encode which PSE IDs neet the set budget command.
    When the "compatible" devicetree string matches Zyxel GS1900-24HP-v1,
    set the mask to 0xff, to command PS ID's 0->7. The vendor firmware
    also uses ID's 0->7. This enables power delivery to PoE sinks.
    
    Tested-by: Martin Kennedy hurricos@gmail.com
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
    mrnuke committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    a19d224 View commit details
    Browse the repository at this point in the history