source: umon/main/common/dhcp_01.c @ 87db514

Last change on this file since 87db514 was 87db514, checked in by Amar Takhar <amar@…>, on 04/16/15 at 19:26:21

Initial commit of the umon repository.

Prior to this three changes were made:

  • Remove umon_ prefix from parent directories.
  • Collapse main/target/ into main/
  • Remove ports/template/flashtest.scr.ucon script.
  • Property mode set to 100644
File size: 6.0 KB
Line 
1/**************************************************************************
2 *
3 * Copyright (c) 2013 Alcatel-Lucent
4 *
5 * Alcatel Lucent licenses this file to You under the Apache License,
6 * Version 2.0 (the "License"); you may not use this file except in
7 * compliance with the License.  A copy of the License is contained the
8 * file LICENSE at the top level of this repository.
9 * You may also obtain a copy of the License at:
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 **************************************************************************
20 *
21 * dhcp_01.c:
22 * This is the PPA-specific code used for Videotron Market trial.
23 * It was built from the dhcp_00.c DHCP-extension template file.
24 *
25 * Original author:     Ed Sutter (ed.sutter@alcatel-lucent.com)
26 *
27 */
28
29#include "config.h"
30#include "cpuio.h"
31#include "ether.h"
32#include "tfs.h"
33#include "tfsprivate.h"
34#include "genlib.h"
35#include "stddefs.h"
36
37/* Vendor specific option definitions: */
38#define VS_PROXYIP              1
39#define VS_PHONENUM             2
40#define VS_CODER                3
41#define VS_PPADHCPSRVR  4
42#define VS_MINNETDELAY  5
43#define VS_MAXNETDELAY  6
44#define VS_APPINFO              7
45#define VS_CODERCTL             8
46#define VS_NAMEVAL              99
47
48#define PPADHCPSRVR_STR "PPADHCPSRVR"
49
50/* ValidDHCPOffer():
51 *      Target issued the DISCOVER, the incoming packet is the server's
52 *      OFFER reply.  If the offer contains the vendor specific
53 *      VS_PPADHCPSRVR option and the string within that
54 *      option is correct, then accept the offer; by issuing a request.
55 */
56ValidDHCPOffer(struct   dhcphdr *dhdr)
57{
58        uchar   *op, *op1;
59
60        op = op1 = 0;
61        op1 = DhcpGetOption(DHCPOPT_VENDORSPECIFICINFO,dhdr+1);
62        if (op1) {
63                op = DhcpGetOption(VS_PPADHCPSRVR,op1+2);
64        }
65        if (op) {
66                if (!strncmp(op+2,PPADHCPSRVR_STR,sizeof(PPADHCPSRVR_STR)-1)) {
67                        return(1);
68                }
69        }
70        return(0);
71}
72
73/* buildDhcpHdr():
74 *      Called by dhcpboot.c to allow application-specific header stuff to
75 *      be added to header.  Return 0 if generic stuff in dhcpboot.c is to be
76 *      used; else return 1 and the calling code will assume this function is
77 *      dealing with it (see dhcpboot.c for basic idea).
78 */
79int
80buildDhcpHdr(struct dhcphdr *dhcpdata)
81{
82        return(0);
83}
84
85/* DhcpBootpDone():
86 *      Called at the end of the Bootp or Dhcp transaction.
87 *      Input...
88 *      bootp:  1 if BOOTP; else DHCP.
89 *      dhdr:   pointer to dhcp or bootp header.
90 *      vsize:  size of vendor specific area (for bootp this is fixed at 64,
91 *                      but for dhcp it is variable).
92 */
93void
94DhcpBootpDone(int bootp, struct dhcphdr *dhdr, int vsize)
95{
96        return;
97}
98
99void
100SetPPAOption(type,op1,varname)
101int             type;
102uchar   *op1;
103char    *varname;
104{
105        uchar   *op, tmp;
106
107        op = DhcpGetOption(type,op1+2);
108        if (op) {
109                tmp = op[*(op+1)+2];
110                op[*(op+1)+2] = 0;
111                DhcpSetEnv(varname,op+2);
112                op[*(op+1)+2] = tmp;
113        }
114}
115
116/* DhcpVendorSpecific():
117 *      Process vendor specific stuff within the incoming dhcp header.
118 */
119DhcpVendorSpecific(struct       dhcphdr *dhdr)
120{
121        ulong   ip;
122        uchar   *op, *op1, buf[16], tmp;
123
124        op = op1 = 0;
125        op1 = DhcpGetOption(DHCPOPT_VENDORSPECIFICINFO,dhdr+1);
126        if (op1) {
127                /* Get PROXY_IP and BPROXY_IP (optionally): */
128                op = DhcpGetOption(VS_PROXYIP,op1+2);
129                if (op) {
130                        memcpy(&ip,op+2,4);
131                        DhcpSetEnv("PROXY_IP",IpToString(ip,buf));
132                        if (*(op+1) == 8) {
133                                memcpy(&ip,op+6,4);
134                                DhcpSetEnv("BPROXY_IP",IpToString(ip,buf));
135                        }
136                }
137
138                /* Get PPA phone numbers (1 or 2). */
139                op = DhcpGetOption(VS_PHONENUM,op1+2);
140                if (op) {
141                        char *space;
142                        tmp = op[*(op+1)+2];
143                        op[*(op+1)+2] = 0;
144                        space = strchr(op+2,' ');
145                        if (space) {
146                                *space = 0;
147                                DhcpSetEnv("LINE0_NUMBER",op+2);
148                                DhcpSetEnv("LINE1_NUMBER",space+1);
149                                *space = ' ';
150                        }
151                        else
152                                DhcpSetEnv("LINE0_NUMBER",op+2);
153                        op[*(op+1)+2] = tmp;
154                }
155
156                /* Set Coder type: */
157                SetPPAOption(VS_CODER,op1,"CODER");
158
159                /* Set Coder control: */
160                SetPPAOption(VS_CODERCTL,op1,"CODERCTL");
161
162                /* Set minimum network delay setting: */
163                SetPPAOption(VS_MINNETDELAY,op1,"MIN_NET_DELAY");
164
165                /* Set maximum network delay setting: */
166                SetPPAOption(VS_MAXNETDELAY,op1,"MAX_NET_DELAY");
167
168                /* Set appinfo: */
169                SetPPAOption(VS_APPINFO,op1,"APPINFO");
170        }
171
172        /* Check for VS_NAMEVAL here...
173         * If the Vendor-Specific-Information is present, and within that
174         * information there is a sub-option of VS_NAMEVAL,
175         * then consider the content of that sub-option to be one or more
176         * strings (separated by a comma) of the format "VARNAME=VALUE".
177         * This is used to allow the DHCP server to configure shell variables
178         * into the environment prior to the monitor turning over control to
179         * the application.
180         * Two examples of VS_NAMEVAL strings:
181         * First, just one name-value combination...
182         *      VARNAME=VALUE
183         * Second, a multiple name-value combination...
184         *      VARNAME=VALUE,VAR1=ABC,IP=1.2.3.4
185         */
186
187        op = op1 = 0;
188        op1 = DhcpGetOption(DHCPOPT_VENDORSPECIFICINFO,dhdr+1);
189        if (op1)
190                op = DhcpGetOption(VS_NAMEVAL,op1+2);
191        if (op) {
192                int             len;
193                uchar   *end, tmp;
194                uchar   *name, *value, *eqsign, *comma, *base;
195
196                op++;
197                len =  (int)*op++;
198                base = op;
199                tmp = base[len];
200                base[len] = 0;
201                end = base + len;
202                while (op < end) {
203                        eqsign = (uchar *)strchr(op,'=');
204                        if (!eqsign)
205                                break;
206                        name = op;
207                        *eqsign = 0;
208                        value = eqsign+1;
209                        comma = (uchar *)strchr(value,',');
210                        if (comma) {
211                                *comma = 0;
212                                op = comma+1;
213                        }
214                        else
215                                op = end;
216                        DhcpSetEnv(name,value);
217                        *eqsign = '=';
218                        *comma = ',';
219                }
220                base[len] = tmp;
221        }
222}
223
224int
225printDhcpVSopt(int vsopt, int vsoptlen, char *options)
226{
227        switch(vsopt) {
228        case VS_PROXYIP:
229                for(i=0;i<vsoptlen;i++)
230                        printf("%d ",(unsigned int)*options++);
231                break;
232        case VS_CODER:
233        case VS_NAMEVAL:
234        case VS_MINNETDELAY:
235        case VS_MAXNETDELAY:
236        case VS_PPADHCPSRVR:
237        case VS_PHONENUM:
238        case VS_APPINFO:
239                for(i=0;i<vsoptlen;i++)
240                        printf("%c",*options++);
241                break;
242        default:
243                return(0);
244        }
245        return(1);
246}
Note: See TracBrowser for help on using the repository browser.