1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: peth.h
4
5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 12449 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NN_NETWORK_PETH_H
17 #define NN_NETWORK_PETH_H
18
19 #include <nnet.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /*---------------------------------------------------------------------------*
26 * Definitions
27 *---------------------------------------------------------------------------*/
28 #define PETH_DEVICE_1 0 /* このドライバで扱えるI/Fは1つだけ */
29
30 #define PETH_VENDOR_NINTENDO 0x0000
31 #define PETH_COMMON_CONF_VERSION 0x1100
32 #define PETH_INS_CONF_VERSION 0x2100
33
34 /**
35 * エラーコード
36 */
37 #define PETH_ERROR_BASE 0xffff9000
38 #define PETH_ERROR_CODE(code) ((s32)(PETH_ERROR_BASE|(code)))
39 enum {
40 PETH_ERR_PARAM = PETH_ERROR_CODE(1), /* パラメータエラー */
41 PETH_ERR_INIT = PETH_ERROR_CODE(2), /* 初期状態のため実行不可 */
42 PETH_ERR_FINISH = PETH_ERROR_CODE(3), /* 終了状態のため実行不可 */
43 PETH_ERR_CONFVER = PETH_ERROR_CODE(4), /* 設定のバージョンエラー */
44 PETH_ERR_STATE = PETH_ERROR_CODE(5), /* ステートエラー */
45 PETH_ERR_EXIST = PETH_ERROR_CODE(6), /* 既に作成済み */
46 PETH_ERR_NOMEM = PETH_ERROR_CODE(7), /* メモリ不足 */
47 PETH_ERR_TIMEOUT = PETH_ERROR_CODE(8), /* タイムアウト */
48 PETH_ERR_NONE = 0 /* 正常終了 */
49 };
50
51 /**
52 * メモリ
53 */
54 #define PETH_MEM_BASE 0x00050000
55 #define PETH_MEM_NAME(name) ((s32)(PETH_MEM_BASE|(name)))
56 enum {
57 PETH_MEM_INSTANCE = PETH_MEM_NAME(1)
58 };
59
60 /**
61 * ステート
62 */
63 enum {
64 PETH_STATE_INIT = 0, /* 初期状態 */
65 PETH_STATE_ACTIVE, /* 接続完了状態 */
66 PETH_STATE_ABORT /* 接続完了状態 */
67 };
68
69 /*---------------------------------------------------------------------------*
70 * Types/Declarations
71 *---------------------------------------------------------------------------*/
72 #define PETH_MAC_LEN 6
73
74 /**
75 * 無線ドライバが保持するプロトコル情報
76 */
77 typedef struct PETHProtocolList {
78 u16 protocol; /* IP、ARPなど */
79 NNETInstance *upper_ins; /* 上位インスタンス */
80 NOSMessageQueueId mq_receive; /* 上記プロトコルを受信したときにパケットを入れるキュー */
81 } PETHProtocolList;
82
83 /**
84 * インスタンス
85 */
86 #define PETH_PROTOCOL_NUM 8 /* ARP, RARP, IP, PPPoE Discovery, PPPoE Session */
87 #define PETH_UPPER_NUM 2 /* 上位のレイヤ数 */
88 #define PETH_MQ_NUM 16 /* 上位へ渡すキューのサイズ */
89 #define PETH_MAX_SEND_LEN 1600
90 typedef struct PETHMessage {
91 NOSMessageQueue mq; /* 上位用の受信キュー */
92 NOSMessage mqarray[PETH_MQ_NUM]; /* 上位用の受信キュー実体 */
93 } PETHMessage;
94
95 typedef struct PETHInstance {
96 NNETInstance ins; /* 全レイヤ共通に持っているインスタンス情報 */
97
98 PETHProtocolList upper_protocol[PETH_PROTOCOL_NUM]; /* 上位のプロトコルと送信するメッセージキュー */
99 s32 upper_protocol_count;
100
101 PETHMessage upper_mq[PETH_UPPER_NUM]; /* 上位用の受信キュー */
102
103 s32 upper_ins_count;
104
105 s32 state;
106
107 u8 macaddr[PETH_MAC_LEN]; /* 自MACアドレス */
108 u16 pad;
109 u8 sendBuf[PETH_MAX_SEND_LEN]; /* 送信バッファ */
110
111 } PETHInstance;
112
113 /*
114 WCMのインスタンスからNNETInstanceを取得する
115 */
PETH_GetNNETInstance(PETHInstance * peth_ins)116 static inline NNETInstance *PETH_GetNNETInstance(PETHInstance *peth_ins)
117 {
118 return &peth_ins->ins;
119 }
120
121 /*
122 NNETInstanceからWCMのインスタンスを取得する
123 */
PETH_GetPETHInstance(NNETInstance * ins)124 static inline PETHInstance *PETH_GetPETHInstance(NNETInstance *ins)
125 {
126 return (PETHInstance *)ins;
127 }
128
129 /*---------------------------------------------------------------------------*
130 * Function Prototypes
131 *---------------------------------------------------------------------------*/
132 /* PETH_main.c */
133 extern s32 PETH_Init(const NNETAllocator *allocator);
134 extern s32 PETH_Finish(void);
135 extern s32 PETH_StartupIns(NNETInstance *ins, s32 timeout);
136 extern s32 PETH_CleanupIns(NNETInstance *ins, s32 timeout);
137 extern s32 PETH_AbortIns(NNETInstance *ins);
138 extern s32 PETH_CreateIns(PETHInstance **peth_ins);
139 extern s32 PETH_DestroyIns(PETHInstance *peth_ins);
140 extern s32 PETH_GetStateIns(PETHInstance *peth_ins);
141 extern s32 PETH_GetUpperAPI(NNETEthernetAPI *wcm_api, PETHInstance *peth_ins);
142 extern s32 PETH_SetUpper(NNETInstance *ins, NNETInstance *upper_ins, u32 *receive_id, u16 entry[]);
143 extern s32 PETH_ClearUpper(NNETInstance *ins, NNETInstance *upper_ins);
144 extern s32 PETH_GetMacAddr(NNETInstance *ins, u8 *macaddr);
145 extern s32 PETH_SetMulticastAddr(NNETInstance *ins, u8 *macaddr);
146 extern s32 PETH_ClearMulticastAddr(NNETInstance *ins, u8 *macaddr);
147 extern s32 PETH_Send(NNETInstance *ins, u8 *dstMAC, NOSMessageBuf *mbuf);
148 extern s32 PETH_Receive(NNETInstance *ins, u32 receive_id, NOSMessageBuf **mbuf);
149 extern s32 PETH_CancelReceive(NNETInstance *ins, u32 receive_id);
150
151
152 #ifdef __cplusplus
153 }
154 #endif
155
156 /* NN_NETWORK_PETH_H */
157 #endif
158