Chapter 8.  Embedded API Reference

Table of Contents

Introduction
External API Functions
ihpapi_InitializeDevice
ihpapi_UpdateDevice
ihpapi_ResetDevice
ihpapi_RxFrame
ihpapi_TxFrame
ihpapi_ManageEnetPHY
ihpapi_SetSDRAMConfig
ihpapi_GetVersionInfo
ihpapi_GetManufacturerInfo
ihpapi_SetKey
ihpapi_GetNetworkInfo
ihpapi_GetConnectionInfo
ihpapi_GetToneMapInfo
Internal API Functions
EncodeEthernetHeader
EncodeAtherosHeader
ihp_DecodeGetVersion
ihp_DecodeLinkStats
ihp_DecodeNetworkInfo
ihp_DecodeSetKey
ihp_DecodeMfgString
ihp_DecodeHostAction
ihp_DecodeResetDevice
ihp_DecodeResetToFactoryDefaults
ihp_DecodeSetSDRAMCfg
ihp_DecodeGetToneMapInfo
ihp_DecodeEthernetPHYSettings
ihp_DecodeGetRxToneMap
ihp_DecodeSetLEDBehavior
ihp_DecodeStartMAC
ihp_DecodeReadModule
ihp_DecodeWriteModule
ihp_DecodeWriteMemory
ihp_DecodeFlashNVM
ihp_DecodeGetNVM
ihp_SequenceReadModule
ihp_SequenceWriteModule
ihp_SequenceWriteMemory
ihp_FindFWHeader

Introduction

This chapter is a function reference for the Atheros Embedded API. It assumes that the reader has a copy of the Atheros HomePlug AV Application Programming Interface User's Guide and the Atheros HomePlug AV Firmware Technical Reference Manual. Obtain copies from Atheros Communications, Ocala FL USA, if you do not have them.

Atheros supports three levels of Application Programming Interface (API), described below. Atheros device operations are ultimately performed by sending and receiving Atheros vendor-specific management messages using ISO Layer 2 Ethernet frames. The HomePlug AV API assists application developers with common Atheros powerline device operations with the encoding and decoding of Ethernet frames and the automation of transaction sequences. Application developers must still select appropriate raw packet send and receive function and implement process decision logic.

Management Messages

Management messages are the lowest level interface to Atheros powerline devices. They consist of Ethernet frames exchanged between a host processor and Atheros powerline devices connected to the host via an ethernet connection. Some messages can be forwared from one powerline device to another overpowerline. Others cannot. An application must allocate memory for the Ethernet frame, encode it with the correct information and then transmit it using a raw Ethernet socket.

Application developers must understand each and every managment message transmitted or received and write program logic to encode and decode each type of Ethernet frame. They must also understand how to send and receive ISO Layer 2 Ethernet frames from their host processor. Management message function and format are explained in HomePlug AV Firmware Technical Reference Manual. Management messages are often added with new firmware revisions.

Application developers must take into account the endian-ness of their host processor when encoding and decoding managment messages.

Internal API Functions

Ethernet frame encoding is not difficult but it can be tedious and repetitive to implement. The Embedded API includes a number of core functions that can assist programmers in encoding and decoding Ethernet frames containing Atheros vendor-specific management messages. Atheros has defined a series of data structures that correspond to common powerline device operations and function that process them.

Applications populate structures and pass to frame encoders to create well-formed management messages for transmission. They all oass them to frame decoders to populate them from management messages received from powerline devices. This approach isolates application software from implementation or platform details such as data offsets, data interpretation and processor byte order.

Many powerline device operations require a sequence of transactions to complete. For example, downloading firmware to a powerline device requires multiple transactions because the firmware exceeds the data capacity of an Ethernet frame. Other operations, like device initiialization, also require multiple management message types. In addition, transmission errors can occur and must ve handled before proceeding.

External API Functions

The Atheros Embedded API is designed to listen for Atheros powerline device requests and respond to them. It also supports an number of device and network interrogation operations that return critical or, in some cases, complex information. Applications routinely execute a basic loop to detect powerline device requests and decode them. The application determines what sort of response is required, encodes it and transmits it and awaits acknowledgement from the powerline device.

A key feature of the Embedded API is that application programmers need not deal with Atheros vendor-specific management messages directly. Management messages are handled by the Core API Functions mentioned above. Also, processor byte-order issues are handled internally.

Example 8.1.  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(&amp;length, packet);                                   
if (isHomePlugEthertype(&frame))
{                  
 	if (ihpapi_RxFrame(sizeof (packet), packet, &result))  
	{
       		processErrorStatus(&amp;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 message handling code shown above briefly demonstrates how the Atheros Embedded API could be used to dynamically handle an incoming vendor-specific message. Notice that only two API functions are used: RxFrame and TxFrame. The application developer must select the appropriate read and send function and must design and implement function processTheResponse.