File: maemo_usb_helper.c

package info (click to toggle)
spectools 201601r1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,272 kB
  • ctags: 1,837
  • sloc: ansic: 18,708; sh: 2,476; makefile: 85
file content (52 lines) | stat: -rw-r--r-- 1,181 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Maemo USB helper utility to wedge drivers in and out of host mode, needed
 * for suidroot capability
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

int main(int argc, char *argv[]) {
	FILE *controlf;

	if (argc < 2) {
		fprintf(stderr, "Failed to parse mode request\n");
		exit(1);
	}

	if (strcasecmp(argv[1], "host") == 0) {
		if ((controlf = fopen("/sys/devices/platform/musb_hdrc/mode", "w")) != NULL) {
			fprintf(controlf, "peripheral\n");
			fflush(controlf);
			usleep(10000);
			fprintf(controlf, "host\n");
			fflush(controlf);
			fclose(controlf);
			exit(0);
		} else {
			fprintf(stderr, "Failed to open musb_hdrc/mode: %s\n", strerror(errno));
			exit(0);
		}
	} 

	if (strcasecmp(argv[1], "periph") == 0) {
		if ((controlf = fopen("/sys/devices/platform/musb_hdrc/mode", "w")) != NULL) {
			fprintf(controlf, "peripheral\n");
			fflush(controlf);
			usleep(10000);
			fprintf(controlf, "otg\n");
			fflush(controlf);
			fclose(controlf);
			exit(0);
		} else {
			fprintf(stderr, "Failed to open musb_hdrc/mode: %s\n", strerror(errno));
			exit(0);
		}
	} 

	fprintf(stderr, "Failed to parse mode request\n");

	exit(1);
}