Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / wmi / wmi_svc_api.h
1 /*
2  * Copyright (c) 2007 Atheros Communications Inc.
3  * All rights reserved.
4  *
5  * This file contains the API for the Wireless Module Interface (WMI) Service
6  * 
7  */
8
9 #ifndef WMI_SVC_API_H_
10 #define WMI_SVC_API_H_
11
12 #include <htc.h>
13 #include <htc_api.h>
14 #include <wmi.h>
15 #include <adf_nbuf.h>
16 #include <buf_pool_api.h>
17
18 #define WMI_SVC_MAX_BUFFERED_EVENT_SIZE 100
19 #define WMI_SVC_MSG_SIZE                1536    /* maximum size of any WMI control or event message */
20
21 /* event classes */
22 typedef enum WMI_EVT_CLASS {
23         WMI_EVT_CLASS_NONE = -1,
24         WMI_EVT_CLASS_CMD_EVENT = 0,
25         WMI_EVT_CLASS_CMD_REPLY = 1,            
26         WMI_EVT_CLASS_MAX
27 } WMI_EVT_CLASS;
28
29 /* command handler callback when a message is dispatched */
30 typedef void (* WMI_CMD_HANDLER)(void *pContext,     /* application supplied context from dispatch table */
31                                  A_UINT16 Command,      /* command ID that was dispatched */
32                                  A_UINT16 SeqNo,
33                                  A_UINT8 *pCmdBuffer,   /* command data, 256 bytes max, 32-bit aligned */
34                                  int Length);      /* length of command (excludes WMI header) */
35
36 /* configuration settings for the WMI service */
37 typedef struct _WMI_SVC_CONFIG {
38         htc_handle_t    HtcHandle;
39         pool_handle_t   PoolHandle;
40         int             MaxCmdReplyEvts;    /* total buffers for command replies */
41         int             MaxEventEvts;       /* total buffers for low priority events */
42 } WMI_SVC_CONFIG;
43                                                 
44 /* command dispatch entry */
45 typedef struct _WMI_DISPATCH_ENTRY {
46         WMI_CMD_HANDLER      pCmdHandler;    /* dispatch function */
47         A_UINT16             CmdID;          /* WMI command to dispatch from */
48         A_UINT16             CheckLength;    /* expected length of command, set to 0 to bypass check */    
49 } WMI_DISPATCH_ENTRY;
50
51 /* dispatch table that is used to register a set of dispatch entries */
52 typedef struct _WMI_DISPATCH_TABLE {
53         struct _WMI_DISPATCH_TABLE *pNext;              /* next dispatch, WMI-reserved */
54         void                       *pContext;           /* optional context that is passed to command handlers 
55                                                            assigned to this dispatch table  */
56         int                         NumberOfEntries;    /* number of elements pointed to by pTable */
57         WMI_DISPATCH_ENTRY         *pTable;             /* start of table */
58 } WMI_DISPATCH_TABLE;
59
60 #define WMI_DISPATCH_ENTRY_COUNT(table) \
61     (sizeof((table)) / sizeof(WMI_DISPATCH_ENTRY))  
62
63     /* handy macro to declare a dispatch table */
64 #define WMI_DECLARE_DISPATCH_TABLE(name,dispatchEntries)         \
65 WMI_DISPATCH_TABLE name =                                        \
66 {   NULL, NULL, WMI_DISPATCH_ENTRY_COUNT(dispatchEntries), dispatchEntries }
67
68     /* macro to programatically set the dispatch table context */
69 #define WMI_SET_DISPATCH_CONTEXT(pDispTable, pCtxt)  (pDispTable)->pContext = (pCtxt)
70
71 typedef struct _WMI_BUF_CONTEXT {
72         HTC_BUF_CONTEXT     HtcBufCtx;
73         
74         WMI_EVT_CLASS       EventClass;   /* the event class this packet belongs to */ 
75         A_UINT16            Flags;        /* internal flags reserved for WMI */     
76 } WMI_BUF_CONTEXT;
77
78 /* ROM-version, eventually. For now, in RAM */
79     
80 typedef void* wmi_handle_t;
81    
82 /* the API table */
83 typedef struct _wmi_svc_apis {
84         wmi_handle_t    (* _WMI_Init)(WMI_SVC_CONFIG *pWmiConfig);
85         void            (* _WMI_RegisterDispatchTable)(wmi_handle_t h, WMI_DISPATCH_TABLE *pDispatchTable);
86         adf_nbuf_t      (* _WMI_AllocEvent)(wmi_handle_t h, WMI_EVT_CLASS EventClass, int Length);
87         void            (* _WMI_SendEvent)(wmi_handle_t h, adf_nbuf_t pEvt, A_UINT16 EventId, A_UINT16 SeqNo, int Length);
88         int             (* _WMI_GetPendingEventsCount)(wmi_handle_t handle);
89         void            (* _WMI_SendCompleteHandler)(HTC_ENDPOINT_ID Endpt, adf_nbuf_t pHTCBuf, void *arg);
90         int             (* _WMI_GetControlEp)(wmi_handle_t h);
91         void            (* _WMI_Shutdown)(wmi_handle_t h);
92     
93         /* */
94         void            (*_WMI_RecvMessageHandler)(HTC_ENDPOINT_ID EndPt, adf_nbuf_t hdr_buf, adf_nbuf_t pHTCBuf, void *arg);
95         A_UINT8         (*_WMI_ServiceConnect)(HTC_SERVICE *pService, HTC_ENDPOINT_ID eid, 
96                                                A_UINT8 *pDataIn, 
97                                                int LengthIn,
98                                                A_UINT8 *pDataOut,
99                                                int *pLengthOut);
100                                  
101         void            *pReserved;  /* for expansion if need be */
102 } WMI_SVC_APIS;
103
104 extern void WMI_service_module_install(WMI_SVC_APIS *pAPIs);
105
106 #endif /*WMI_SVC_API_H_*/