remove htc ril wrapper and add reference ril
This commit is contained in:
parent
6b39212ad0
commit
4451d92d32
2
leo.mk
2
leo.mk
@ -99,7 +99,7 @@ PRODUCT_PACKAGES += \
|
||||
gralloc.qsd8k \
|
||||
copybit.qsd8k \
|
||||
gps.leo \
|
||||
libhtc_ril_wrapper \
|
||||
leo-reference-ril \
|
||||
libOmxCore \
|
||||
libOmxVidEnc
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit 13ae855f761b0c15ad0633d9dba8a2167d841470
|
37
libreference-ril/Android.mk
Normal file
37
libreference-ril/Android.mk
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright 2006 The Android Open Source Project
|
||||
|
||||
# XXX using libutils for simulator build only...
|
||||
#
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
leoreference-ril.c \
|
||||
misc.c \
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libcutils libutils libril
|
||||
|
||||
# for asprinf
|
||||
LOCAL_CFLAGS := -D_GNU_SOURCE
|
||||
|
||||
LOCAL_PRELINK_MODULE := false
|
||||
LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
|
||||
|
||||
ifeq (foo,foo)
|
||||
#build shared library
|
||||
LOCAL_SHARED_LIBRARIES += \
|
||||
libcutils libutils libdl
|
||||
LOCAL_LDLIBS += -lpthread -ldl
|
||||
LOCAL_CFLAGS += -DRIL_SHLIB
|
||||
LOCAL_MODULE:= libleo-reference-ril
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
else
|
||||
#build executable
|
||||
LOCAL_SHARED_LIBRARIES += \
|
||||
libril libdl
|
||||
LOCAL_MODULE:= leo-reference-ril
|
||||
include $(BUILD_EXECUTABLE)
|
||||
endif
|
0
libreference-ril/MODULE_LICENSE_APACHE2
Normal file
0
libreference-ril/MODULE_LICENSE_APACHE2
Normal file
190
libreference-ril/NOTICE
Normal file
190
libreference-ril/NOTICE
Normal file
@ -0,0 +1,190 @@
|
||||
|
||||
Copyright (c) 2005-2008, The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
491
libreference-ril/leoreference-ril.c
Normal file
491
libreference-ril/leoreference-ril.c
Normal file
@ -0,0 +1,491 @@
|
||||
/* //device/system/reference-ril/reference-ril.c
|
||||
**
|
||||
** Copyright 2006, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
#include <telephony/ril.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <alloca.h>
|
||||
|
||||
#include "misc.h"
|
||||
#include <getopt.h>
|
||||
#include <sys/socket.h>
|
||||
#include <cutils/sockets.h>
|
||||
#include <termios.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#define LOG_TAG "RILW"
|
||||
|
||||
#define RIL_DEBUG 1
|
||||
|
||||
#if RIL_DEBUG
|
||||
# define D(...) LOGD(__VA_ARGS__)
|
||||
#else
|
||||
# define D(...) ((void)0)
|
||||
#endif
|
||||
|
||||
#define RIL_onRequestComplete(t, e, response, responselen) s_rilenv->OnRequestComplete(t,e, response, responselen)
|
||||
|
||||
#define PPP_TTY_PATH "/dev/ppp0"
|
||||
|
||||
#define AT_ERROR_GENERIC -1
|
||||
#define AT_ERROR_COMMAND_PENDING -2
|
||||
#define AT_ERROR_CHANNEL_CLOSED -3
|
||||
#define AT_ERROR_TIMEOUT -4
|
||||
#define AT_ERROR_INVALID_THREAD -5 /* AT commands may not be issued from
|
||||
reader thread (or unsolicited response
|
||||
callback */
|
||||
#define AT_ERROR_INVALID_RESPONSE -6 /* eg an at_send_command_singleline that
|
||||
did not get back an intermediate
|
||||
response */
|
||||
|
||||
void (*libhtc_ril_onRequest)(int request, void *data, size_t datalen, RIL_Token t);
|
||||
|
||||
static const char * s_device_path = NULL;
|
||||
static const struct RIL_Env *s_rilenv;
|
||||
static void *ril_handler=NULL;
|
||||
|
||||
static int s_fd = -1; /* fd of the AT channel */
|
||||
|
||||
static const char * getVersion(void) {
|
||||
return "android leo-reference-ril 1.0";
|
||||
}
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
void AT_DUMP(const char* prefix, const char* buff, int len) {
|
||||
if (len < 0)
|
||||
len = strlen(buff);
|
||||
D("%.*s", len, buff);
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
static int at_writeline (const char *s) {
|
||||
size_t cur = 0;
|
||||
size_t len = strlen(s);
|
||||
ssize_t written;
|
||||
|
||||
if (s_fd < 0 ) {
|
||||
return AT_ERROR_CHANNEL_CLOSED;
|
||||
}
|
||||
|
||||
AT_DUMP( ">> ", s, strlen(s) );
|
||||
|
||||
/* the main string */
|
||||
while (cur < len) {
|
||||
do {
|
||||
written = write (s_fd, s + cur, len - cur);
|
||||
} while (written < 0 && errno == EINTR);
|
||||
|
||||
if (written < 0) {
|
||||
return AT_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
cur += written;
|
||||
}
|
||||
|
||||
/* the \r */
|
||||
|
||||
do {
|
||||
written = write (s_fd, "\r" , 1);
|
||||
} while ((written < 0 && errno == EINTR) || (written == 0));
|
||||
|
||||
if (written < 0) {
|
||||
return AT_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
//D("AT> %s", "sent");
|
||||
|
||||
return 0;
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
static int at_command(char *cmd, int to)
|
||||
{
|
||||
fd_set rfds;
|
||||
struct timeval timeout;
|
||||
|
||||
char buf[1024];
|
||||
int sel, len, i, err;
|
||||
|
||||
err=at_writeline(cmd);
|
||||
if (err != 0 ) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
//read always failed, not sure why ?
|
||||
for (i = 0; i < 100; i++) {
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(s_fd, &rfds);
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = to;
|
||||
if ((sel = select(s_fd + 1, &rfds, NULL, NULL, &timeout)) > 0) {
|
||||
if (FD_ISSET(s_fd, &rfds)) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
len = read(s_fd, buf, sizeof(buf));
|
||||
if (len> 0) {
|
||||
D("%d: %s", len, buf);
|
||||
if (strstr(buf, "\r\nOK") != NULL){
|
||||
D(" > OK");
|
||||
break;
|
||||
}
|
||||
if (strstr(buf, "\r\nERROR") != NULL){
|
||||
D(" > ERROR");
|
||||
break;
|
||||
}
|
||||
if (strstr(buf, "\r\nCONNECT") != NULL){
|
||||
D(" > CONNECT");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
//LOGE("select %s: %s (%d)", s_device_path, strerror(errno), errno);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
static int open_modem() {
|
||||
struct termios ios;
|
||||
int fd;
|
||||
LOGI("Opening tty device %s", s_device_path);
|
||||
//
|
||||
// fd = open(s_device_path, O_RDWR | O_NONBLOCK);
|
||||
fd = open(s_device_path, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
LOGE("Can't open %s: %s (%d)", s_device_path, strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tcflush(fd, TCIOFLUSH);
|
||||
#if 0
|
||||
/* Switch tty to RAW mode */
|
||||
tcgetattr( fd, &ios );
|
||||
/* cfmakeraw(&ios); */
|
||||
ios.c_lflag = 0; /* disable ECHO, ICANON, etc... */
|
||||
tcsetattr(fd, TCSANOW, &ios);
|
||||
#endif
|
||||
|
||||
/* Switch tty to RAW mode */
|
||||
cfmakeraw(&ios);
|
||||
tcsetattr(fd, TCSANOW, &ios);
|
||||
|
||||
s_fd = fd;
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int close_modem() {
|
||||
if (s_fd >= 0) {
|
||||
close(s_fd);
|
||||
}
|
||||
LOGI("Closing tty device %s", s_device_path);
|
||||
s_fd = -1;
|
||||
return 0;
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
#if 0
|
||||
int open_modem () {
|
||||
int fd;
|
||||
int ret;
|
||||
struct termios ios;
|
||||
|
||||
fd = open (s_device_path, O_RDWR);
|
||||
if(fd == -1) {
|
||||
LOGE("Error opening %s", s_device_path);
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* disable echo on serial ports */
|
||||
tcgetattr( fd, &ios );
|
||||
ios.c_lflag = 0; /* disable ECHO, ICANON, etc... */
|
||||
tcsetattr( fd, TCSANOW, &ios );
|
||||
|
||||
s_fd = fd;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
static void requestRegistrationState(int request, void *data,
|
||||
size_t datalen, RIL_Token t) {
|
||||
|
||||
D("%s", __func__);
|
||||
if (request == RIL_REQUEST_REGISTRATION_STATE) {
|
||||
D("### RIL_REQUEST_REGISTRATION_STATE");
|
||||
} else if (request == RIL_REQUEST_GPRS_REGISTRATION_STATE) {
|
||||
D("### RIL_REQUEST_GPRS_REGISTRATION_STATE");
|
||||
}
|
||||
libhtc_ril_onRequest(request, data, datalen, t);
|
||||
|
||||
D("%s:%.*s", __func__ , datalen, (char *)data);
|
||||
return;
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
void requestDeactivateDataCall(void *data, size_t datalen, RIL_Token t)
|
||||
{
|
||||
int ret, err;
|
||||
char * cmd;
|
||||
char * cid;
|
||||
int fd;
|
||||
|
||||
open_modem();
|
||||
|
||||
cid = ((char **)data)[0];
|
||||
|
||||
D("%s, cid: %s", __func__, cid);
|
||||
|
||||
asprintf(&cmd, "AT+CGACT=0,%s", cid);
|
||||
err = at_command(cmd, 10000);
|
||||
free(cmd);
|
||||
|
||||
int i=0;
|
||||
i=0;
|
||||
while((fd = open("/etc/ppp/ppp0.pid",O_RDONLY)) > 0) {
|
||||
if(i%5 == 0) system("killall pppd");
|
||||
close(fd);
|
||||
if(i>25) goto error;
|
||||
i++;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
close_modem();
|
||||
|
||||
D("%s: RIL_E_SUCCESS ", __func__);
|
||||
RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
|
||||
return;
|
||||
|
||||
error:
|
||||
close_modem();
|
||||
LOGE("%s: GENERIC_FAILURE ", __func__);
|
||||
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
static void requestSetupDataCall(char **data, size_t datalen, RIL_Token t) {
|
||||
const char *apn;
|
||||
char *user = NULL;
|
||||
char *pass = NULL;
|
||||
char *cmd;
|
||||
char *userpass;
|
||||
int err;
|
||||
int fd;
|
||||
FILE *cfg;
|
||||
char *buffer;
|
||||
long buffSize, len;
|
||||
char *response[2] = { "1", "ppp0" };
|
||||
|
||||
int status;
|
||||
int ret;
|
||||
|
||||
D("%s", __func__);
|
||||
|
||||
/* check if /dev/ppp exists else pppd will be fail*/
|
||||
int fd_ppp = open ("/dev/ppp", O_RDWR);
|
||||
if (fd_ppp == -1) {
|
||||
system("mknod /dev/ppp c 108 0");
|
||||
fd_ppp = open ("/dev/ppp", O_RDWR);
|
||||
if (fd_ppp == -1) LOGE("Error opening /dev/ppp");
|
||||
}
|
||||
|
||||
open_modem();
|
||||
|
||||
apn = ((const char **)data)[2];
|
||||
user = ((char **)data)[3];
|
||||
pass = ((char **)data)[4];
|
||||
|
||||
D("requesting data connection to APN '%s'", apn);
|
||||
|
||||
/*at_command("ATZ", 10000);*/
|
||||
|
||||
//D("Setting up PDP Context");
|
||||
asprintf(&cmd, "AT+CGDCONT=1,\"IP\",\"%s\",,0,0", apn);
|
||||
//FIXME check for error here
|
||||
err = at_command(cmd, 10000);
|
||||
free(cmd);
|
||||
|
||||
// Set required QoS params to default
|
||||
err = at_command("AT+CGQREQ=1", 10000);
|
||||
|
||||
// Set minimum QoS params to default
|
||||
err = at_command("AT+CGQMIN=1", 10000);
|
||||
|
||||
// packet-domain event reporting
|
||||
err = at_command("AT+CGEREP=1,0", 10000);
|
||||
|
||||
//D("Activating PDP Context");
|
||||
// Hangup anything that's happening there now
|
||||
err = at_command("AT+CGACT=1,0", 10000);
|
||||
|
||||
//D("Start data on PDP context 1");
|
||||
err = at_command("ATD*99***1#", 10000);
|
||||
|
||||
//err = at_command("ATD*99#", 1);
|
||||
|
||||
asprintf(&userpass, "%s * %s", user, pass);
|
||||
len = strlen(userpass);
|
||||
fd = open("/etc/ppp/pap-secrets",O_WRONLY);
|
||||
if(fd < 0) {
|
||||
D("could not open /etc/ppp/pap-secrets");
|
||||
goto error;
|
||||
}
|
||||
write(fd, userpass, len);
|
||||
close(fd);
|
||||
|
||||
fd = open("/etc/ppp/chap-secrets",O_WRONLY);
|
||||
if(fd < 0) {
|
||||
D("could not open /etc/ppp/chap-secrets");
|
||||
goto error;
|
||||
}
|
||||
write(fd, userpass, len);
|
||||
close(fd);
|
||||
free(userpass);
|
||||
|
||||
cfg = fopen("/etc/ppp/options.smd","r");
|
||||
if(!cfg) {
|
||||
D("could not open /etc/ppp/options.smd");
|
||||
goto error;
|
||||
}
|
||||
|
||||
//filesize
|
||||
fseek(cfg, 0, SEEK_END);
|
||||
buffSize = ftell(cfg);
|
||||
rewind(cfg);
|
||||
|
||||
//allocate memory
|
||||
buffer = (char *) malloc (sizeof(char)*buffSize);
|
||||
if (buffer == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
//read in the original file
|
||||
len = fread (buffer,1,buffSize,cfg);
|
||||
if (len != buffSize) {
|
||||
D("could not set cfg");
|
||||
goto error;
|
||||
}
|
||||
fclose(cfg);
|
||||
|
||||
cfg = fopen("/etc/ppp/options.smd1","w");
|
||||
fwrite(buffer,1,buffSize,cfg);
|
||||
fprintf(cfg,"user %s",user);
|
||||
fclose(cfg);
|
||||
free(buffer);
|
||||
|
||||
status = system("/bin/pppd /dev/smd1 debug defaultroute");
|
||||
if (status == 0) {
|
||||
sleep(5); // allow time for ip-up to run
|
||||
/*system("/system/bin/log -t pppd -c1 www.google.com");*/
|
||||
} else {
|
||||
LOGE("/bin/pppd failed, status: %d", status);
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
inaddr_t addr,mask;
|
||||
unsigned int flags;
|
||||
ifc_init();
|
||||
ifc_get_info(PPP_TTY_PATH, &addr, &mask, &flags);
|
||||
ifc_close();
|
||||
*/
|
||||
|
||||
close_modem();
|
||||
D("%s: RIL_E_SUCCESS ", __func__);
|
||||
RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response));
|
||||
return;
|
||||
|
||||
error:
|
||||
close_modem();
|
||||
LOGE("%s: GENERIC_FAILURE ", __func__);
|
||||
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
void onRequest(int request, void *data, size_t datalen, RIL_Token t) {
|
||||
switch (request) {
|
||||
case RIL_REQUEST_SETUP_DATA_CALL:
|
||||
return requestSetupDataCall(data, datalen, t);
|
||||
case RIL_REQUEST_DEACTIVATE_DATA_CALL:
|
||||
return requestDeactivateDataCall(data, datalen, t);
|
||||
case RIL_REQUEST_REGISTRATION_STATE:
|
||||
case RIL_REQUEST_GPRS_REGISTRATION_STATE:
|
||||
return requestRegistrationState(request, data, datalen, t);
|
||||
default:
|
||||
return libhtc_ril_onRequest(request, data, datalen, t);
|
||||
}
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
static void usage(char *s)
|
||||
{
|
||||
#ifdef RIL_SHLIB
|
||||
fprintf(stderr, "leo-reference-ril requires: -p <tcp port> or -d /dev/tty_device");
|
||||
#else
|
||||
fprintf(stderr, "usage: %s [-p <tcp port>] [-d /dev/tty_device]", s);
|
||||
exit(-1);
|
||||
#endif
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
||||
const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv) {
|
||||
int ret;
|
||||
int fd = -1;
|
||||
int opt;
|
||||
|
||||
s_rilenv = env;
|
||||
|
||||
D("%s", __func__);
|
||||
|
||||
while ( -1 != (opt = getopt(argc, argv, "p:d:s:"))) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
s_device_path = optarg;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_device_path == NULL) {
|
||||
usage(argv[0]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ril_handler=dlopen("/system/lib/libhtc_ril.so", 0/*Need to RTFM, 0 seems fine*/);
|
||||
RIL_RadioFunctions* (*htc_ril)(const struct RIL_Env *env, int argc, char **argv);
|
||||
|
||||
htc_ril=dlsym(ril_handler, "RIL_Init");
|
||||
RIL_RadioFunctions *s_callbacks;
|
||||
s_callbacks=htc_ril(env, argc, argv);
|
||||
libhtc_ril_onRequest=s_callbacks->onRequest;
|
||||
s_callbacks->onRequest=onRequest;
|
||||
|
||||
return s_callbacks;
|
||||
}
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
|
29
libreference-ril/misc.c
Normal file
29
libreference-ril/misc.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* //device/system/reference-ril/misc.c
|
||||
**
|
||||
** Copyright 2006, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
/** returns 1 if line starts with prefix, 0 if it does not */
|
||||
int strStartsWith(const char *line, const char *prefix)
|
||||
{
|
||||
for ( ; *line != '\0' && *prefix != '\0' ; line++, prefix++) {
|
||||
if (*line != *prefix) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return *prefix == '\0';
|
||||
}
|
||||
|
19
libreference-ril/misc.h
Normal file
19
libreference-ril/misc.h
Normal file
@ -0,0 +1,19 @@
|
||||
/* //device/system/reference-ril/misc.h
|
||||
**
|
||||
** Copyright 2006, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
/** returns 1 if line starts with prefix, 0 if it does not */
|
||||
int strStartsWith(const char *line, const char *prefix);
|
Loading…
Reference in New Issue
Block a user