Fix Ethertype decimal-to-hex conversion for TR-181 compliance

Problem

The current Ethertype parameter handling in QoS Classification has an issue where decimal values (as specified by TR-181) are not properly converted to hexadecimal format for UCI configuration storage.

Issue Symptoms:

  • Setting Device.QoS.Classification.1.Ethertype 2054 results in UCI config: option ethertype '2054'
  • But the system expects hexadecimal format: option ethertype '0x0806'
  • This causes the QoS classification rule to not work properly

Steps to Reproduce:

# Via TR-181 interface
set EasyDM.QoS.Class.lan1_eth_type.Ethertype 2054
# Results in broken UCI config:
# option ethertype '2054'

Working Workaround:

# Manual UCI fix required:
uci set qos.@classify[0].ethertype='0x0806'
uci commit
/etc/init.d/qos restart

Solution

This MR improves the Ethertype parameter handling functions to:

  1. Strict TR-181 Compliance: Only accept decimal integer input as per TR-181 specification
  2. Proper Conversion: Convert decimal input to hexadecimal format for UCI storage
  3. Better Error Handling: Enhanced validation and error checking
  4. Backward Compatibility: Maintain compatibility with existing -1 (disabled) values

Key Changes:

get_QoSClassification_Ethertype:

  • Enhanced to handle both hex-stored values and decimal values
  • Properly converts hex (0x0806) back to decimal (2054) for TR-181 interface
  • Improved error handling

set_QoSClassification_Ethertype:

  • Strict decimal validation as per TR-181 spec
  • Proper handling of -1 (disabled) case
  • Automatic conversion from decimal to hex for UCI storage
  • Better error validation

Example Flow:

TR-181 Input: 2054 (decimal)

UCI Storage: 0x0806 (hex)  

TR-181 Output: 2054 (decimal)

Testing

The fix resolves the original issue:

  • set Device.QoS.Classification.1.Ethertype 2054 now works correctly
  • Results in proper UCI config: option ethertype '0x0806'
  • QoS classification rules function as expected
  • Maintains backward compatibility

Related Issues

This is similar to fixes applied in libbbfdm for the same Ethertype handling issue.

Verification

  • Unit tests pass
  • QoS classification with Ethertype works correctly
  • UCI configuration contains proper hex format
  • TR-181 interface returns decimal values correctly
  • Backward compatibility maintained

Merge request reports

Loading