1 /* -*- mode:C; c-file-style: "bsd" -*- */
2 /*
3 * Copyright (c) 2012-2015 Yubico AB
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <assert.h>
35 #include <stdbool.h>
36
37 #include <ykstatus.h>
38 #include <ykcore.h>
39 #include <ykdef.h>
40
41 struct versions {
42 int major;
43 int minor;
44 int build;
45 bool support;
46 } supported[] = {
47 {0,8,0,true},
48 {0,9,9,true},
49 {1,2,9,true},
50 {1,3,1,true},
51 {1,4,5,true},
52 {2,0,2,true},
53 {2,1,1,true},
54 {2,2,3,true},
55 {2,3,0,true},
56 {2,4,5,true},
57 {2,5,2,true},
58 {2,6,0,true},
59 {3,0,1,true},
60 {3,2,8,true},
61 {3,3,0,true},
62 {3,4,3,true},
63 {3,5,1,true},
64 {4,0,1,true},
65 {4,1,2,true},
66 {4,1,10,true},
67 {4,2,1,true},
68 {4,3,7,true},
69 {4,4,5,true},
70 {5,0,0,true},
71 };
72
_test_init_st(int major,int minor,int build)73 static YK_STATUS * _test_init_st(int major, int minor, int build)
74 {
75 YK_STATUS *st = ykds_alloc();
76 struct status_st *t;
77
78 t = (struct status_st *) st;
79
80 /* connected key details */
81 t->versionMajor = major;
82 t->versionMinor = minor;
83 t->versionBuild = build;
84
85 return st;
86 }
87
_test_yk_firmware(void)88 static void _test_yk_firmware(void)
89 {
90 size_t i;
91 for(i = 0; i < sizeof(supported) / sizeof(struct versions); i++) {
92 int rc;
93 YK_STATUS *st = _test_init_st(supported[i].major, supported[i].minor, supported[i].build);
94 printf("testing: %d.%d.%d\n", supported[i].major, supported[i].minor, supported[i].build);
95 rc = yk_check_firmware_version2(st);
96 if(supported[i].support == true) {
97 assert(rc == 1);
98 } else {
99 assert(yk_errno == YK_EFIRMWARE);
100 assert(rc == 0);
101 }
102 ykds_free(st);
103 }
104 }
105
main(void)106 int main(void)
107 {
108 _test_yk_firmware();
109
110 return 0;
111 }
112
113