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 switch (op) { 64 case PPPC_GET_SIMPLE_HANDLER_INFO: 65 { 66 if (length < sizeof(ppp_simple_handler_info_t) || !data) 67 return B_ERROR; 68 69 ppp_simple_handler_info *info = (ppp_simple_handler_info*) data; 70 memset(info, 0, sizeof(ppp_simple_handler_info_t)); 71 if (Name()) 72 strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); 73 info->isEnabled = IsEnabled(); 74 break; 75 } 76 77 case PPPC_ENABLE: 78 if (length < sizeof(uint32) || !data) 79 return B_ERROR; 80 81 SetEnabled(*((uint32*)data)); 82 break; 83 84 default: 85 return B_BAD_VALUE; 86 } 87 88 return B_OK; 89 } 90 91 92 //! Stack ioctl handler. 93 status_t 94 KPPPOptionHandler::StackControl(uint32 op, void *data) 95 { 96 switch (op) { 97 default: 98 return B_BAD_VALUE; 99 } 100 101 return B_OK; 102 } 103 104 105 /*! \brief Add request item. 106 107 What you do here depends on the connection side (client or server). \n 108 Received nak and reject packets influence which value gets added to the 109 request, too. 110 */ 111 status_t 112 KPPPOptionHandler::AddToRequest(KPPPConfigurePacket& request) 113 { 114 return B_OK; 115 } 116 117 118 /*! \brief Parse a nak received from the peer. 119 120 This method is called only once for each option handler. You must find the item 121 yourself (no index is given). 122 */ 123 status_t 124 KPPPOptionHandler::ParseNak(const KPPPConfigurePacket& nak) 125 { 126 return B_OK; 127 } 128 129 130 /*! \brief Parse a reject received from the peer. 131 132 This method is called only once for each option handler. You must find the item 133 yourself (no index is given). 134 */ 135 status_t 136 KPPPOptionHandler::ParseReject(const KPPPConfigurePacket& reject) 137 { 138 return B_OK; 139 } 140 141 142 /*! \brief Parse an ack received from the peer. 143 144 This method is called only once for each option handler. You must find the item 145 yourself (no index is given). 146 */ 147 status_t 148 KPPPOptionHandler::ParseAck(const KPPPConfigurePacket& ack) 149 { 150 return B_OK; 151 } 152 153 154 /*! \brief Handler for configure requests sent by peer. 155 156 Index may be behind the last item which means additional values can be 157 appended. 158 159 \param request The requested values. 160 \param index Index of item in \a request. 161 \param nak Values for the nak should be added here. 162 \param reject Values for the reject should be added here. 163 */ 164 status_t 165 KPPPOptionHandler::ParseRequest(const KPPPConfigurePacket& request, 166 int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) 167 { 168 return B_OK; 169 } 170 171 172 //! Notification that we ack the values in \a ack. 173 status_t 174 KPPPOptionHandler::SendingAck(const KPPPConfigurePacket& ack) 175 { 176 return B_OK; 177 } 178 179 180 //! Reset internal state (e.g.: remove list of rejected values). 181 void 182 KPPPOptionHandler::Reset() 183 { 184 // do nothing by default 185 } 186