1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * s_common.c - common utilities for Solaris PPP
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc.
5*7c478bd9Sstevel@tonic-gate * All rights reserved.
6*7c478bd9Sstevel@tonic-gate *
7*7c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this software and its
8*7c478bd9Sstevel@tonic-gate * documentation is hereby granted, provided that the above copyright
9*7c478bd9Sstevel@tonic-gate * notice appears in all copies.
10*7c478bd9Sstevel@tonic-gate *
11*7c478bd9Sstevel@tonic-gate * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
12*7c478bd9Sstevel@tonic-gate * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13*7c478bd9Sstevel@tonic-gate * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14*7c478bd9Sstevel@tonic-gate * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
15*7c478bd9Sstevel@tonic-gate * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
16*7c478bd9Sstevel@tonic-gate * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
17*7c478bd9Sstevel@tonic-gate */
18*7c478bd9Sstevel@tonic-gate
19*7c478bd9Sstevel@tonic-gate #define RCSID "$Id: s_common.c,v 1.0 2000/05/08 01:10:12 masputra Exp $"
20*7c478bd9Sstevel@tonic-gate
21*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
22*7c478bd9Sstevel@tonic-gate #include <sys/debug.h>
23*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
24*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
25*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
26*7c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
27*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
28*7c478bd9Sstevel@tonic-gate #include <sys/ioccom.h>
29*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
33*7c478bd9Sstevel@tonic-gate #include <net/ppp_defs.h>
34*7c478bd9Sstevel@tonic-gate #include <net/pppio.h>
35*7c478bd9Sstevel@tonic-gate #include "s_common.h"
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate /*
38*7c478bd9Sstevel@tonic-gate * putctl4()
39*7c478bd9Sstevel@tonic-gate *
40*7c478bd9Sstevel@tonic-gate * Description:
41*7c478bd9Sstevel@tonic-gate * Create and send a 4-byte message.
42*7c478bd9Sstevel@tonic-gate */
43*7c478bd9Sstevel@tonic-gate int
putctl4(queue_t * q,uchar_t type,uchar_t code,uint16_t val)44*7c478bd9Sstevel@tonic-gate putctl4(queue_t *q, uchar_t type, uchar_t code, uint16_t val)
45*7c478bd9Sstevel@tonic-gate {
46*7c478bd9Sstevel@tonic-gate mblk_t *mp;
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate if ((mp = allocb(4, BPRI_HI)) == NULL) {
49*7c478bd9Sstevel@tonic-gate return (0);
50*7c478bd9Sstevel@tonic-gate }
51*7c478bd9Sstevel@tonic-gate MTYPE(mp) = type;
52*7c478bd9Sstevel@tonic-gate mp->b_wptr[0] = code;
53*7c478bd9Sstevel@tonic-gate ((uint16_t *)mp->b_wptr)[1] = val;
54*7c478bd9Sstevel@tonic-gate mp->b_wptr += 4;
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate putnext(q, mp);
57*7c478bd9Sstevel@tonic-gate return (1);
58*7c478bd9Sstevel@tonic-gate }
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate /*
61*7c478bd9Sstevel@tonic-gate * putctl8()
62*7c478bd9Sstevel@tonic-gate *
63*7c478bd9Sstevel@tonic-gate * Description:
64*7c478bd9Sstevel@tonic-gate * Create and send a 8-byte message.
65*7c478bd9Sstevel@tonic-gate */
66*7c478bd9Sstevel@tonic-gate int
putctl8(queue_t * q,uchar_t type,uchar_t code,uint32_t val)67*7c478bd9Sstevel@tonic-gate putctl8(queue_t *q, uchar_t type, uchar_t code, uint32_t val)
68*7c478bd9Sstevel@tonic-gate {
69*7c478bd9Sstevel@tonic-gate mblk_t *mp;
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate if ((mp = allocb(8, BPRI_HI)) == NULL) {
72*7c478bd9Sstevel@tonic-gate return (0);
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate MTYPE(mp) = type;
75*7c478bd9Sstevel@tonic-gate mp->b_wptr[0] = code;
76*7c478bd9Sstevel@tonic-gate ((uint32_t *)mp->b_wptr)[1] = val;
77*7c478bd9Sstevel@tonic-gate mp->b_wptr += 8;
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate putnext(q, mp);
80*7c478bd9Sstevel@tonic-gate return (1);
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate * msg_byte()
85*7c478bd9Sstevel@tonic-gate *
86*7c478bd9Sstevel@tonic-gate * Description:
87*7c478bd9Sstevel@tonic-gate * Helper routine to return a specific byte off a data buffer.
88*7c478bd9Sstevel@tonic-gate */
89*7c478bd9Sstevel@tonic-gate int
msg_byte(mblk_t * mp,unsigned int i)90*7c478bd9Sstevel@tonic-gate msg_byte(mblk_t *mp, unsigned int i)
91*7c478bd9Sstevel@tonic-gate {
92*7c478bd9Sstevel@tonic-gate while (mp != NULL) {
93*7c478bd9Sstevel@tonic-gate if (i < MBLKL(mp)) {
94*7c478bd9Sstevel@tonic-gate break;
95*7c478bd9Sstevel@tonic-gate }
96*7c478bd9Sstevel@tonic-gate i -= MBLKL(mp);
97*7c478bd9Sstevel@tonic-gate mp = mp->b_cont;
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate if (mp == NULL) {
100*7c478bd9Sstevel@tonic-gate return (-1);
101*7c478bd9Sstevel@tonic-gate }
102*7c478bd9Sstevel@tonic-gate return (mp->b_rptr[i]);
103*7c478bd9Sstevel@tonic-gate }
104*7c478bd9Sstevel@tonic-gate
105*7c478bd9Sstevel@tonic-gate /*
106*7c478bd9Sstevel@tonic-gate * sppp_create_lsmsg()
107*7c478bd9Sstevel@tonic-gate *
108*7c478bd9Sstevel@tonic-gate * Description:
109*7c478bd9Sstevel@tonic-gate * Create a PPP link status message.
110*7c478bd9Sstevel@tonic-gate */
111*7c478bd9Sstevel@tonic-gate mblk_t *
create_lsmsg(enum LSstat ls_type)112*7c478bd9Sstevel@tonic-gate create_lsmsg(enum LSstat ls_type)
113*7c478bd9Sstevel@tonic-gate {
114*7c478bd9Sstevel@tonic-gate mblk_t *mp;
115*7c478bd9Sstevel@tonic-gate struct ppp_ls *plt;
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate if ((mp = allocb(sizeof (*plt), BPRI_HI)) == NULL) {
118*7c478bd9Sstevel@tonic-gate return (NULL);
119*7c478bd9Sstevel@tonic-gate }
120*7c478bd9Sstevel@tonic-gate /*
121*7c478bd9Sstevel@tonic-gate * Make sure that this message is a control message, and contains
122*7c478bd9Sstevel@tonic-gate * a notification that the link has been terminated.
123*7c478bd9Sstevel@tonic-gate */
124*7c478bd9Sstevel@tonic-gate MTYPE(mp) = M_PROTO;
125*7c478bd9Sstevel@tonic-gate mp->b_wptr += sizeof (*plt);
126*7c478bd9Sstevel@tonic-gate plt = (struct ppp_ls *)mp->b_rptr;
127*7c478bd9Sstevel@tonic-gate plt->magic = PPPLSMAGIC;
128*7c478bd9Sstevel@tonic-gate plt->ppp_message = ls_type;
129*7c478bd9Sstevel@tonic-gate
130*7c478bd9Sstevel@tonic-gate return (mp);
131*7c478bd9Sstevel@tonic-gate }
132