1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1996 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate #include <sys/types.h>
29*0Sstevel@tonic-gate #include <netinet/in.h>
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #include "impl.h"
32*0Sstevel@tonic-gate #include "asn1.h"
33*0Sstevel@tonic-gate #include "error.h"
34*0Sstevel@tonic-gate #include "snmp.h"
35*0Sstevel@tonic-gate #include "trap.h"
36*0Sstevel@tonic-gate #include "pdu.h"
37*0Sstevel@tonic-gate #include "node.h"
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #include "snmpdx_stub.h"
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /***** regTreeEntry         ********************************/
44*0Sstevel@tonic-gate 
get_regTreeEntry(int search_type,RegTreeEntry_t ** regTreeEntry_data,IndexType * index)45*0Sstevel@tonic-gate extern int get_regTreeEntry(int search_type, RegTreeEntry_t **regTreeEntry_data, IndexType *index)
46*0Sstevel@tonic-gate {
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate 	int res;
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate 	*regTreeEntry_data = (RegTreeEntry_t*)calloc(1,sizeof(RegTreeEntry_t));
51*0Sstevel@tonic-gate 	if(regTreeEntry_data == NULL) return SNMP_ERR_GENERR;
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate 	res = get_regTreeIndex(
54*0Sstevel@tonic-gate 	        search_type,
55*0Sstevel@tonic-gate 	        &((*regTreeEntry_data)->regTreeIndex),
56*0Sstevel@tonic-gate 	        index);
57*0Sstevel@tonic-gate 	if(res != SNMP_ERR_NOERROR) return res;
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate 	res = get_regTreeAgentID(
60*0Sstevel@tonic-gate 	        search_type,
61*0Sstevel@tonic-gate 	        &((*regTreeEntry_data)->regTreeAgentID),
62*0Sstevel@tonic-gate 	        index);
63*0Sstevel@tonic-gate 	if(res != SNMP_ERR_NOERROR) return res;
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate 	res = get_regTreeOID(
66*0Sstevel@tonic-gate 	        search_type,
67*0Sstevel@tonic-gate 	        &((*regTreeEntry_data)->regTreeOID),
68*0Sstevel@tonic-gate 	        index);
69*0Sstevel@tonic-gate 	if(res != SNMP_ERR_NOERROR) return res;
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate 	res = get_regTreeStatus(
72*0Sstevel@tonic-gate 	        search_type,
73*0Sstevel@tonic-gate 	        &((*regTreeEntry_data)->regTreeStatus),
74*0Sstevel@tonic-gate 	        index);
75*0Sstevel@tonic-gate 	if(res != SNMP_ERR_NOERROR) return res;
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 	 return res;
78*0Sstevel@tonic-gate }
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 
free_regTreeEntry(RegTreeEntry_t * regTreeEntry)81*0Sstevel@tonic-gate void free_regTreeEntry(RegTreeEntry_t *regTreeEntry)
82*0Sstevel@tonic-gate {
83*0Sstevel@tonic-gate 	free_regTreeOID(&(regTreeEntry->regTreeOID));
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate 
get_regTreeIndex(int search_type,Integer * regTreeIndex,IndexType * index)86*0Sstevel@tonic-gate int get_regTreeIndex(int search_type, Integer *regTreeIndex, IndexType *index)
87*0Sstevel@tonic-gate {
88*0Sstevel@tonic-gate 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
89*0Sstevel@tonic-gate 	/* this function should modify the index argument to the */
90*0Sstevel@tonic-gate 	/* appropriate value */
91*0Sstevel@tonic-gate 	switch(search_type)
92*0Sstevel@tonic-gate 	{
93*0Sstevel@tonic-gate 		case FIRST_ENTRY:
94*0Sstevel@tonic-gate 			if(index->type == INTEGER){
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate 				/* assume 1 is the first index */
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 				index->value[0] = 1;
99*0Sstevel@tonic-gate 				index->len = 1;
100*0Sstevel@tonic-gate 			}else{
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 				/* index type will be array of integer */
103*0Sstevel@tonic-gate 				/* assume that there are two index */
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate 				index->value[0] = 1;
106*0Sstevel@tonic-gate 				index->value[1]= 1;
107*0Sstevel@tonic-gate 				index->len = 2;
108*0Sstevel@tonic-gate 			}
109*0Sstevel@tonic-gate 			break;
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate 		case NEXT_ENTRY:
112*0Sstevel@tonic-gate 			if(index->type == INTEGER){
113*0Sstevel@tonic-gate 				index->value[0]++;
114*0Sstevel@tonic-gate 			}else{
115*0Sstevel@tonic-gate 
116*0Sstevel@tonic-gate 				/* index type will be array of integer */
117*0Sstevel@tonic-gate 				/* assume that there are two index */
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate 				index->value[index->len-1]++;
120*0Sstevel@tonic-gate 			}
121*0Sstevel@tonic-gate 			break;
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate 		case EXACT_ENTRY:
124*0Sstevel@tonic-gate 			break;
125*0Sstevel@tonic-gate 	}
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate 	/*assume that the mib variable has a value of 1 */
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 	*regTreeIndex = 1;
130*0Sstevel@tonic-gate 	return SNMP_ERR_NOERROR;
131*0Sstevel@tonic-gate }
132*0Sstevel@tonic-gate 
get_regTreeAgentID(int search_type,Integer * regTreeAgentID,IndexType * index)133*0Sstevel@tonic-gate int get_regTreeAgentID(int search_type, Integer *regTreeAgentID, IndexType *index)
134*0Sstevel@tonic-gate {
135*0Sstevel@tonic-gate 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
136*0Sstevel@tonic-gate 	/* this function should modify the index argument to the */
137*0Sstevel@tonic-gate 	/* appropriate value */
138*0Sstevel@tonic-gate 	switch(search_type)
139*0Sstevel@tonic-gate 	{
140*0Sstevel@tonic-gate 		case FIRST_ENTRY:
141*0Sstevel@tonic-gate 			if(index->type == INTEGER){
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 				/* assume 1 is the first index */
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate 				index->value[0] = 1;
146*0Sstevel@tonic-gate 				index->len = 1;
147*0Sstevel@tonic-gate 			}else{
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate 				/* index type will be array of integer */
150*0Sstevel@tonic-gate 				/* assume that there are two index */
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate 				index->value[0] = 1;
153*0Sstevel@tonic-gate 				index->value[1]= 1;
154*0Sstevel@tonic-gate 				index->len = 2;
155*0Sstevel@tonic-gate 			}
156*0Sstevel@tonic-gate 			break;
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate 		case NEXT_ENTRY:
159*0Sstevel@tonic-gate 			if(index->type == INTEGER){
160*0Sstevel@tonic-gate 				index->value[0]++;
161*0Sstevel@tonic-gate 			}else{
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate 				/* index type will be array of integer */
164*0Sstevel@tonic-gate 				/* assume that there are two index */
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate 				index->value[index->len-1]++;
167*0Sstevel@tonic-gate 			}
168*0Sstevel@tonic-gate 			break;
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate 		case EXACT_ENTRY:
171*0Sstevel@tonic-gate 			break;
172*0Sstevel@tonic-gate 	}
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate 	/*assume that the mib variable has a value of 1 */
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 	*regTreeAgentID = 1;
177*0Sstevel@tonic-gate 	return SNMP_ERR_NOERROR;
178*0Sstevel@tonic-gate }
179*0Sstevel@tonic-gate 
get_regTreeOID(int search_type,Oid * regTreeOID,IndexType * index)180*0Sstevel@tonic-gate int get_regTreeOID(int search_type, Oid *regTreeOID, IndexType *index)
181*0Sstevel@tonic-gate {
182*0Sstevel@tonic-gate 	Subid *sub;
183*0Sstevel@tonic-gate 	Subid fake_sub[] = {1,3,6,1,4,1,4,42};
184*0Sstevel@tonic-gate 	int len;
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
187*0Sstevel@tonic-gate 	/* this function should modify the index argument to the */
188*0Sstevel@tonic-gate 	/* appropriate value */
189*0Sstevel@tonic-gate 	switch(search_type)
190*0Sstevel@tonic-gate 	{
191*0Sstevel@tonic-gate 		case FIRST_ENTRY:
192*0Sstevel@tonic-gate 			if(index->type == INTEGER){
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate 				/* assume 1 is the first index */
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate 				index->value[0] = 1;
197*0Sstevel@tonic-gate 				index->len = 1;
198*0Sstevel@tonic-gate 			}else{
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate 				/* index type will be array of integer */
201*0Sstevel@tonic-gate 				/* assume that there are two index */
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 				index->value[0] = 1;
204*0Sstevel@tonic-gate 				index->value[1]= 1;
205*0Sstevel@tonic-gate 				index->len = 2;
206*0Sstevel@tonic-gate 			}
207*0Sstevel@tonic-gate 			break;
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate 		case NEXT_ENTRY:
210*0Sstevel@tonic-gate 			if(index->type == INTEGER){
211*0Sstevel@tonic-gate 				index->value[0]++;
212*0Sstevel@tonic-gate 			}else{
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate 				/* index type will be array of integer */
215*0Sstevel@tonic-gate 				/* assume that there are two index */
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate 				index->value[index->len-1]++;
218*0Sstevel@tonic-gate 			}
219*0Sstevel@tonic-gate 			break;
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate 		case EXACT_ENTRY:
222*0Sstevel@tonic-gate 			break;
223*0Sstevel@tonic-gate 	}
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate 	/* It is required to allocate memory to the pointers */
226*0Sstevel@tonic-gate 	/* inside the input argument */
227*0Sstevel@tonic-gate 	/* Here, we assume that "1.3.6.1.4.1.42" is the value */
228*0Sstevel@tonic-gate 	/* of the mib variable */
229*0Sstevel@tonic-gate 	/* please change it to the real one */
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate 	/* 1.3.6.1.4.1.42 has 7 number separated by "." */
232*0Sstevel@tonic-gate 
233*0Sstevel@tonic-gate 	len =7 ;
234*0Sstevel@tonic-gate 	sub = (Subid*)calloc(len,sizeof(Subid));
235*0Sstevel@tonic-gate 	if(sub==NULL) return SNMP_ERR_GENERR;
236*0Sstevel@tonic-gate 	memcpy(sub,fake_sub,len*sizeof(Subid));
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate 	/* fill in the contents of the argument */
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate 	regTreeOID->subids = sub;
241*0Sstevel@tonic-gate 	regTreeOID->len = len;
242*0Sstevel@tonic-gate 	return SNMP_ERR_NOERROR;
243*0Sstevel@tonic-gate }
244*0Sstevel@tonic-gate 
set_regTreeOID(int pass,IndexType index,Oid * regTreeOID)245*0Sstevel@tonic-gate int set_regTreeOID(int pass, IndexType index, Oid *regTreeOID)
246*0Sstevel@tonic-gate {
247*0Sstevel@tonic-gate 	switch(pass)
248*0Sstevel@tonic-gate 	{
249*0Sstevel@tonic-gate 		case FIRST_PASS:
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate 			/* check the existence of the element which */
252*0Sstevel@tonic-gate 			/* corresponding to the given index and */
253*0Sstevel@tonic-gate 			/* check the validity fo the input value */
254*0Sstevel@tonic-gate 			/* if not valid or not exist, */
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate 			return SNMP_ERR_GENERR;
257*0Sstevel@tonic-gate 
258*0Sstevel@tonic-gate 		case SECOND_PASS:
259*0Sstevel@tonic-gate 
260*0Sstevel@tonic-gate 			/* change the following coding, such that */
261*0Sstevel@tonic-gate 			/* the input value will be stored in the */
262*0Sstevel@tonic-gate 			/* corresponding mib variable of the given */
263*0Sstevel@tonic-gate 			/* index */
264*0Sstevel@tonic-gate 			printf("The new value is %s\n",SSAOidString(regTreeOID));
265*0Sstevel@tonic-gate 			return SNMP_ERR_NOERROR;
266*0Sstevel@tonic-gate 	}
267*0Sstevel@tonic-gate }
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate 
free_regTreeOID(Oid * regTreeOID)270*0Sstevel@tonic-gate void free_regTreeOID(Oid *regTreeOID)
271*0Sstevel@tonic-gate {
272*0Sstevel@tonic-gate 	 if(regTreeOID->subids!=NULL && regTreeOID->len !=0)
273*0Sstevel@tonic-gate 	{
274*0Sstevel@tonic-gate 		free(regTreeOID->subids);
275*0Sstevel@tonic-gate 		regTreeOID->len = 0;
276*0Sstevel@tonic-gate 	}
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate 
get_regTreeStatus(int search_type,Integer * regTreeStatus,IndexType * index)279*0Sstevel@tonic-gate int get_regTreeStatus(int search_type, Integer *regTreeStatus, IndexType *index)
280*0Sstevel@tonic-gate {
281*0Sstevel@tonic-gate 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
282*0Sstevel@tonic-gate 	/* this function should modify the index argument to the */
283*0Sstevel@tonic-gate 	/* appropriate value */
284*0Sstevel@tonic-gate 	switch(search_type)
285*0Sstevel@tonic-gate 	{
286*0Sstevel@tonic-gate 		case FIRST_ENTRY:
287*0Sstevel@tonic-gate 			if(index->type == INTEGER){
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate 				/* assume 1 is the first index */
290*0Sstevel@tonic-gate 
291*0Sstevel@tonic-gate 				index->value[0] = 1;
292*0Sstevel@tonic-gate 				index->len = 1;
293*0Sstevel@tonic-gate 			}else{
294*0Sstevel@tonic-gate 
295*0Sstevel@tonic-gate 				/* index type will be array of integer */
296*0Sstevel@tonic-gate 				/* assume that there are two index */
297*0Sstevel@tonic-gate 
298*0Sstevel@tonic-gate 				index->value[0] = 1;
299*0Sstevel@tonic-gate 				index->value[1]= 1;
300*0Sstevel@tonic-gate 				index->len = 2;
301*0Sstevel@tonic-gate 			}
302*0Sstevel@tonic-gate 			break;
303*0Sstevel@tonic-gate 
304*0Sstevel@tonic-gate 		case NEXT_ENTRY:
305*0Sstevel@tonic-gate 			if(index->type == INTEGER){
306*0Sstevel@tonic-gate 				index->value[0]++;
307*0Sstevel@tonic-gate 			}else{
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate 				/* index type will be array of integer */
310*0Sstevel@tonic-gate 				/* assume that there are two index */
311*0Sstevel@tonic-gate 
312*0Sstevel@tonic-gate 				index->value[index->len-1]++;
313*0Sstevel@tonic-gate 			}
314*0Sstevel@tonic-gate 			break;
315*0Sstevel@tonic-gate 
316*0Sstevel@tonic-gate 		case EXACT_ENTRY:
317*0Sstevel@tonic-gate 			break;
318*0Sstevel@tonic-gate 	}
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate 	/*assume that the mib variable has a value of 1 */
321*0Sstevel@tonic-gate 
322*0Sstevel@tonic-gate 	*regTreeStatus = 1;
323*0Sstevel@tonic-gate 	return SNMP_ERR_NOERROR;
324*0Sstevel@tonic-gate }
325*0Sstevel@tonic-gate 
set_regTreeStatus(int pass,IndexType index,Integer * regTreeStatus)326*0Sstevel@tonic-gate int set_regTreeStatus(int pass, IndexType index, Integer *regTreeStatus)
327*0Sstevel@tonic-gate {
328*0Sstevel@tonic-gate 	switch(pass)
329*0Sstevel@tonic-gate 	{
330*0Sstevel@tonic-gate 		case FIRST_PASS:
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 			/* check the existence of the element which */
333*0Sstevel@tonic-gate 			/* corresponding to the given index and */
334*0Sstevel@tonic-gate 			/* check the validity fo the input value */
335*0Sstevel@tonic-gate 			/* if not valid or not exist, */
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate 			return SNMP_ERR_GENERR;
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 		case SECOND_PASS:
340*0Sstevel@tonic-gate 
341*0Sstevel@tonic-gate 			/* change the following coding, such that */
342*0Sstevel@tonic-gate 			/* the input value will be stored in the */
343*0Sstevel@tonic-gate 			/* corresponding mib variable of the given */
344*0Sstevel@tonic-gate 			/* index */
345*0Sstevel@tonic-gate 			printf("The new value is %d\n",regTreeStatus);
346*0Sstevel@tonic-gate 			return SNMP_ERR_NOERROR;
347*0Sstevel@tonic-gate 	}
348*0Sstevel@tonic-gate }
349*0Sstevel@tonic-gate 
350