/* * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * * This document is the property of Apple Computer, Inc. * It is considered confidential and proprietary. * * This document may not be reproduced or transmitted in any form, * in whole or in part, without the express written permission of * Apple Computer, Inc. */ //a very minimal Ethernet stack. //protocol handlers can register for a certain service, and this layer will call their functions when a packet of that type arrive #include #include #include #include #include #include #include //For the different layers #include #include #include #include static callbacks_t ethercb; int registerEtherTypeHandler(int ethertype,callback_handler cb) { return registerCallback(ðercb,ethertype,cb); } int unregisterEtherTypeHandler(int id) { return unregisterCallback(ðercb,id); } static int parseEtherHeader(char *buff,int len,uint16_t *ethertype) { //XXX: Check that the destination macaddress matches. if(ethertype) { *ethertype = ntohs(*(uint16_t *)(buff+12)); } return 0; } void ethernet_init(void) { } void ethernet_uninit(void) { } void ethernet_input(mymbuf_t *inputbuf) { uint16_t ethertype; int len; char *rawbuf; callback_handler cb; len = mbuf_getlength(inputbuf); rawbuf = mbuf_getlinear(inputbuf); //This fails if the packet was not directed to us (ie, wrong macaddr) if(parseEtherHeader(rawbuf,len,ðertype) == 0) { cb = find_callback(ðercb,ethertype); if(cb) { cb(rawbuf,ETHERNET_OFFSET,len,0); } else { // printf("Unsupported ethertype 0x%x\n",ethertype); } } } #if 0 //Called from timer (background) or from tsys commandprompt if not background //Handles maxpkt packages before returning. (Or until it would have to block) void ethernet_workloop(struct callout *c, void *param) { int i; uint16_t ethertype; int len; char *rawbuf; callback_handler cb; int maxpkt = (int)param; // utime_t now; // callout_reset(c, 0); if(!buf) return; for(i = 0;i