1 /* 2 * Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net> 3 * Distributed under the terms of the MIT License. 4 */ 5 6 /*! \class KPPPOptionHandler 7 \brief Handler for LCP configure packets. 8 9 This class can be used to extend the supported LCP configure packets. 10 */ 11 12 #include <KPPPOptionHandler.h> 13 14 #include <PPPControl.h> 15 16 17 /*! \brief Constructor. 18 19 If an error occurs in the constructor you should set \c fInitStatus. 20 21 \param name Name of the handler. 22 \param type Request type you can handle. 23 \param interface Owning interface. 24 \param settings Settings for this handler. 25 */ 26 KPPPOptionHandler::KPPPOptionHandler(const char *name, uint8 type, 27 KPPPInterface& interface, driver_parameter *settings) 28 : fInitStatus(B_OK), 29 fType(type), 30 fInterface(interface), 31 fSettings(settings), 32 fEnabled(true) 33 { 34 if(name) 35 fName = strdup(name); 36 else 37 fName = NULL; 38 } 39 40 41 //! Destructor. Frees the name and unregisters handler from LCP protocol. 42 KPPPOptionHandler::~KPPPOptionHandler() 43 { 44 Interface().LCP().RemoveOptionHandler(this); 45 46 free(fName); 47 } 48 49 50 //! Returns \c fInitStatus. May be overridden to return status-dependend errors. 51 status_t 52 KPPPOptionHandler::InitCheck() const 53 { 54 return fInitStatus; 55 } 56 57 58 //! Allows controlling this handler from userlevel. 59 status_t 60 KPPPOptionHandler::Control(uint32 op, void *data, size_t length) 61 { 62 switch(op) { 63 case PPPC_GET_SIMPLE_HANDLER_INFO: { 64 if(length < sizeof(ppp_simple_handler_info_t) || !data) 65 return B_ERROR; 66 67 ppp_simple_handler_info *info = (ppp_simple_handler_info*) data; 68 memset(info, 0, sizeof(ppp_simple_handler_info_t)); 69 if(Name()) 70 strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); 71 info->isEnabled = IsEnabled(); 72 } break; 73 74 case PPPC_ENABLE: 75 if(length < sizeof(uint32) || !data) 76 return B_ERROR; 77 78 SetEnabled(*((uint32*)data)); 79 break; 80 81 default: 82 return B_BAD_VALUE; 83 } 84 85 return B_OK; 86 } 87 88 89 //! Stack ioctl handler. 90 status_t 91 KPPPOptionHandler::StackControl(uint32 op, void *data) 92 { 93 switch(op) { 94 default: 95 return B_BAD_VALUE; 96 } 97 98 return B_OK; 99 } 100 101 102 /*! \brief Add request item. 103 104 What you do here depends on the connection side (client or server). \n 105 Received nak and reject packets influence which value gets added to the 106 request, too. 107 */ 108 status_t 109 KPPPOptionHandler::AddToRequest(KPPPConfigurePacket& request) 110 { 111 return B_OK; 112 } 113 114 115 /*! \brief Parse a nak received from the peer. 116 117 This method is called only once for each option handler. You must find the item 118 yourself (no index is given). 119 */ 120 status_t 121 KPPPOptionHandler::ParseNak(const KPPPConfigurePacket& nak) 122 { 123 return B_OK; 124 } 125 126 127 /*! \brief Parse a reject received from the peer. 128 129 This method is called only once for each option handler. You must find the item 130 yourself (no index is given). 131 */ 132 status_t 133 KPPPOptionHandler::ParseReject(const KPPPConfigurePacket& reject) 134 { 135 return B_OK; 136 } 137 138 139 /*! \brief Parse an ack received from the peer. 140 141 This method is called only once for each option handler. You must find the item 142 yourself (no index is given). 143 */ 144 status_t 145 KPPPOptionHandler::ParseAck(const KPPPConfigurePacket& ack) 146 { 147 return B_OK; 148 } 149 150 151 /*! \brief Handler for configure requests sent by peer. 152 153 Index may be behind the last item which means additional values can be 154 appended. 155 156 \param request The requested values. 157 \param index Index of item in \a request. 158 \param nak Values for the nak should be added here. 159 \param reject Values for the reject should be added here. 160 */ 161 status_t 162 KPPPOptionHandler::ParseRequest(const KPPPConfigurePacket& request, 163 int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) 164 { 165 return B_OK; 166 } 167 168 169 //! Notification that we ack the values in \a ack. 170 status_t 171 KPPPOptionHandler::SendingAck(const KPPPConfigurePacket& ack) 172 { 173 return B_OK; 174 } 175 176 177 //! Reset internal state (e.g.: remove list of rejected values). 178 void 179 KPPPOptionHandler::Reset() 180 { 181 // do nothing by default 182 } 183