The following code structure illustrates how the Atheros Embedded API can be used to process incoming vendor-specific messages using Embedded API functions. Notice that only two Embedded API functions, ihpapi_RxFrame and ihpapi_TxFrame, are called. Between them, they manage the sequence of operations needed to support Host Action Required messages received from Atheros chipsets using a local host.
Example 3.11. Message Handling Loop
#include <stdint.h>
#include <errno.h>
#include <transport.h>
#include "ihpapi.h"
int8_t packet [ETHER_MAX_LEN]
size_t length;
ihpapi_result_t result;
ihpapi_status_t status;
read(&length, packet);
if (isHomePlugEthertype(&frame))
{
if (ihpapi_RxFrame(sizeof (packet), packet, &result))
{
processErrorStatus(&result.opStatus)
}
else
{
if(IHPAPI_OPCODE_NOOP == result.opcode)
{
processTheResponse(&result);
}
length = ihpapi_TxFrame(sa, da, sizeof (packet), packet, &status)
if (length)
{
send (length, packet);
}
}
}
The application must provide raw packet read and send functions for the targetenvironment because the Embedded API does not presume to know anything about the environment. The Powerline Toolkit readpacket and sendpacket are examples of such functions.
The application must also provide processErrorStatus and processTheResponse functions or logical equivalents. These can take several forms depending on the application. Examples can be seen in various components of program int6k2 where function RdModWrPib2 may be the best example. Others include FactoryDefaults2, HostActionWait2, Identity2, MfgString2, NetworkInfo2, ReadMAC2, ReadPIB2, ResetDevice2, SetKey2, SetSDRAM2, Upgrade2 and VersionInfo2.