Karthikeyan Ramasubramanian | 6a116d6 | 2016-09-16 16:05:32 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2012-2014,2016 The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _IPC_ROUTER_SECURITY_H |
| 14 | #define _IPC_ROUTER_SECURITY_H |
| 15 | |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/socket.h> |
| 18 | #include <linux/errno.h> |
| 19 | |
| 20 | #ifdef CONFIG_IPC_ROUTER_SECURITY |
| 21 | #include <linux/android_aid.h> |
| 22 | |
| 23 | /** |
| 24 | * check_permisions() - Check whether the process has permissions to |
| 25 | * create an interface handle with IPC Router |
| 26 | * |
| 27 | * @return: true if the process has permissions, else false. |
| 28 | */ |
| 29 | int check_permissions(void); |
| 30 | |
| 31 | /** |
| 32 | * msm_ipc_config_sec_rules() - Add a security rule to the database |
| 33 | * @arg: Pointer to the buffer containing the rule. |
| 34 | * |
| 35 | * @return: 0 if successfully added, < 0 for error. |
| 36 | * |
| 37 | * A security rule is defined using <Service_ID: Group_ID> tuple. The rule |
| 38 | * implies that a user-space process in order to send a QMI message to |
| 39 | * service Service_ID should belong to the Linux group Group_ID. |
| 40 | */ |
| 41 | int msm_ipc_config_sec_rules(void *arg); |
| 42 | |
| 43 | /** |
| 44 | * msm_ipc_get_security_rule() - Get the security rule corresponding to a |
| 45 | * service |
| 46 | * @service_id: Service ID for which the rule has to be got. |
| 47 | * @instance_id: Instance ID for which the rule has to be got. |
| 48 | * |
| 49 | * @return: Returns the rule info on success, NULL on error. |
| 50 | * |
| 51 | * This function is used when the service comes up and gets registered with |
| 52 | * the IPC Router. |
| 53 | */ |
| 54 | void *msm_ipc_get_security_rule(u32 service_id, u32 instance_id); |
| 55 | |
| 56 | /** |
| 57 | * msm_ipc_check_send_permissions() - Check if the sendng process has |
| 58 | * permissions specified as per the rule |
| 59 | * @data: Security rule to be checked. |
| 60 | * |
| 61 | * @return: true if the process has permissions, else false. |
| 62 | * |
| 63 | * This function is used to check if the current executing process has |
| 64 | * permissions to send message to the remote entity. The security rule |
| 65 | * corresponding to the remote entity is specified by "data" parameter |
| 66 | */ |
| 67 | int msm_ipc_check_send_permissions(void *data); |
| 68 | |
| 69 | /** |
| 70 | * msm_ipc_router_security_init() - Initialize the security rule database |
| 71 | * |
| 72 | * @return: 0 if successful, < 0 for error. |
| 73 | */ |
| 74 | int msm_ipc_router_security_init(void); |
| 75 | |
| 76 | /** |
| 77 | * wait_for_irsc_completion() - Wait for IPC Router Security Configuration |
| 78 | * (IRSC) to complete |
| 79 | */ |
| 80 | void wait_for_irsc_completion(void); |
| 81 | |
| 82 | /** |
| 83 | * signal_irsc_completion() - Signal the completion of IRSC |
| 84 | */ |
| 85 | void signal_irsc_completion(void); |
| 86 | |
| 87 | #else |
| 88 | |
| 89 | static inline int check_permissions(void) |
| 90 | { |
| 91 | return 1; |
| 92 | } |
| 93 | |
| 94 | static inline int msm_ipc_config_sec_rules(void *arg) |
| 95 | { |
| 96 | return -ENODEV; |
| 97 | } |
| 98 | |
| 99 | static inline void *msm_ipc_get_security_rule(u32 service_id, |
| 100 | u32 instance_id) |
| 101 | { |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | static inline int msm_ipc_check_send_permissions(void *data) |
| 106 | { |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | static inline int msm_ipc_router_security_init(void) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static inline void wait_for_irsc_completion(void) { } |
| 116 | |
| 117 | static inline void signal_irsc_completion(void) { } |
| 118 | |
| 119 | #endif |
| 120 | #endif |