13#include "rpc_client.h"
14#include "rpc_server.h"
18static struct NetManNetIF NetIFs[NETMAN_MAX_NETIF_COUNT];
20static unsigned char IsInitialized=0;
21static char NIFLinkState=0;
22static unsigned char NextNetIFID=0;
23static int NetManIOSemaID;
25IRX_ID(
"Network_Manager", 2, 1);
29int _start(
int argc,
char *argv[]){
35 if(RegisterLibraryEntries(&_exp_netman) == 0){
40 NetManIOSemaID = CreateSema(&sema);
42 NetmanInitRPCServer();
44 return MODULE_RESIDENT_END;
47 return MODULE_NO_RESIDENT_END;
50void *malloc(
int size){
55 result = AllocSysMemory(ALLOC_FIRST, size, NULL);
61void free(
void *buffer){
65 FreeSysMemory(buffer);
69void NetManToggleGlobalNetIFLinkState(
unsigned char state){
72 NetManUpdateStackNIFLinkState();
75int NetManGetGlobalNetIFLinkState(
void){
79void NetManUpdateStackNIFLinkState(
void){
82 MainNetProtStack.LinkStateUp();
85 MainNetProtStack.LinkStateDown();
90static void UpdateNetIFStatus(
void){
93 if(MainNetIF == NULL){
96 for(i=0; i<NETMAN_MAX_NETIF_COUNT; i++){
104 NetManToggleGlobalNetIFLinkState((MainNetIF!=NULL && (MainNetIF->flags&
NETMAN_NETIF_LINK_UP)) ? 1 : 0);
108 WaitSema(NetManIOSemaID);
111 memcpy(&MainNetProtStack, stack,
sizeof(MainNetProtStack));
114 NetManUpdateStackNIFLinkState();
117 SignalSema(NetManIOSemaID);
122void NetManUnregisterNetworkStack(
void){
125 WaitSema(NetManIOSemaID);
127 for(i=0; i<NETMAN_MAX_NETIF_COUNT; i++){
135 memset(&MainNetProtStack, 0,
sizeof(MainNetProtStack));
138 SignalSema(NetManIOSemaID);
141void NetManNetIFXmit(
void){
142 if(MainNetIF != NULL)
146int NetManIoctl(
unsigned int command,
void *args,
unsigned int args_len,
void *output,
unsigned int length){
149 WaitSema(NetManIOSemaID);
152 result=MainNetIF->ioctl(command, args, args_len, output, length);
156 SignalSema(NetManIOSemaID);
161int NetManNetIFSetLinkMode(
int mode){
165void *NetManNetProtStackAllocRxPacket(
unsigned int length,
void **payload){
166 return IsInitialized?MainNetProtStack.AllocRxPacket(length, payload):NULL;
169void NetManNetProtStackFreeRxPacket(
void *packet){
171 MainNetProtStack.FreeRxPacket(packet);
174void NetManNetProtStackEnQRxPacket(
void *packet){
176 MainNetProtStack.EnQRxPacket(packet);
179int NetManTxPacketNext(
void **payload){
180 return IsInitialized?MainNetProtStack.NextTxPacket(payload):0;
183void NetManTxPacketDeQ(
void){
185 MainNetProtStack.DeQTxPacket();
193 WaitSema(NetManIOSemaID);
195 for(i=0, result=-
ENOMEM; i<NETMAN_MAX_NETIF_COUNT; i++){
197 if(
NetIF->init()==0){
199 EventFlag.option = 0;
201 if((result =
NetIF->EventFlagID = CreateEventFlag(&EventFlag)) >= 0){
202 memcpy(&NetIFs[i],
NetIF,
sizeof(NetIFs[i]));
204 result=NetIFs[i].
id=((
unsigned int)NextNetIFID)<<8|i;
215 SignalSema(NetManIOSemaID);
220void NetManUnregisterNetIF(
const char *name){
223 WaitSema(NetManIOSemaID);
225 for(i=0; i<NETMAN_MAX_NETIF_COUNT; i++){
229 DeleteEventFlag(NetIFs[i].EventFlagID);
235 SignalSema(NetManIOSemaID);
238void NetManToggleNetIFLinkState(
int NetIFID,
unsigned char state){
239 WaitSema(NetManIOSemaID);
241 if((NetIFID&0xFF)<NETMAN_MAX_NETIF_COUNT && NetIFID==NetIFs[NetIFID&0xFF].
id && (NetIFs[NetIFID&0xFF].flags&
NETMAN_NETIF_IN_USE)){
244 pNetIF = &NetIFs[NetIFID&0xFF];
246 ClearEventFlag(pNetIF->EventFlagID, ~(NETMAN_NETIF_EVF_UP|NETMAN_NETIF_EVF_DOWN));
250 SetEventFlag(pNetIF->EventFlagID, NETMAN_NETIF_EVF_UP);
253 pNetIF->flags&=~NETMAN_NETIF_LINK_UP;
254 SetEventFlag(pNetIF->EventFlagID, NETMAN_NETIF_EVF_DOWN);
260 SignalSema(NetManIOSemaID);
263int NetManSetMainIF(
const char *name){
266 WaitSema(NetManIOSemaID);
268 for(i=0,result=-
ENXIO; i<NETMAN_MAX_NETIF_COUNT; i++){
270 MainNetIF=&NetIFs[i];
276 SignalSema(NetManIOSemaID);
281int NetManQueryMainIF(
char *name){
284 WaitSema(NetManIOSemaID);
287 strcpy(name, MainNetIF->name);
289 }
else result = -
ENXIO;
291 SignalSema(NetManIOSemaID);
296int NetManSetLinkMode(
int mode){
299 WaitSema(NetManIOSemaID);
302 evfid = MainNetIF->EventFlagID;
304 ClearEventFlag(evfid, ~NETMAN_NETIF_EVF_DOWN);
312 SignalSema(NetManIOSemaID);
314 if(result == 0 && evfid >= 0)
315 WaitEventFlag(evfid, NETMAN_NETIF_EVF_DOWN, WEF_OR, NULL);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
@ NETMAN_NETIF_IOCTL_ETH_SET_LINK_MODE
#define NETMAN_NETIF_LINK_UP
#define NETMAN_NETIF_IN_USE