San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include <errno.h> |
| 17 | |
| 18 | #include <sys/types.h> |
| 19 | #include <sys/socket.h> |
Nick Kralevich | 6bc0828 | 2011-04-18 15:55:59 -0700 | [diff] [blame] | 20 | #include <linux/netlink.h> |
San Mehat | 3d40729 | 2009-05-07 08:49:30 -0700 | [diff] [blame] | 21 | #include <string.h> |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 22 | |
| 23 | #define LOG_TAG "NetlinkListener" |
| 24 | #include <cutils/log.h> |
Nick Kralevich | 531312e | 2011-04-29 16:49:22 -0700 | [diff] [blame] | 25 | #include <cutils/uevent.h> |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 26 | |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 27 | #include <sysutils/NetlinkEvent.h> |
| 28 | |
Mike J. Chen | 2a56688 | 2011-06-23 15:04:32 -0700 | [diff] [blame] | 29 | #if 1 |
| 30 | /* temporary version until we can get Motorola to update their |
| 31 | * ril.so. Their prebuilt ril.so is using this private class |
| 32 | * so changing the NetlinkListener() constructor breaks their ril. |
| 33 | */ |
| 34 | NetlinkListener::NetlinkListener(int socket) : |
| 35 | SocketListener(socket, false) { |
| 36 | mFormat = NETLINK_FORMAT_ASCII; |
| 37 | } |
| 38 | #endif |
| 39 | |
Mike J. Chen | ec16b9d | 2011-06-23 14:55:28 -0700 | [diff] [blame] | 40 | NetlinkListener::NetlinkListener(int socket, int format) : |
Mike J. Chen | 17260b1 | 2011-06-23 15:00:30 -0700 | [diff] [blame] | 41 | SocketListener(socket, false), mFormat(format) { |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 42 | } |
| 43 | |
San Mehat | fa644ff | 2009-05-08 11:15:53 -0700 | [diff] [blame] | 44 | bool NetlinkListener::onDataAvailable(SocketClient *cli) |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 45 | { |
San Mehat | fa644ff | 2009-05-08 11:15:53 -0700 | [diff] [blame] | 46 | int socket = cli->getSocket(); |
Nick Kralevich | 6bc0828 | 2011-04-18 15:55:59 -0700 | [diff] [blame] | 47 | ssize_t count; |
Geremy Condra | d98533a | 2012-03-29 15:44:06 -0700 | [diff] [blame] | 48 | uid_t uid = -1; |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 49 | |
Geremy Condra | d98533a | 2012-03-29 15:44:06 -0700 | [diff] [blame] | 50 | count = TEMP_FAILURE_RETRY(uevent_kernel_multicast_uid_recv( |
| 51 | socket, mBuffer, sizeof(mBuffer), &uid)); |
David 'Digit' Turner | b59539d | 2011-01-17 02:04:37 +0100 | [diff] [blame] | 52 | if (count < 0) { |
Geremy Condra | d98533a | 2012-03-29 15:44:06 -0700 | [diff] [blame] | 53 | if (uid > 0) |
| 54 | LOG_EVENT_INT(65537, uid); |
Nick Kralevich | 6bc0828 | 2011-04-18 15:55:59 -0700 | [diff] [blame] | 55 | SLOGE("recvmsg failed (%s)", strerror(errno)); |
| 56 | return false; |
| 57 | } |
| 58 | |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 59 | NetlinkEvent *evt = new NetlinkEvent(); |
Mike J. Chen | 17260b1 | 2011-06-23 15:00:30 -0700 | [diff] [blame] | 60 | if (!evt->decode(mBuffer, count, mFormat)) { |
San Mehat | 7e8529a | 2010-03-25 09:31:42 -0700 | [diff] [blame] | 61 | SLOGE("Error decoding NetlinkEvent"); |
Mike J. Chen | ec16b9d | 2011-06-23 14:55:28 -0700 | [diff] [blame] | 62 | } else { |
| 63 | onEvent(evt); |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 64 | } |
| 65 | |
San Mehat | 168415b | 2009-05-06 11:14:21 -0700 | [diff] [blame] | 66 | delete evt; |
| 67 | return true; |
| 68 | } |