1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: nnet.h 4 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 $Rev: 14703 $ 11 *--------------------------------------------------------------------------- 12 13 14 */ 15 16 /* Please see man pages for details 17 18 */ 19 20 #ifndef NNET_H 21 #define NNET_H 22 23 #include <nn/net/compatible/nos.h> /* for NOS*** */ 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /*---------------------------------------------------------------------------* 30 * Definitions 31 *---------------------------------------------------------------------------*/ 32 33 #define NNET_ERROR_BASE 0xfff70000 34 #define NNET_ERROR_CODE(code) ((s32)(NNET_ERROR_BASE|(code))) 35 36 /* Please see man pages for details 37 38 */ 39 enum { 40 NNET_ERR_PARAM = NNET_ERROR_CODE(1), /* Please see man pages for details */ 41 NNET_ERR_EXIST = NNET_ERROR_CODE(2), /* Please see man pages for details */ 42 NNET_ERR_NOMEM = NNET_ERROR_CODE(3), /* Please see man pages for details */ 43 NNET_ERR_RECEIVE = NNET_ERROR_CODE(4), /* Please see man pages for details */ 44 NNET_ERR_SEND = NNET_ERROR_CODE(5), /* Please see man pages for details */ 45 NNET_ERR_RESOURCE = NNET_ERROR_CODE(6), /* Please see man pages for details */ 46 NNET_ERR_CANCEL = NNET_ERROR_CODE(7), /* Please see man pages for details */ 47 NNET_ERR_BUSY = NNET_ERROR_CODE(8), /* Please see man pages for details */ 48 NNET_ERR_STATE = NNET_ERROR_CODE(9), /* Please see man pages for details */ 49 NNET_ERR_NONE = 0 /* Please see man pages for details */ 50 }; 51 52 /*---------------------------------------------------------------------------* 53 * Types/Declarations 54 *---------------------------------------------------------------------------*/ 55 #define NNET_TMO_WAITFOREVER (-1L) /* Infinite wait */ 56 57 #define NNET_ETH_ALEN 6 /* MAC address length */ 58 #define NNET_IP_ALEN 4 /* IPv4 address length */ 59 60 #define NNET_MIN(a, b) (((a) < (b)) ? (a) : (b)) /* Please see man pages for details */ 61 #define NNET_MAX(a, b) (((a) > (b)) ? (a) : (b)) /* Please see man pages for details */ 62 63 64 /* Please see man pages for details 65 66 */ 67 typedef struct NNETAllocator { 68 void* (* alloc) (u32 name, u32 size, u32 align); /* Please see man pages for details */ 69 void (* free) (u32 name, void* ptr); /* Please see man pages for details */ 70 } NNETAllocator; 71 72 /* Please see man pages for details 73 74 */ 75 typedef struct NNETInstance { 76 struct NNETInstance *lower_ins; /* Please see man pages for details */ 77 s32 (* startup) (struct NNETInstance *ins, s32 timeout); /* Please see man pages for details */ 78 s32 (* cleanup) (struct NNETInstance *ins, s32 timeout); /* Please see man pages for details */ 79 s32 (* abort) (struct NNETInstance *ins); /* Please see man pages for details */ 80 } NNETInstance; 81 82 /* Please see man pages for details 83 84 */ 85 typedef struct NNETConfig { 86 u8 addr[NNET_IP_ALEN]; /* Please see man pages for details */ 87 u8 gateway[NNET_IP_ALEN]; /* Please see man pages for details */ 88 u8 dns1[NNET_IP_ALEN]; /* Please see man pages for details */ 89 u8 dns2[NNET_IP_ALEN]; /* Please see man pages for details */ 90 s32 mtu; /* Please see man pages for details */ 91 } NNETConfig; 92 93 94 #define NNET_L2TYPE_ETHERNET 1 /* Please see man pages for details */ 95 #define NNET_L2TYPE_PPP 2 /* Please see man pages for details */ 96 97 /* Please see man pages for details 98 99 */ 100 typedef struct NNETEthernetAPI { 101 NNETInstance *ins; 102 s32 (* eth_send) (NNETInstance *ins, u8 *dstMAC, NOSMessageBuf *mbuf); /* Please see man pages for details */ 103 s32 (* eth_receive) (NNETInstance *ins, u32 receive_id, NOSMessageBuf **mbuf); /* Please see man pages for details */ 104 s32 (* eth_setupper) (NNETInstance *ins, NNETInstance *upper_ins, u32 *receive_id, u16 list[]); /* Please see man pages for details */ 105 s32 (* eth_clearupper) (NNETInstance *ins, NNETInstance *upper_ins); /* Please see man pages for details */ 106 u8 eth_type; /* Please see man pages for details */ 107 s32 (* eth_getmacaddr) (NNETInstance *ins, u8 *mac); /* Please see man pages for details */ 108 s32 (* eth_setmulticast) (NNETInstance *ins, u8 *mac); /* Please see man pages for details */ 109 s32 (* eth_clearmulticast) (NNETInstance *ins, u8 *mac); /* Please see man pages for details */ 110 s32 (* eth_cancel_receive) (NNETInstance *ins, u32 receive_id); /* Please see man pages for details */ 111 s32 (* eth_getconfig) (NNETInstance *ins, NNETConfig *config); /* Please see man pages for details */ 112 } NNETEthernetAPI; 113 114 115 /* Please see man pages for details 116 117 */ 118 typedef struct NNETPPPAPI { 119 NNETInstance *ins; 120 s32 (* ppp_send) (NNETInstance *ins, NOSMessageBuf *mbuf); /* Please see man pages for details */ 121 s32 (* ppp_receive) (NNETInstance *ins, NOSMessageBuf **mbuf); /* Please see man pages for details */ 122 s32 (* ppp_setupper) (NNETInstance *ins, NNETInstance *upper_ins); /* Please see man pages for details */ 123 s32 (* ppp_clearupper) (NNETInstance *ins, NNETInstance *upper_ins); /* Please see man pages for details */ 124 s32 (* ppp_cancel_receive) (NNETInstance *ins); /* Please see man pages for details */ 125 } NNETPPPAPI; 126 127 /*---------------------------------------------------------------------------* 128 * Function Prototypes 129 *---------------------------------------------------------------------------*/ 130 extern NNETInstance *NNET_GetBottomIF(const NNETInstance *upper_ins); 131 extern NNETInstance *NNET_GetUpperIFByTop(const NNETInstance *top_ins, const NNETInstance *low_ins); 132 extern NNETInstance *NNET_GetLowerIF(NNETInstance *upper_ins); 133 extern s32 NNET_StartupIF(NNETInstance *ins, s32 timeout); 134 extern s32 NNET_CleanupIF(NNETInstance *ins, s32 timeout); 135 extern s32 NNET_AbortIF(NNETInstance *ins); 136 137 #ifdef NNET_BIG_ENDIAN 138 #define NNET_Swp2( _d ) d 139 #else 140 #define NNET_Swp2( _d ) ((u16)((((_d)>>8)&0x00FF)|(((_d)<<8)&0xFF00))) 141 #endif 142 extern u16 NNET_Get2( const void* ptr ); 143 extern u16 NNET_Set2( void* ptr, u16 dat ); 144 extern u16 NNET_And2( void* ptr, u16 dat ); 145 extern u16 NNET_Orr2( void* ptr, u16 dat ); 146 extern u16 NNET_Inc2( void* ptr ); 147 extern u16 NNET_Dec2( void* ptr ); 148 extern u16 NNET_Sub2( void* ptr, u16 dat ); 149 150 extern u32 NNET_Get4( const void* ptr ); 151 extern u32 NNET_Get4( const void* ptr ); 152 extern u32 NNET_Set4( void* ptr, u32 dat ); 153 extern u32 NNET_Inc4( void* ptr ); 154 extern u32 NNET_Add4( void* ptr, u32 dat ); 155 156 #include <nn/net/compatible/nnet/nnet_ring.h> 157 158 159 /* 160 Definitions for debugging 161 */ 162 #include <nn/net/compatible/ndebug.h> 163 164 #ifdef NDEBUG_ENABLE 165 166 #define NNET_DBGASSERT(cond) NDEBUG_Assert(cond) 167 168 #else /* NDEBUG_ENABLE */ 169 170 #define NNET_DBGASSERT(cond) 171 172 #endif /* NDEBUG_ENABLE */ 173 174 175 #ifdef NDEBUG_PRINT_ENABLE 176 177 extern u32 ndebug_mask_nnet; 178 179 #define NNET_DBGREPORT(level, log) \ 180 do { \ 181 if( level & ndebug_mask_nnet ) { \ 182 NDEBUG_Printf ("[NNET] "); \ 183 NDEBUG_Printf log; \ 184 NDEBUG_Printf ("\n"); \ 185 } \ 186 } while (0) 187 188 #define NNET_DBGFUNC(level, func) \ 189 do { \ 190 if( level & ndebug_mask_nnet ) { \ 191 func; \ 192 } \ 193 } while (0) 194 195 #else /* NDEBUG_PRINT_ENABLE */ 196 197 #define NNET_DBGREPORT(level, log) 198 #define NNET_DBGFUNC(level, func) 199 200 #endif /* NDEBUG_PRINT_ENABLE */ 201 202 203 #ifdef __cplusplus 204 } 205 #endif 206 207 /* NNET_H */ 208 #endif 209