xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp (revision 01b25646004ff628ecad0281a9795e5e90f71746)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //---------------------------------------------------------------------
7 
8 #include <KPPPLayer.h>
9 
10 #include <cstdlib>
11 #include <cstring>
12 #include <core_funcs.h>
13 
14 #ifdef _KERNEL_MODE
15 	#include <kernel_cpp.h>
16 #endif
17 
18 
19 PPPLayer::PPPLayer(const char *name, ppp_level level, uint32 overhead)
20 	: fInitStatus(B_OK),
21 	fOverhead(overhead),
22 	fLevel(level),
23 	fNext(NULL)
24 {
25 	if(name)
26 		fName = strdup(name);
27 	else
28 		fName = strdup("Unknown");
29 }
30 
31 
32 PPPLayer::~PPPLayer()
33 {
34 	free(fName);
35 }
36 
37 
38 status_t
39 PPPLayer::InitCheck() const
40 {
41 	return fInitStatus;
42 }
43 
44 
45 status_t
46 PPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
47 {
48 	if(!packet)
49 		return B_ERROR;
50 
51 	// Find the next possible handler for this packet.
52 	// Normal protocols (Level() >= PPP_PROTOCOL_LEVEL) do not encapsulate anything.
53 	if(Next()) {
54 		if(Next()->IsAllowedToSend() && Next()->Level() < PPP_PROTOCOL_LEVEL)
55 			return Next()->Send(packet, protocolNumber);
56 		else
57 			return Next()->SendToNext(packet, protocolNumber);
58 	} else {
59 		m_freem(packet);
60 		return B_ERROR;
61 	}
62 }
63 
64 
65 void
66 PPPLayer::Pulse()
67 {
68 	// do nothing by default
69 }
70