Skip to content

Latest commit

 

History

History
117 lines (101 loc) · 2.83 KB

usb_moded-android.c

File metadata and controls

117 lines (101 loc) · 2.83 KB
 
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
/**
@file usb_moded-android.c
Copyright (C) 2013 Jolla. All rights reserved.
@author: Philippe De Swert <philippe.deswert@jollamobile.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include <stdio.h>
#include <glib.h>
#include "usb_moded-android.h"
#include "usb_moded-log.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-config.h"
Aug 14, 2013
Aug 14, 2013
30
#include "usb_moded-mac.h"
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/** check if android settings are set
*
* @return 1 if settings are available, 0 if not
*
*/
int android_settings(void)
{
int ret = 0;
ret = check_android_section();
return ret;
}
/** initialize the basic android values
*/
void android_init_values(void)
{
const char *text;
text = get_android_manufacturer();
if(text)
{
write_to_file("/sys/class/android_usb/android0/iManufacturer", text);
g_free((char *)text);
}
Aug 7, 2013
Aug 7, 2013
58
text = get_android_vendor_id();
59
60
61
62
63
if(text)
{
write_to_file("/sys/class/android_usb/android0/idVendor", text);
g_free((char *)text);
}
Aug 2, 2013
Aug 2, 2013
64
65
66
67
68
69
text = get_android_product();
if(text)
{
write_to_file("/sys/class/android_usb/android0/iProduct", text);
g_free((char *)text);
}
Aug 7, 2013
Aug 7, 2013
70
71
72
73
74
75
text = get_android_product_id();
if(text)
{
write_to_file("/sys/class/android_usb/android0/idProduct", text);
g_free((char *)text);
}
Aug 14, 2013
Aug 14, 2013
76
77
78
79
80
81
82
83
text = read_mac();
if(text)
{
write_to_file("/sys/class/android_usb/f_rndis/ethaddr", text);
g_free((char *)text);
}
}
Aug 14, 2013
Aug 14, 2013
84
85
86
87
88
89
90
91
/* Set a charging mode for the android gadget
*
* @return 0 if successful, 1 on failure
*/
int set_android_charging_mode(void)
{
int ret = 0;
Aug 22, 2013
Aug 22, 2013
92
/* disable, set functions to "mass_storage", re-enable */
Aug 14, 2013
Aug 14, 2013
93
write_to_file("/sys/class/android_usb/android0/enable", "0");
Sep 11, 2013
Sep 11, 2013
94
write_to_file("/sys/class/android_usb/android0/idProduct", "0AFE"); /* TODO: make configurable */
Aug 22, 2013
Aug 22, 2013
95
write_to_file("/sys/class/android_usb/android0/functions", "mass_storage");
Aug 14, 2013
Aug 14, 2013
96
97
98
99
100
ret = write_to_file("/sys/class/android_usb/android0/enable", "1");
if(ret < 0)
return(1);
else
return(ret);
Aug 23, 2013
Aug 23, 2013
102
103
104
105
106
107
108
109
110
111
/* Set a product id for the android gadget
*
* @return 0 if successful, 1 on failure
*/
int set_android_productid(char *id)
{
int ret = 0;
/* disable, set functions to "mass_storage", re-enable */
Sep 19, 2013
Sep 19, 2013
112
ret = write_to_file("/sys/class/android_usb/android0/idProduct", id);
Aug 23, 2013
Aug 23, 2013
113
114
115
116
117
if(ret < 0)
return(1);
else
return(ret);
}