1 /*
2  * v4l-test: Test environment for Video For Linux Two API
3  *
4  * 30 Jan 2009  0.1  First release
5  *
6  * Written by M�rton N�meth <nm127@freemail.hu>
7  * Released under GPL
8  */
9 
10 #include <stdio.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <sys/ioctl.h>
16 #include <errno.h>
17 #include <string.h>
18 
19 #include <linux/videodev2.h>
20 #include <linux/errno.h>
21 
22 #include "v4l2_test.h"
23 #include "dev_video.h"
24 #include "video_limits.h"
25 #include "v4l2_validator.h"
26 
valid_v4l2_std_id(v4l2_std_id std_id)27 int valid_v4l2_std_id(v4l2_std_id std_id)
28 {
29 	int valid = 0;
30 
31 	if ((std_id & ~(V4L2_STD_PAL_B |
32 			V4L2_STD_PAL_B1 |
33 			V4L2_STD_PAL_G |
34 			V4L2_STD_PAL_H |
35 			V4L2_STD_PAL_I |
36 			V4L2_STD_PAL_D |
37 			V4L2_STD_PAL_D1 |
38 			V4L2_STD_PAL_K |
39 			V4L2_STD_PAL_M |
40 			V4L2_STD_PAL_N |
41 			V4L2_STD_PAL_Nc |
42 			V4L2_STD_PAL_60 |
43 			V4L2_STD_NTSC_M |
44 			V4L2_STD_NTSC_M_JP |
45 			V4L2_STD_NTSC_443 |
46 			V4L2_STD_NTSC_M_KR |
47 			V4L2_STD_SECAM_B |
48 			V4L2_STD_SECAM_D |
49 			V4L2_STD_SECAM_G |
50 			V4L2_STD_SECAM_H |
51 			V4L2_STD_SECAM_K |
52 			V4L2_STD_SECAM_K1 |
53 			V4L2_STD_SECAM_L |
54 			V4L2_STD_SECAM_LC |
55 			V4L2_STD_ATSC_8_VSB | V4L2_STD_ATSC_16_VSB))
56 	    == 0) {
57 		valid = 1;
58 	} else {
59 		valid = 0;
60 	}
61 	return valid;
62 }
63 
valid_tuner_capability(__u32 capability)64 int valid_tuner_capability(__u32 capability)
65 {
66 	int valid = 0;
67 
68 	if ((capability & ~(V4L2_TUNER_CAP_LOW |
69 			    V4L2_TUNER_CAP_NORM |
70 			    V4L2_TUNER_CAP_STEREO |
71 			    V4L2_TUNER_CAP_LANG1 |
72 			    V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP))
73 	    == 0) {
74 		valid = 1;
75 	} else {
76 		valid = 0;
77 	}
78 	return valid;
79 }
80 
valid_modulator_capability(__u32 capability)81 int valid_modulator_capability(__u32 capability)
82 {
83 	return valid_tuner_capability(capability);
84 }
85 
valid_string(char * str,unsigned int max_length)86 int valid_string(char *str, unsigned int max_length)
87 {
88 	int valid = 1;
89 	unsigned int i;
90 
91 	i = 0;
92 	while (i < max_length && str[i] != 0) {
93 		/* Printable characters start with SPACE (32) and
94 		 * ends with '~' (126) inclusively.
95 		 */
96 		if (str[i] < 32 || 126 < str[i]) {
97 			valid = 0;
98 			break;
99 		}
100 		i++;
101 	}
102 
103 	/* check if the string was closed with zero byte properly */
104 	if (i == max_length) {
105 		valid = 0;
106 	}
107 
108 	return valid;
109 }
110