xref: /openbsd/usr.sbin/ldomctl/pri.c (revision a6445c1d)
1 /*	$OpenBSD: pri.c,v 1.1 2012/11/04 19:04:11 kettenis Exp $	*/
2 
3 /*
4  * Copyright (c) 2012 Mark Kettenis
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <stdio.h>
20 #include <string.h>
21 
22 #include "ds.h"
23 #include "mdesc.h"
24 #include "util.h"
25 
26 void	pri_start(struct ldc_conn *, uint64_t);
27 void	pri_rx_data(struct ldc_conn *, uint64_t, void *, size_t);
28 
29 struct ds_service pri_service = {
30 	"pri", 1, 0, pri_start, pri_rx_data
31 };
32 
33 #define PRI_REQUEST	0x00
34 
35 struct pri_msg {
36 	uint32_t	msg_type;
37 	uint32_t	payload_len;
38 	uint64_t	svc_handle;
39 	uint64_t	reqnum;
40 	uint64_t	type;
41 } __packed;
42 
43 #define PRI_DATA	0x01
44 
45 struct pri_data {
46 	uint32_t	msg_type;
47 	uint32_t	payload_len;
48 	uint64_t	svc_handle;
49 	uint64_t	reqnum;
50 	uint64_t	type;
51 	char		data[1];
52 } __packed;
53 
54 #define PRI_UPDATE	0x02
55 
56 struct pri_update {
57 	uint32_t	msg_type;
58 	uint32_t	payload_len;
59 	uint64_t	svc_handle;
60 	uint64_t	reqnum;
61 	uint64_t	type;
62 } __packed;
63 
64 void
65 pri_start(struct ldc_conn *lc, uint64_t svc_handle)
66 {
67 	struct pri_msg pm;
68 
69 	bzero(&pm, sizeof(pm));
70 	pm.msg_type = DS_DATA;
71 	pm.payload_len = sizeof(pm) - 8;
72 	pm.svc_handle = svc_handle;
73 	pm.reqnum = 0;
74 	pm.type = PRI_REQUEST;
75 	ds_send_msg(lc, &pm, sizeof(pm));
76 }
77 
78 void *pri_buf;
79 size_t pri_len;
80 
81 void
82 pri_rx_data(struct ldc_conn *lc, uint64_t svc_handle, void *data, size_t len)
83 {
84 	struct pri_data *pd = data;
85 
86 	if (pd->type != PRI_DATA) {
87 		DPRINTF(("Unexpected PRI message type 0x%02llx\n", pd->type));
88 		return;
89 	}
90 
91 	pri_len = pd->payload_len - 24;
92 	pri_buf = xmalloc(pri_len);
93 
94 	len -= sizeof(struct pri_msg);
95 	bcopy(&pd->data, pri_buf, len);
96 	ds_receive_msg(lc, pri_buf + len, pri_len - len);
97 }
98