Commit 8886548b authored by Michal Wasiak's avatar Michal Wasiak Committed by Adam Wujek

userspace/libwr: add function to change order o bits in a portmask

Used by SNMP
Signed-off-by: 's avatarMichal Wasiak <michal.wasiak@gmail.com>
parent fea1d9ec
......@@ -30,4 +30,7 @@ void *create_map(unsigned long address, unsigned long size);
/* Count bits in a unsigned int */
unsigned int bitCount (unsigned int value);
/* Convert bitmask of ports from notation used by RTU (lowest port on lowest bit)
* to notation used by SNMP (lowrst port, most significant bit) */
void convert_portmask_to_snmp_bitmask(int nports, uint32_t port_mask, char *bitmask, size_t *snmp_bitmask_len);
#endif /* __LIBWR_HW_UTIL_H */
......@@ -144,3 +144,24 @@ unsigned int bitCount (unsigned int value) {
return count;
}
/* Convert bitmask of ports from notation used by RTU (lowest port on lowest bit)
* to notation used by SNMP (lowrst port, most significant bit) */
void convert_portmask_to_snmp_bitmask(int nports, uint32_t port_mask, char *bitmask, size_t *snmp_bitmask_len)
{
int i;
/* round up number of ports to a number dividable by 8 */
nports = 8 * ((nports + 7) / 8);
for (i = 0; i < nports;i++){
*bitmask |= port_mask & 1;
port_mask >>= 1;
/* jump to next char */
if (i % 8 == 7) {
bitmask++;
*bitmask = 0;
}
*bitmask <<= 1;
}
/* count the number of bytes used */
*snmp_bitmask_len = nports / 8;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment