diff options
author | Paul Kocialkowski <contact@paulk.fr> | 2012-10-01 20:48:16 +0200 |
---|---|---|
committer | Paul Kocialkowski <contact@paulk.fr> | 2012-10-01 20:48:16 +0200 |
commit | 5b1434f5eedc49aa6dec223cc36492aff4e0b4ce (patch) | |
tree | ffd56c8e9dad7f65040ea51ab3bb58219aa57e5b | |
parent | 72003a4010528070591617a082460e61eb4d2010 (diff) | |
download | device_samsung_crespo-5b1434f5eedc49aa6dec223cc36492aff4e0b4ce.tar.gz device_samsung_crespo-5b1434f5eedc49aa6dec223cc36492aff4e0b4ce.tar.bz2 device_samsung_crespo-5b1434f5eedc49aa6dec223cc36492aff4e0b4ce.zip |
Switch to Samsung-RIL and Samsung-RIL-Client
Change-Id: Ie13359e9d69e597d72b429f38b102cde8fa24126
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r-- | device_base.mk | 5 | ||||
-rw-r--r-- | libaudio/AudioHardware.cpp | 8 | ||||
-rw-r--r-- | samsung-ril-client/Android.mk | 18 | ||||
-rw-r--r-- | samsung-ril-client/samsung-ril-client.c | 313 | ||||
-rw-r--r-- | system.prop | 2 |
5 files changed, 341 insertions, 5 deletions
diff --git a/device_base.mk b/device_base.mk index 45e6adb..8128886 100644 --- a/device_base.mk +++ b/device_base.mk @@ -161,6 +161,11 @@ PRODUCT_PACKAGES += \ libstagefrighthw \ com.android.future.usb.accessory +# RIL/RIL client/libsamsung-ipc +PRODUCT_PACKAGES += libsamsung-ril \ + libsamsung-ril-client \ + ipc-modemctrl + # Input device calibration files PRODUCT_COPY_FILES += \ device/samsung/crespo/mxt224_ts_input.idc:system/usr/idc/mxt224_ts_input.idc diff --git a/libaudio/AudioHardware.cpp b/libaudio/AudioHardware.cpp index a189510..e501463 100644 --- a/libaudio/AudioHardware.cpp +++ b/libaudio/AudioHardware.cpp @@ -145,10 +145,10 @@ status_t AudioHardware::initCheck() void AudioHardware::loadRILD(void) { - mSecRilLibHandle = dlopen("libsecril-client.so", RTLD_NOW); + mSecRilLibHandle = dlopen("libsamsung-ril-client.so", RTLD_NOW); if (mSecRilLibHandle) { - LOGV("libsecril-client.so is loaded"); + LOGV("libsamsung-ril-client.so is loaded"); openClientRILD = (HRilClient (*)(void)) dlsym(mSecRilLibHandle, "OpenClient_RILD"); @@ -170,7 +170,7 @@ void AudioHardware::loadRILD(void) if (!openClientRILD || !disconnectRILD || !closeClientRILD || !isConnectedRILD || !connectRILD || !setCallVolume || !setCallAudioPath || !setCallClockSync) { - LOGE("Can't load all functions from libsecril-client.so"); + LOGE("Can't load all functions from libsamsung-ril-client.so"); dlclose(mSecRilLibHandle); mSecRilLibHandle = NULL; @@ -184,7 +184,7 @@ void AudioHardware::loadRILD(void) } } } else { - LOGE("Can't load libsecril-client.so"); + LOGE("Can't load libsamsung-ril-client.so"); } } diff --git a/samsung-ril-client/Android.mk b/samsung-ril-client/Android.mk new file mode 100644 index 0000000..b1050e7 --- /dev/null +++ b/samsung-ril-client/Android.mk @@ -0,0 +1,18 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := libsamsung-ril-client +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := samsung-ril-client.c + +LOCAL_SHARED_LIBRARIES := liblog libcutils +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES) +LOCAL_C_INCLUDES := $(LOCAL_PATH) +LOCAL_C_INCLUDES += hardware/ril/samsung-ril/include \ + device/samsung/crespo/libaudio/ + +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) diff --git a/samsung-ril-client/samsung-ril-client.c b/samsung-ril-client/samsung-ril-client.c new file mode 100644 index 0000000..fa0d146 --- /dev/null +++ b/samsung-ril-client/samsung-ril-client.c @@ -0,0 +1,313 @@ +/** + * Samsung RIL Client (Samsung RIL Socket Client-side implementation) + * + * Copyright (C) 2011 Paul Kocialkowski <contact@paulk.fr> + * + * samsung-ril-client is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * samsung-ril-client 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 GNU General Public License + * along with samsung-ril-client. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> + +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/select.h> + +#include <signal.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#include <cutils/sockets.h> + +#define LOG_TAG "SRS-Client" +#include <cutils/log.h> + +#include <secril-client.h> +#include <samsung-ril-socket.h> + +int srs_send_message(HRilClient client, struct srs_message *message) +{ + int client_fd = *((int *) client->prv); + fd_set fds; + + struct srs_header header; + void *data; + + int rc; + + header.length = message->data_len + sizeof(header); + header.group = SRS_GROUP(message->command); + header.index = SRS_INDEX(message->command); + + data = malloc(header.length); + memset(data, 0, header.length); + + memcpy(data, &header, sizeof(header)); + memcpy((void *) (data + sizeof(header)), message->data, message->data_len); + + FD_ZERO(&fds); + FD_SET(client_fd, &fds); + + // We can't rely on select RC + select(client_fd + 1, NULL, &fds, NULL, NULL); + + rc = write(client_fd, data, header.length); + + free(data); + + return rc; +} + +int srs_send(HRilClient client, unsigned short command, void *data, int data_len) +{ + struct srs_message message; + int rc; + + LOGE("%s", __func__); + + message.command = command; + message.data = data; + message.data_len = data_len; + + rc = srs_send_message(client, &message); + + return rc; +} + +int srs_recv_timed(HRilClient client, struct srs_message *message, long sec, long usec) +{ + void *raw_data = malloc(SRS_DATA_MAX_SIZE); + struct srs_header *header; + int rc; + + int client_fd = *((int *) client->prv); + struct timeval timeout; + fd_set fds; + + FD_ZERO(&fds); + FD_SET(client_fd, &fds); + + timeout.tv_sec = sec; + timeout.tv_usec = usec; + + select(client_fd + 1, &fds, NULL, NULL, &timeout); + + rc = read(client_fd, raw_data, SRS_DATA_MAX_SIZE); + if(rc < sizeof(struct srs_header)) { + return -1; + } + + header = raw_data; + + message->command = SRS_COMMAND(header); + message->data_len = header->length - sizeof(struct srs_header); + message->data = malloc(message->data_len); + + memcpy(message->data, raw_data + sizeof(struct srs_header), message->data_len); + + free(raw_data); + + return 0; +} + +int srs_recv(HRilClient client, struct srs_message *message) +{ + return srs_recv_timed(client, message, 0, 0); +} + +int srs_ping(HRilClient client) +{ + int caffe_w = SRS_CONTROL_CAFFE; + int caffe_r = 0; + int rc = 0; + + struct srs_message message; + + rc = srs_send(client, SRS_CONTROL_PING, &caffe_w, sizeof(caffe_w)); + + if(rc < 0) { + return -1; + } + + rc = srs_recv_timed(client, &message, 0, 300); + + if(rc < 0) { + return -1; + } + + if(message.data == NULL) + return -1; + + caffe_r = *((int *) message.data); + + if(caffe_r == SRS_CONTROL_CAFFE) { + LOGD("Caffe is ready!"); + rc = 0; + } else { + LOGE("Caffe went wrong!"); + rc = -1; + } + + free(message.data); + return rc; +} + +HRilClient OpenClient_RILD(void) +{ + HRilClient client; + int *client_fd_p = NULL; + + LOGE("%s", __func__); + + signal(SIGPIPE, SIG_IGN); + + client = malloc(sizeof(struct RilClient)); + client->prv = malloc(sizeof(int)); + client_fd_p = (int *) client->prv; + *client_fd_p = -1; + + return client; +} + +int Connect_RILD(HRilClient client) +{ + int t = 0; + int fd = -1; + int rc; + int *client_fd_p = (int *) client->prv; + + LOGE("%s", __func__); + +socket_connect: + while(t < 5) { + fd = socket_local_client(SRS_SOCKET_NAME, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); + + if(fd > 0) + break; + + LOGE("Socket creation to RIL failed: trying another time"); + + t++; + usleep(300); + } + + if(fd < 0) { + LOGE("Socket creation to RIL failed too many times"); + return RIL_CLIENT_ERR_CONNECT; + } + + *client_fd_p = fd; + + LOGE("Socket creation done, sending ping"); + + rc = srs_ping(client); + + if(rc < 0) { + LOGE("Ping failed!"); + goto socket_connect; + } else { + LOGD("Ping went alright"); + } + + return RIL_CLIENT_ERR_SUCCESS; +} + +int Disconnect_RILD(HRilClient client) +{ + int client_fd = *((int *) client->prv); + + LOGE("%s", __func__); + + close(client_fd); + + return RIL_CLIENT_ERR_SUCCESS; +} + +int CloseClient_RILD(HRilClient client) +{ + int *client_fd_p = (int *) client->prv; + + LOGE("%s", __func__); + + if(client_fd_p != NULL) + free(client_fd_p); + + free(client); + + return RIL_CLIENT_ERR_SUCCESS; +} + +int isConnected_RILD(HRilClient client) +{ + int client_fd = *((int *) client->prv); + int rc; + + LOGE("%s", __func__); + + if(client_fd < 0) { + return 0; + } + + rc = srs_ping(client); + + if(rc < 0) { + LOGE("Ping failed!"); + close(client_fd); + + return 0; + } else { + LOGD("Ping went alright"); + } + + return 1; +} + +int SetCallVolume(HRilClient client, SoundType type, int vol_level) +{ + struct srs_snd_call_volume call_volume; + + LOGD("Asking call volume"); + + call_volume.type = (enum srs_snd_type) type; + call_volume.volume = vol_level; + + srs_send(client, SRS_SND_SET_CALL_VOLUME, (void *) &call_volume, sizeof(call_volume)); + + return RIL_CLIENT_ERR_SUCCESS; +} + + +int SetCallAudioPath(HRilClient client, AudioPath path) +{ + srs_send(client, SRS_SND_SET_CALL_AUDIO_PATH, (void *) &path, sizeof(enum srs_snd_path)); + + LOGD("Asking audio path"); + + return RIL_CLIENT_ERR_SUCCESS; +} + +int SetCallClockSync(HRilClient client, SoundClockCondition condition) +{ + unsigned char data = condition; + + LOGD("Asking clock sync"); + + srs_send(client, SRS_SND_SET_CALL_CLOCK_SYNC, &data, sizeof(data)); + + return RIL_CLIENT_ERR_SUCCESS; +} diff --git a/system.prop b/system.prop index c445964..6c34c3f 100644 --- a/system.prop +++ b/system.prop @@ -2,6 +2,6 @@ # system.prop for smdkc110 # -rild.libpath=/vendor/lib/libsec-ril.so +rild.libpath=/system/lib/libsamsung-ril.so rild.libargs=-d /dev/ttyS0 ro.sf.lcd_density=240 |