Jump to main content

##

# TCPIP_STACK_MACObjectGet Function

## C

    const TCPIP_MAC_OBJECT* TCPIP_STACK_MACObjectGet(
        TCPIP_NET_HANDLE netH
    );

## Description

This function returns the MAC driver object that's associated with the interface handle.

## Preconditions

The TCP/IP stack should have been initialized by TCPIP_STACK_Initialize() and the TCPIP_STACK_Status() returned SYS_STATUS_READY.

## Parameters

Parameters | Description
--- | ---
netH | Interface handle to get the name of.

## Returns

- A valid MAC driver object pointer if success.
- 0 if no such interface or there is no MAC object.

## Remarks

The MAC driver object is the one that's passed at the stack/interface initialization.

The MAC driver is not a true multi-client driver. Under normal circumstances the MAC driver has only one client, the TCP/IP stack. To have the TCPIP_MAC_Open() succeed after the MAC driver has been initialized by the TCP/IP stack, the configuration symbol DRV_ETHMAC_CLIENTS_NUMBER has to be > 1. But the returned handle is the same one that the TCP/IP stack uses.

Access to the MAC driver in this way is allowed mainly for debugging, diagnostic and statistics purposes. However, it is possible to transmit packets this way. But it's not possible to be signalled about incoming RX packets while the stack is running because only the TCP/IP dispatcher will be notified by the RX events.

## Example

    TCPIP_NET_HANDLE netH = TCPIP_STACK_NetHandleGet("eth0");
    const TCPIP_MAC_OBJECT* pEthMacObject = TCPIP_STACK_MACObjectGet(netH);
    if(pEthMacObject != 0)
    {    // valid MAC object pointer
        DRV_HANDLE hMac = (*pEthMacObject->TCPIP_MAC_Open)(pEthMacObject->macId, DRV_IO_INTENT_READWRITE);
        if(hMac != DRV_HANDLE_INVALID)
        {   // can use the MAC handle to access a MAC function
            TCPIP_MAC_RX_STATISTICS rxStatistics;
            TCPIP_MAC_TX_STATISTICS txStatistics;
            TCPIP_MAC_RES macRes = (*pEthMacObject->TCPIP_MAC_StatisticsGet)(hMac, &rxStatistics, &txStatistics);
        }
    }