dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / common / modules / crypto / common.c
blob4f368ec0652e7e09a011f2c616021daee2844044
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * mdb dcmds for selected structures from include/sys/crypto/common.h
33 #include <sys/mdb_modapi.h>
34 #include <sys/modctl.h>
35 #include <sys/types.h>
36 #include <sys/crypto/api.h>
37 #include <sys/crypto/common.h>
38 #include <sys/crypto/spi.h>
39 #include <sys/crypto/impl.h>
40 #include "crypto_cmds.h"
42 /*ARGSUSED*/
43 int
44 crypto_mechanism(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
46 crypto_mechanism_t mch;
48 if (!(flags & DCMD_ADDRSPEC))
49 return (DCMD_USAGE);
51 if (mdb_vread(&mch, sizeof (crypto_mechanism_t), addr) == -1) {
52 mdb_warn("cannot read %p", addr);
53 return (DCMD_ERR);
55 /* XXX a future RFE will interpret cm_type */
56 mdb_printf("cm_type\t%ll#x\n", mch.cm_type);
57 mdb_printf("cm_param\t%p\n", mch.cm_param);
58 mdb_printf("cm_param_len\t%u\n", mch.cm_param_len);
59 return (DCMD_OK);
62 /*ARGSUSED*/
63 static void
64 iovec_prt(iovec_t *addr)
66 mdb_printf("iov_base\t%p\n", addr->iov_base);
67 mdb_printf("iov_len\t\t%d\n", addr->iov_len);
70 /*ARGSUSED*/
71 static void
72 uio_prt(uio_t *addr)
74 char *segstrings[] = {
75 "UIO_USERSPACE",
76 "UIO_SYSSPACE",
77 "UIO_USERISPACE"
79 iovec_t iov;
80 uio_t uio;
81 int i;
83 mdb_printf("uio\t%p\n", addr);
84 if (mdb_vread(&uio, sizeof (uio_t), (uintptr_t)addr)
85 == -1) {
86 mdb_warn("uio_prt: could not read uio");
88 mdb_inc_indent(4);
89 for (i = 0; i < uio.uio_iovcnt; i++) {
90 if (mdb_vread(&iov, sizeof (iovec_t),
91 (uintptr_t)(uio.uio_iov +i))
92 == -1) {
93 mdb_printf("uio_iov\t?????");
94 mdb_warn("uio_prt: could not read uio_iov[%s]", i);
95 } else
96 iovec_prt(&iov);
98 mdb_dec_indent(4);
99 mdb_printf("uio_iovcnt\t%d\n", uio.uio_iovcnt);
100 mdb_printf("uio_offset\t%lld\n", uio.uio_offset);
101 mdb_printf("uio_segflg\t%s", segstrings[uio.uio_segflg]);
102 mdb_printf("uio_fmode\t0%o", (int)uio.uio_fmode);
103 mdb_printf("uio_limit\t%lld", uio.uio_limit);
104 mdb_printf("uio_resid\t%ld", uio.uio_resid);
107 static char *cdstrings[] = {
108 "INVALID FORMAT",
109 "CRYPTO_DATA_RAW",
110 "CRYPTO_DATA_UIO",
111 "CRYPTO_DATA_MBLK"
115 * Routine to print either of two structrually identical sub-structures --
116 * with different naming conventions. Might be changed if we decide
117 * to merge the two. They are the cdu union from crypto_data_t and
118 * the one from crypto_dual_data_t.
121 typedef union crypto_data_union {
122 iovec_t cdu_raw; /* Raw format */
123 uio_t *cdu_uio; /* uio scatter-gather format */
124 mblk_t *cdu_mp; /* The mblk chain */
125 } crypto_data_union_t;
127 /*ARGSUSED*/
128 static void
129 prt_cdu(crypto_data_union_t *cdu, int format, const char *prefix)
132 switch (format) {
133 case CRYPTO_DATA_RAW:
134 mdb_printf("%s_raw:\n", prefix);
135 mdb_inc_indent(4);
136 iovec_prt(&cdu->cdu_raw);
137 mdb_dec_indent(4);
138 break;
140 case CRYPTO_DATA_UIO:
141 mdb_printf("%s_uio:\n", prefix);
142 mdb_inc_indent(4);
143 uio_prt(cdu->cdu_uio);
144 mdb_dec_indent(4);
145 break;
147 case CRYPTO_DATA_MBLK:
148 mdb_printf("%s_mp:\t\t%p\n", prefix, cdu->cdu_mp);
149 break;
151 default:
152 mdb_printf("cm_format\t??????\n");
153 break;
157 /*ARGSUSED*/
159 crypto_data(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
161 crypto_data_t data;
163 if (!(flags & DCMD_ADDRSPEC))
164 return (DCMD_USAGE);
166 if (mdb_vread(&data, sizeof (crypto_data_t), addr) == -1) {
167 mdb_warn("cannot read %p", addr);
168 return (DCMD_ERR);
170 if ((data.cd_format >= CRYPTO_DATA_RAW) &&
171 (data.cd_format <= CRYPTO_DATA_MBLK))
172 mdb_printf("cm_format\t%s\n", cdstrings[data.cd_format]);
173 else
174 mdb_printf("bad cm_format\t%d\n", data.cd_format);
175 mdb_printf("cm_offset\t%ld\n", data.cd_offset);
176 mdb_printf("cm_length\t%ld\n", data.cd_length);
177 mdb_printf("cm_miscdata\t%p\n", data.cd_miscdata);
178 mdb_inc_indent(4);
179 prt_cdu((crypto_data_union_t *)&data.cdu, data.cd_format, "cdu");
180 mdb_dec_indent(4);
181 return (DCMD_OK);
184 /*ARGSUSED*/
186 crypto_dual_data(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
188 crypto_dual_data_t ddata;
190 if (!(flags & DCMD_ADDRSPEC))
191 return (DCMD_USAGE);
193 if (mdb_vread(&ddata, sizeof (crypto_dual_data_t), addr) == -1) {
194 mdb_warn("cannot read %p", addr);
195 return (DCMD_ERR);
197 if ((ddata.dd_format > CRYPTO_DATA_RAW) &&
198 (ddata.dd_format <= CRYPTO_DATA_MBLK))
199 mdb_printf("dd_format\t%s\n", cdstrings[ddata.dd_format]);
200 else
201 mdb_printf("bad dd_format\t%d\n", ddata.dd_format);
202 mdb_printf("dd_offset1\t%ld\n", ddata.dd_offset1);
203 mdb_printf("dd_len1\t%ld\n", ddata.dd_len1);
204 mdb_printf("dd_offset2\t%ld\n", ddata.dd_offset2);
205 mdb_printf("dd_len2\t%ld\n", ddata.dd_len2);
206 mdb_printf("dd_miscdata\t%p\n", ddata.dd_miscdata);
207 mdb_printf("cdu:\n");
208 mdb_inc_indent(4);
209 prt_cdu((crypto_data_union_t *)&ddata.dd_data.cdu, ddata.dd_format,
210 "ddu");
211 mdb_dec_indent(4);
212 return (DCMD_OK);
216 /*ARGSUSED*/
218 crypto_key(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
220 crypto_key_t key;
222 if (!(flags & DCMD_ADDRSPEC))
223 return (DCMD_USAGE);
225 if (mdb_vread(&key, sizeof (crypto_key_t), addr) == -1) {
226 mdb_warn("cannot read %p", addr);
227 return (DCMD_ERR);
229 switch (key.ck_format) {
230 case CRYPTO_KEY_RAW:
231 mdb_printf("ck_format:\tCRYPTO_KEY_RAW\n");
232 mdb_printf(
233 "cku_data.cku_key_value.cku_data.cku_v_length:\t%d\n",
234 key.cku_data.cku_key_value.cku_v_length);
235 mdb_printf("cku_data.cku_key_value.cku_v_data:\t%p\n",
236 key.cku_data.cku_key_value.cku_v_data);
237 break;
238 case CRYPTO_KEY_REFERENCE:
239 mdb_printf("ck_format:\tCRYPTO_KEY_REFERENCE\n");
240 mdb_printf("cku_data.cku_key_id:\t%u\n",
241 key.cku_data.cku_key_id);
242 break;
243 case CRYPTO_KEY_ATTR_LIST:
244 mdb_printf("ck_format:\tCRYPTO_KEY_ATTR_LIST\n");
245 mdb_printf("cku_data.cku_key_attrs.cku_a_count:\t%u\n",
246 key.cku_data.cku_key_attrs.cku_a_count);
247 mdb_printf("cku_data.cku_key_attrs.cku_o_oattr:\t%p\n",
248 key.cku_data.cku_key_attrs.cku_a_oattr);
249 break;
250 default:
251 mdb_printf("ck_format:\t\t?????\n");
252 break;
254 return (DCMD_OK);