Skip to content

Commit 91661db

Browse files
fredrikdanielmollerhefloryd
authored andcommitted
rt-kernel: Fix ifSpeed in SNMP MIB-II ifTable
1 parent 0e20c71 commit 91661db

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/ports/rt-kernel/dwmac1000.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ typedef struct dwmac1000
252252
* PHY at startup.
253253
*/
254254
uint16_t anar;
255+
256+
/* lwip network interface handle */
257+
struct netif * netif;
255258
} dwmac1000_t;
256259

257260
#ifdef DEBUG_DATA
@@ -289,6 +292,24 @@ static void dwmac1000_pbuf_dump (struct pbuf * p)
289292
}
290293
#endif /* DEBUG_DATA */
291294

295+
#if MIB2_STATS
296+
static uint32_t dwmac1000_snmp_link_speed (uint8_t link_state)
297+
{
298+
if (link_state & PHY_LINK_10MBIT)
299+
{
300+
return 10 * 1000 * 1000;
301+
}
302+
else if (link_state & PHY_LINK_100MBIT)
303+
{
304+
return 100 * 1000 * 1000;
305+
}
306+
else
307+
{
308+
return 0;
309+
}
310+
}
311+
#endif /* MIB2_STATS */
312+
292313
static uint16_t dwmac1000_read_phy (void * arg, uint8_t address, uint8_t reg)
293314
{
294315
dwmac1000_t * dwmac1000 = arg;
@@ -727,6 +748,11 @@ static dev_state_t dwmac1000_probe (drv_t * drv)
727748
/* Save link state for IOCTL_NET_GET_STATUS */
728749
dwmac1000->last_link_state = link_state;
729750

751+
/* Set ifSpeed in SNMP MIB-II ifTable */
752+
#if MIB2_STATS
753+
dwmac1000->netif->link_speed = dwmac1000_snmp_link_speed (link_state);
754+
#endif /* MIB2_STATS */
755+
730756
return (link_state & PHY_LINK_OK) ? StateAttached : StateDetached;
731757
}
732758

@@ -815,6 +841,7 @@ drv_t * dwmac1000_init (
815841
dwmac1000->mmc = (eth_mmc_t *)(cfg->base + 0x100);
816842
dwmac1000->dma = (eth_dma_t *)(cfg->base + 0x1000);
817843
dwmac1000->last_link_state = 0x00;
844+
dwmac1000->netif = netif;
818845

819846
/* Create receive task */
820847
dwmac1000->tRcv = task_spawn (

0 commit comments

Comments
 (0)