2 * Copyright © 2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
39 static void wait_event(int pipe
, enum auth_event expected_event
)
42 enum auth_event event
;
45 ret
= read(commfd
[pipe
], &in
, 1);
50 if (event
!= expected_event
)
51 errx(1, "unexpected event: %d\n", event
);
55 send_event(int pipe
, enum auth_event send_event
)
61 ret
= write(commfd
[pipe
], &event
, 1);
63 err(1, "failed to send event %d", event
);
71 /* XXX: Should make sure we open the same DRM as the master */
72 wait_event(0, SERVER_READY
);
74 drmfd
= drm_open_any();
76 /* Get a client magic number and pass it to the master for auth. */
77 auth
.magic
= 0; /* Quiet valgrind */
78 ret
= ioctl(drmfd
, DRM_IOCTL_GET_MAGIC
, &auth
);
80 err(1, "Couldn't get client magic");
81 send_event(0, CLIENT_MAGIC
);
82 ret
= write(commfd
[0], &auth
.magic
, sizeof(auth
.magic
));
84 err(1, "Couldn't write auth data");
86 /* Signal that the client is completely done. */
87 send_event(0, CLIENT_DONE
);
95 drmfd
= drm_open_any_master();
97 auth
.magic
= 0xd0d0d0d0;
98 ret
= ioctl(drmfd
, DRM_IOCTL_AUTH_MAGIC
, &auth
);
99 if (ret
!= -1 || errno
!= EINVAL
)
100 errx(1, "Authenticating bad magic succeeded\n");
102 send_event(1, SERVER_READY
);
104 wait_event(1, CLIENT_MAGIC
);
105 ret
= read(commfd
[1], &auth
.magic
, sizeof(auth
.magic
));
107 err(1, "Failure to read client magic");
109 ret
= ioctl(drmfd
, DRM_IOCTL_AUTH_MAGIC
, &auth
);
111 err(1, "Failure to authenticate client magic\n");
113 wait_event(1, CLIENT_DONE
);
117 * Checks DRM authentication mechanisms.
119 int main(int argc
, char **argv
)
125 err(1, "Couldn't create pipe");
129 err(1, "failure to fork client");