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