1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/* -ed- ============= */
#include <stdio.h>
#if 0
#define HI_TECH_C
#endif
#define SCN 0x01
#define SCA 0x02
typedef enum
{
FALSE,
TRUE
}
BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef union
{
unsigned long lw;
BYTE b[4];
}
LWORD;
enum
{
IPCP_OPT_ADDR
};
enum
{
EVENT_RCR_ERR,
EVENT_RCR_OK,
EVENT_RCN,
EVENT_dummy
};
static enum
{
PPP_CFG_REQ,
PPP_ECHO_REQ,
PPP_OPENED,
PPP_ECHO_REP,
PPP_IPCP,
PPP_CFG_NAK,
PPP_CFG_ACK,
PPP_dummy
}
ppp_code;
static BYTE lcp_state;
static BYTE net_rxin;
static BYTE rxout;
static BYTE ppp_rxid;
static BYTE ppp_pcol;
static LWORD hostip;
static LWORD myip;
static BOOL ipcp_action;
static BYTE get_byte (BYTE * p)
{
return *p;
}
static void put_byte (int val)
{
putchar (val);
}
static void copy_rx_tx (int val) // Echo the data
{
putchar (val);
}
static void send_ppp (BYTE ppp, int id, int a)
{
printf ("send_ppp (%d, %d, %d)\n", ppp, id, a);
}
static void ipcp_event_handler (BYTE a)
{
printf ("ipcp_event_handler(%d)\n", a);
}
BOOL match_byte (BYTE a)
{
return a == 0xFF;
}
/* ================== */
/* Get an incoming lword value, return 0 if end of message */
/////////////////////////////////
//Fonction avec problemes///
////////////////////////////////
// j'es mi plein de ////////////// lorsque ces fonctions sont appelées
BOOL get_lword (LWORD * lwp)
{
#ifdef HI_TECH_C
BYTE n = 4, b;
while (n && get_byte (&b))
lwp->b[--n] = b;
return (n == 0);
#else
if (get_byte (&lwp->b[3]) && get_byte (&lwp->b[2]) &&
get_byte (&lwp->b[1]) && get_byte (&lwp->b[0]))
return (1);
return (0);
#endif
}
/* Put a longword in the network buffer, then add to checksum */
void put_lword (LWORD * lwp)
{
put_byte (lwp->b[3]);
put_byte (lwp->b[2]);
put_byte (lwp->b[1]);
put_byte (lwp->b[0]);
}
/* --------------------------------------------------------------------- */
/////////////////////////
//fonction principales//
/////////////////////////
/* Rx handler for Link Control Protocol */
void lcp_rx_handler (void)
{
LWORD lw;
if (ppp_code == PPP_CFG_REQ) // LCP Config request?
{ // Check option list
}
else if (ppp_code == PPP_ECHO_REQ) // LCP echo request?
{
if ((lcp_state & 0xf) == PPP_OPENED && get_lword (&lw)) /////////////////////////////
{ // Get magic num
lw.lw++; // Return magic num + 1
put_lword (&lw); ///////////////////////////////////////////////////////////
copy_rx_tx (net_rxin - rxout); // Echo the data
send_ppp (PPP_ECHO_REP, ppp_rxid, 1);
} // Others to state machine..
}
}
/* Rx handler for Internet Protocol Control Protocol */
void ipcp_rx_handler (void)
{
BYTE opt, optlen;
BYTE rejects = 0;
ppp_pcol = PPP_IPCP;
if (ppp_code == PPP_CFG_REQ) // IPCP config request?
{ // Check option list
while (get_byte (&opt) && get_byte (&optlen) && optlen >= 2)
{
if (opt == IPCP_OPT_ADDR && optlen == 6) // IP address option?
get_lword (&hostip); // (will be accepted) /////////////////////////////////
else
{
}
}
if (rejects) // If any rejected options..
{
}
else if (!hostip.lw) // If null IP address
{
hostip.lw = myip.lw + 1; // ..give host my IP addr + 1
ipcp_event_handler (EVENT_RCR_ERR); // (for want of anthing else)
if (ipcp_action & SCN)
{ // If OK to NAK, do so
put_byte (IPCP_OPT_ADDR);
put_byte (6);
put_lword (&hostip); // ..with new address as hint ///////////////////////////////////////////
send_ppp (PPP_CFG_NAK, ppp_rxid, 1);
}
}
else // If options OK..
{
ipcp_event_handler (EVENT_RCR_OK);
if (ipcp_action & SCA) // ..and OK to send, do so
{
put_byte (IPCP_OPT_ADDR);
put_byte (6);
put_lword (&hostip); ////////////////////////////////////////////////
send_ppp (PPP_CFG_ACK, ppp_rxid, 1);
}
}
}
else if (ppp_code == PPP_CFG_NAK) // If NAK received..
{ // ..and IP address hint..
if (match_byte (IPCP_OPT_ADDR) && match_byte (6))
get_lword (&myip); // ..use it for my address /////////////////////
ipcp_event_handler (EVENT_RCN);
}
} |
Partager