• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 
17 // IWYU pragma: private, include "chre_api/chre.h"
18 // IWYU pragma: friend chre/.*\.h
19 
20 #ifndef _CHRE_MSG_H_
21 #define _CHRE_MSG_H_
22 
23 /**
24  * @file
25  * Context Hub Runtime Environment API for session-based messaging with generic
26  * endpoints.
27  *
28  * Key concepts:
29  * - **Endpoint**: an entity in the system that can send and receive messages.
30  *   Example endpoints include nanoapps, other offload components outside of
31  *   CHRE, privileged Android applications or Android system components
32  *   (registered via the ContextHubManager.registerEndpoint() API), vendor
33  *   processes (e.g. HALs) registered with the Context Hub HAL, etc.
34  * - **Message**: a datagram sent over a session.
35  * - **Session**: an active connection between two endpoints, optionally scoped
36  *   to a specific service. All messages must be sent over an established
37  *   session. A session will be automatically closed if sending a message fails
38  *   or the remote endpoint otherwise disconnects.
39  * - **Service**: a defined interface and wire format associated with some
40  *   functionality. Endpoints can choose to not register any services, for
41  *   example in cases where the endpoint only functions as a client, or if its
42  *   interface is implied and internal (e.g. a nanoapp that is tightly coupled
43  *   with its host-side code). Endpoints may also register 1 or more services,
44  *   and multiple endpoints may register the same service. This enables
45  *   abstraction between the interface/functionality and the entity/endpoint
46  *   that implements it.
47  *
48  * This API provides a single interface for nanoapps to communicate with other
49  * parts of the system, regardless of location.  Nanoapps should use these APIs
50  * rather than chreSendEvent(), chreSendMessageToHostEndpoint(), and related
51  * APIs if they do not need to support Android versions prior to Android 16 nor
52  * CHRE APIs older than v1.11.
53  *
54  * The general order of API usage as a client (session initiator) is:
55  *
56  * 1. The nanoapp should know the target service and/or endpoint ID it wants to
57  *    interact with, and optionally the target hub ID, and provide this to
58  *    chreMsgConfigureEndpointReadyEvents() or
59  *    chreMsgConfigureServiceReadyEvents().
60  * 2. The nanoapp will receive an event when a suitable endpoint is found. The
61  *    nanoapp then calls chreMsgSessionOpenAsync() to initiate communication.
62  * 3. Once the session is established, the nanoapp receives a
63  *    CHRE_EVENT_MSG_SESSION_OPENED event. If a failure occurred or the target
64  *    endpoint did not accept the session, a CHRE_EVENT_MSG_SESSION_CLOSED event
65  *    will be provided instead.
66  * 4. Assuming the session was opened successfully, the nanoapp can now send
67  *    messages over the session using chreMsgSend() and will receive messages
68  *    via CHRE_EVENT_MSG_FROM_ENDPOINT.
69  * 5. The session may be left open indefinitely, or closed by either endpoint,
70  *    or by the system on error or if one endpoint crashes/disconnects. If the
71  *    target endpoint crashes and then recovers, a new ready event will be
72  *    generated and communication can resume at step 2.
73  *
74  * As a server (session responder), the high-level flow is:
75  *
76  * 1. (Optional) Register one or more services via chreMsgPublishServices().
77  * 2. The nanoapp receives CHRE_EVENT_MSG_SESSION_OPENED when another endpoint
78  *    initiates a session. The session can either be used immediately, or the
79  *    nanoapp can use chreMsgSessionCloseAsync() to reject the session.
80  * 3. Once a session is established, it functions the same regardless of which
81  *    endpoint initiated the session.
82  *
83  * @since v1.11
84  */
85 
86 #include <stdbool.h>
87 #include <stddef.h>
88 #include <stdint.h>
89 #include <stdlib.h>
90 
91 #include <chre/common.h>
92 #include <chre/event.h>
93 #include <chre/toolchain.h>
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 
99 /**
100  * The type of endpoint.
101  * Backing type: uint32_t.
102  */
103 enum chreMsgEndpointType {
104   CHRE_MSG_ENDPOINT_TYPE_INVALID = 0,
105   CHRE_MSG_ENDPOINT_TYPE_HOST_FRAMEWORK = 1,
106   CHRE_MSG_ENDPOINT_TYPE_HOST_APP = 2,
107   CHRE_MSG_ENDPOINT_TYPE_HOST_NATIVE = 3,
108   CHRE_MSG_ENDPOINT_TYPE_NANOAPP = 4,
109   CHRE_MSG_ENDPOINT_TYPE_GENERIC = 5,
110 };
111 
112 /**
113  * The service RPC format.
114  * Backing type: uint32_t.
115  */
116 enum chreMsgEndpointServiceFormat {
117   CHRE_MSG_ENDPOINT_SERVICE_FORMAT_INVALID = 0,
118   CHRE_MSG_ENDPOINT_SERVICE_FORMAT_CUSTOM = 1,
119   CHRE_MSG_ENDPOINT_SERVICE_FORMAT_AIDL = 2,
120   CHRE_MSG_ENDPOINT_SERVICE_FORMAT_PW_RPC_PROTOBUF = 3,
121 };
122 
123 /**
124  * The reason for a session closure event or an endpoint notification
125  * event.
126  * Backing type: uint8_t.
127  */
128 enum chreMsgEndpointReason {
129   CHRE_MSG_ENDPOINT_REASON_UNSPECIFIED = 0,
130   CHRE_MSG_ENDPOINT_REASON_OUT_OF_MEMORY = 1,
131   CHRE_MSG_ENDPOINT_REASON_TIMEOUT = 2,
132   CHRE_MSG_ENDPOINT_REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED = 3,
133   CHRE_MSG_ENDPOINT_REASON_CLOSE_ENDPOINT_SESSION_REQUESTED = 4,
134   CHRE_MSG_ENDPOINT_REASON_ENDPOINT_INVALID = 5,
135   CHRE_MSG_ENDPOINT_REASON_ENDPOINT_GONE = 6,
136   CHRE_MSG_ENDPOINT_REASON_ENDPOINT_CRASHED = 7,
137   CHRE_MSG_ENDPOINT_REASON_HUB_RESET = 8,
138   CHRE_MSG_ENDPOINT_REASON_PERMISSION_DENIED = 9,
139 };
140 
141 /**
142  * The message hub ID reserved for the Android framework (Context Hub Service).
143  */
144 #define CHRE_MSG_HUB_ID_ANDROID UINT64_C(0x416E64726F696400)
145 
146 #define CHRE_MSG_HUB_ID_INVALID UINT64_C(0)
147 #define CHRE_MSG_HUB_ID_RESERVED UINT64_C(-1)
148 #define CHRE_MSG_ENDPOINT_ID_INVALID UINT64_C(0)
149 #define CHRE_MSG_ENDPOINT_ID_RESERVED UINT64_C(-1)
150 #define CHRE_MSG_SESSION_ID_INVALID UINT16_MAX
151 
152 /**
153  * Wildcard hub ID for use with chreMsgConfigureEndpointReadyEvents() and
154  * chreMsgConfigureServiceReadyEvents().
155  */
156 #define CHRE_MSG_HUB_ID_ANY CHRE_MSG_HUB_ID_INVALID
157 
158 /**
159  * Wildcard endpoint ID for use with chreMsgConfigureEndpointReadyEvents() and
160  * chreMsgSessionOpenAsync().
161  */
162 #define CHRE_MSG_ENDPOINT_ID_ANY CHRE_MSG_ENDPOINT_ID_INVALID
163 
164 /**
165  * The maximum length of an endpoint's name.
166  */
167 #define CHRE_MSG_MAX_NAME_LEN (51)
168 
169 /**
170  * The maximum length of a service descriptor (including null terminator).
171  */
172 #define CHRE_MSG_MAX_SERVICE_DESCRIPTOR_LEN (128)
173 
174 /**
175  * @see chreMsgPublishServices
176  */
177 #define CHRE_MSG_MINIMUM_SERVICE_LIMIT UINT8_C(4)
178 
179 /**
180  * Produce an event ID in the block of IDs reserved for session-based messaging.
181  *
182  * Valid input range is [0, 15]. Do not add new events with ID > 15
183  * (see chre/event.h)
184  *
185  * @param offset Index into MSG event ID block; valid range is [0, 15].
186  *
187  * @defgroup CHRE_MSG_EVENT_ID
188  * @{
189  */
190 #define CHRE_MSG_EVENT_ID(offset) (CHRE_EVENT_MSG_FIRST_EVENT + (offset))
191 
192 /**
193  * nanoappHandleEvent argument: struct chreMsgMessageFromEndpointData
194  *
195  * The format of the 'message' part of this structure is left undefined,
196  * and it's up to the nanoapp and endpoint to have an established protocol
197  * beforehand.
198  *
199  * On receiving the first message from an endpoint, the nanoapp can assume
200  * a session with the sessionId has been created and can be used to send
201  * messages to the endpoint. The nanoapp will receive a
202  * CHRE_EVENT_MSG_SESSION_CLOSED event when the session is closed.
203  *
204  * @since v1.11
205  */
206 #define CHRE_EVENT_MSG_FROM_ENDPOINT CHRE_MSG_EVENT_ID(0)
207 
208 /**
209  * nanoappHandleEvent argument: struct chreMsgSessionInfo
210  *
211  * Indicates that a session with an endpoint has been opened.
212  *
213  * @since v1.11
214  */
215 #define CHRE_EVENT_MSG_SESSION_OPENED CHRE_MSG_EVENT_ID(1)
216 
217 /**
218  * nanoappHandleEvent argument: struct chreMsgSessionInfo
219  *
220  * Indicates that a session with an endpoint has been closed.
221  *
222  * @since v1.11
223  */
224 #define CHRE_EVENT_MSG_SESSION_CLOSED CHRE_MSG_EVENT_ID(2)
225 
226 /**
227  * nanoappHandleEvent argument: struct chreMsgEndpointReadyEvent
228  *
229  * Notifications event regarding a generic endpoint.
230  *
231  * @see chreConfigureEndpointNotifications
232  * @since v1.11
233  */
234 #define CHRE_EVENT_MSG_ENDPOINT_READY CHRE_MSG_EVENT_ID(3)
235 
236 /**
237  * nanoappHandleEvent argument: struct chreMsgServiceReadyEvent
238  *
239  * Notifications event regarding a generic endpoint with a service.
240  *
241  * @see chreConfigureEndpointServiceNotifications
242  * @since v1.11
243  */
244 #define CHRE_EVENT_MSG_SERVICE_READY CHRE_MSG_EVENT_ID(4)
245 
246 // NOTE: Do not add new events with ID > 15
247 /** @} */
248 
249 /**
250  * Provides metadata for an endpoint.
251  */
252 struct chreMsgEndpointInfo {
253   /**
254    * The message hub ID and endpoint ID of the endpoint.
255    */
256   uint64_t hubId;
257   uint64_t endpointId;
258 
259   /**
260    * The type of the endpoint. One of chreMsgEndpointType enum values.
261    */
262   uint32_t type;
263 
264   /**
265    * The version of the endpoint.
266    */
267   uint32_t version;
268 
269   /**
270    * The required permissions of the endpoint, a bitmask of
271    * CHRE_MESSAGE_PERMISSION_* values.
272    */
273   uint32_t requiredPermissions;
274 
275   /**
276    * The maximum size of a message that can be sent to the endpoint.
277    *
278    * For endpoints on CHRE_MSG_HUB_ID_ANDROID, this is the same as
279    * chreGetMessageToHostMaxSize().
280    */
281   uint32_t maxMessageSize;
282 
283   /**
284    * The name of the endpoint, an ASCII null-terminated string. This name is
285    * specified by the endpoint when it is registered by its message hub.
286    */
287   char name[CHRE_MSG_MAX_NAME_LEN];
288 };
289 
290 /**
291  * Provides metadata for an endpoint service.
292  */
293 struct chreMsgServiceInfo {
294   /**
295    * The major version of the service.
296    */
297   uint32_t majorVersion;
298 
299   /**
300    * The minor version of the service.
301    */
302   uint32_t minorVersion;
303 
304   /**
305    * The descriptor of the service, an ASCII null-terminated string. This must
306    * be valid for the lifetime of the nanoapp.
307    */
308   const char *serviceDescriptor;
309 
310   /**
311    * The format of the service. One of chreMsgEndpointServiceFormat enum values.
312    */
313   uint32_t serviceFormat;
314 };
315 
316 /**
317  * Data provided with CHRE_EVENT_MSG_SESSION_OPENED,
318  * CHRE_EVENT_MSG_SESSION_CLOSED or chreGetSessionInfo().
319  */
320 struct chreMsgSessionInfo {
321   /**
322    * The message hub ID and endpoint ID of the other party in the session.
323    */
324   uint64_t hubId;
325   uint64_t endpointId;
326 
327   /**
328    * The descriptor of the service, an ASCII null-terminated string. This
329    * will be an empty string if the session was not opened with a service.
330    */
331   char serviceDescriptor[CHRE_MSG_MAX_SERVICE_DESCRIPTOR_LEN];
332 
333   /**
334    * The ID of the session.
335    */
336   uint16_t sessionId;
337 
338   /**
339    * The reason for the event. Used for sessions closure. For all other uses,
340    * this value will be CHRE_MSG_ENDPOINT_REASON_UNSPECIFIED. One of
341    * chreMsgEndpointReason enum values.
342    */
343   uint8_t reason;
344 };
345 
346 /**
347  * Data provided with CHRE_EVENT_MSG_FROM_ENDPOINT.
348  */
349 struct chreMsgMessageFromEndpointData {
350   /**
351    * Message type supplied by the endpoint.
352    */
353   uint32_t messageType;
354 
355   /**
356    * Message permissions supplied by the endpoint. The format is specified by
357    * the CHRE_MESSAGE_PERMISSION_* values if the endpoint is a nanoapp, else
358    * it is specified by the endpoint. These permissions are enforced by CHRE.
359    * A nanoapp without the required permissions will not receive the message.
360    */
361   uint32_t messagePermissions;
362 
363   /**
364    * The message from the endpoint.
365    *
366    * These contents are of a format that the endpoint and nanoapp must have
367    * established beforehand.
368    *
369    * This data is 'messageSize' bytes in length.  Note that if 'messageSize'
370    * is 0, this might contain NULL.
371    */
372   const void *message;
373 
374   /**
375    * The size, in bytes of the following 'message'.
376    *
377    * This can be 0.
378    */
379   size_t messageSize;
380 
381   /**
382    * The session ID of the message. A session is the active connection between
383    * two endpoints. The receiving nanoapp or endpoint initiated the session
384    * before sending this message. If the nanoapp has not yet received a
385    * message with this session ID, it can assume the session was created by
386    * the nanoapp or other endpoint. The nanoapp may send messages to the other
387    * endpoint with this session ID.
388    */
389   uint16_t sessionId;
390 };
391 
392 /**
393  * Data provided in CHRE_EVENT_MSG_ENDPOINT_READY.
394  */
395 struct chreMsgEndpointReadyEvent {
396   /**
397    * The message hub ID and endpoint ID of the endpoint.
398    */
399   uint64_t hubId;
400   uint64_t endpointId;
401 };
402 
403 /**
404  * Data provided in CHRE_EVENT_MSG_SERVICE_READY.
405  */
406 struct chreMsgServiceReadyEvent {
407   /**
408    * The message hub ID and endpoint ID of the endpoint.
409    */
410   uint64_t hubId;
411   uint64_t endpointId;
412 
413   /**
414    * The descriptor of the service, an ASCII null-terminated string.
415    */
416   char serviceDescriptor[CHRE_MSG_MAX_SERVICE_DESCRIPTOR_LEN];
417 };
418 
419 /**
420  * Retrieves metadata for a given endpoint.
421  *
422  * If the given message hub ID and endpoint ID are not associated with a valid
423  * endpoint, this method will return false and info will not be populated.
424  *
425  * @param hubId The message hub ID of the endpoint for which to get info.
426  * @param endpointId The endpoint ID of the endpoint for which to get info.
427  * @param info The non-null pointer to where the metadata will be stored.
428  *
429  * @return true if info has been successfully populated.
430  *
431  * @since v1.11
432  */
433 bool chreMsgGetEndpointInfo(uint64_t hubId, uint64_t endpointId,
434                             struct chreMsgEndpointInfo *info);
435 
436 /**
437  * Configures whether this nanoapp will receive updates regarding an endpoint
438  * that is connected with a message hub and a specific service.  The hubId can
439  * be CHRE_MSG_HUB_ID_ANY to configure notifications for matching endpoints that
440  * are connected with any message hub. The endpoint ID can be
441  * CHRE_MSG_ENDPOINT_ID_ANY to configure notifications for all endpoints that
442  * match the given hub.
443  *
444  * If this API succeeds, the nanoapp will receive endpoint notifications via
445  * CHRE_EVENT_MSG_ENDPOINT_READY with chreMsgEndpointReadyEvent.
446  *
447  * If one or more endpoints matching the filter are already ready when this
448  * function is called, CHRE_EVENT_MSG_ENDPOINT_READY will be immediately
449  * posted to this nanoapp.
450  *
451  * @param hubId The message hub ID of the endpoint for which to configure
452  *     notifications for all endpoints that are connected with any message hub.
453  * @param endpointId The endpoint ID of the endpoint for which to configure
454  *     notifications.
455  * @param enable true to enable notifications.
456  *
457  * @return true on success
458  *
459  * @since v1.11
460  */
461 bool chreMsgConfigureEndpointReadyEvents(uint64_t hubId, uint64_t endpointId,
462                                          bool enable);
463 
464 /**
465  * Configures whether this nanoapp will receive updates regarding all endpoints
466  * that are connected with the message hub that provide the specified service.
467  *
468  * If this API succeeds, the nanoapp will receive endpoint notifications via
469  * CHRE_EVENT_MSG_SERVICE_READY with chreMsgServiceReadyEvent.
470  *
471  * If one or more endpoints matching the filter are already ready when this
472  * function is called, CHRE_EVENT_MSG_SERVICE_READY will be immediately posted
473  * to this nanoapp.
474  *
475  * @param hubId The message hub ID of the endpoint for which to configure
476  *     notifications for all endpoints that are connected with any message hub.
477  * @param serviceDescriptor The descriptor of the service associated with the
478  *     endpoint for which to configure notifications, a null-terminated ASCII
479  *     string. If not NULL, the underlying memory must outlive the notifications
480  *     configuration. If NULL, this will return false.
481  * @param enable true to enable notifications.
482  *
483  * @return true on success
484  *
485  * @see chreMsgConfigureEndpointReadyEvents
486  * @since v1.11
487  */
488 bool chreMsgConfigureServiceReadyEvents(uint64_t hubId,
489                                         const char *serviceDescriptor,
490                                         bool enable);
491 
492 /**
493  * Retrieves metadata for a currently active session ID.
494  *
495  * If the given session ID is not associated with a valid session or if the
496  * caller nanoapp is not a participant in the session, this method will return
497  * false and info will not be populated.
498  *
499  * @param sessionId The session ID of the session for which to get info.
500  * @param info The non-null pointer to where the metadata will be stored.
501  *
502  * @return true if info has been successfully populated.
503  *
504  * @since v1.11
505  */
506 bool chreMsgSessionGetInfo(uint16_t sessionId, struct chreMsgSessionInfo *info);
507 
508 /**
509  * Publishes services exposed by this nanoapp, which will be included with the
510  * endpoint metadata visible to other endpoints in the system.
511  *
512  * This function must be invoked from nanoappStart(), which ensures stable
513  * output of the list of services supported by the nanoapp. Calls made outside
514  * of nanoappStart() will have no effect.
515  *
516  * Although nanoapps are recommended to only call this API once with all
517  * services it intends to publish, if called multiple times, each call will
518  * append to the list of published services.
519  *
520  * The implementation must allow for a nanoapp to publish at least
521  * CHRE_MSG_MINIMUM_SERVICE_LIMIT services and at most UINT8_MAX services. If
522  * calling this function would result in exceeding the limit, the services must
523  * not be published and it must return false.
524  *
525  * @param services A non-null pointer to the list of services to publish.
526  * @param numServices The number of services to publish, i.e. the length of the
527  *     services array.
528  *
529  * @return true if the publishing is successful.
530  *
531  * @since v1.11
532  */
533 bool chreMsgPublishServices(const struct chreMsgServiceInfo *services,
534                             size_t numServices);
535 
536 /**
537  * Opens a session with an endpoint.
538  *
539  * If this function returns true, the result of session initiation will be
540  * provided by a CHRE_EVENT_MSG_SESSION_OPENED or CHRE_EVENT_MSG_SESSION_CLOSED
541  * event containing the same hub ID, endpoint ID, and service descriptor
542  * parameters. Nanoapps may only open one session for each unique combination of
543  * parameters.
544  *
545  * @param hubId The message hub ID of the endpoint. Can be CHRE_MSG_HUB_ID_ANY
546  *     to open a session with the default endpoint.
547  * @param endpointId The endpoint ID of the endpoint. Can be
548  *     CHRE_MSG_ENDPOINT_ID_ANY to open a session with a specified service. The
549  *     service cannot be NULL in this case.
550  * @param serviceDescriptor The descriptor of the service associated with the
551  *     endpoint with which to open the session, a null-terminated ASCII string.
552  *     Can be NULL. The underlying memory must remain valid at least until the
553  *     session is closed - for example, it should be a pointer to a static const
554  *     variable hard-coded in the nanoapp.
555  *     NOTE: as event data supplied to nanoapps does not live beyond the
556  *     nanoappHandleEvent() invocation, it is NOT valid to use the serviceData
557  *     array provided inside chreMsgServiceReadyEvent here.
558  *
559  * @return true if the request was successfully dispatched, or false if a
560  *     synchronous error occurred, in which case no subsequent event will be
561  *     sent.
562  *
563  * @since v1.11
564  */
565 bool chreMsgSessionOpenAsync(uint64_t hubId, uint64_t endpointId,
566                              const char *serviceDescriptor);
567 
568 /**
569  * Closes a session with an endpoint.
570  *
571  * If the given session ID is not associated with a valid session or if the
572  * calling nanoapp is not a participant in the session, this method will return
573  * false.
574  *
575  * The nanoapp will receive a CHRE_EVENT_MSG_SESSION_CLOSED event when the
576  * session teardown is complete. The session is immediately unavailable for
577  * sending. It is unspecified whether any in-flight messages sent by the
578  * other endpoint will be received prior to CHRE_EVENT_MSG_SESSION_CLOSED, but
579  * once this event is delivered, no further data will be received.
580  *
581  * @param sessionId ID of the session to close.
582  *
583  * @return true if the session closure process was initiated.
584  *
585  * @since v1.11
586  */
587 bool chreMsgSessionCloseAsync(uint16_t sessionId);
588 
589 /**
590  * Send a message to an endpoint over an active session.
591  *
592  * This is similar to the stateless host message APIs, such as
593  * chreSendMessageWithPermissions(), but it supports sending data to an
594  * arbitrary endpoint, which could be a host app, another nanoapp, or something
595  * else.
596  *
597  * Messages are guaranteed to be delivered in the order they were sent. If an
598  * error occurs while attempting to deliver the message, the session will be
599  * closed by the system with a suitable reason provided in the data sent with
600  * CHRE_EVENT_MSG_SESSION_CLOSED. While this covers most scenarios, no explicit
601  * end-to-end acknowledgement is provided, and any internal timeouts and/or
602  * retries are implementation-dependent. Similar to chreMsgSessionCloseAsync(),
603  * if the session is closed by the other endpoint or system, it is unspecified
604  * whether any in-flight messages were delivered. The option to send reliable
605  * messages over a socket is planned for a future release. In the meantime, if
606  * full reliability is desired for host communication, use
607  * chreSendReliableMessageAsync().
608  *
609  * @param message Pointer to a block of memory to send to the other endpoint in
610  *     this session. NULL is acceptable only if messageSize is 0. This function
611  *     transfers ownership of the provided memory to the system, so the data
612  *     must stay valid and unmodified until freeCallback is invoked.
613  * @param messageSize The size, in bytes, of the given message. Maximum allowed
614  *     size for the destination endpoint is provided in chreMsgEndpointInfo.
615  * @param messageType An opaque value passed along with the message payload,
616  *     using an application/service-defined scheme.
617  * @param sessionId The session over which to send this message, which also
618  *     implicitly identifies the destination service (if used), endpoint, and
619  *     hub. Provided in chreMsgSessionInfo.
620  * @param messagePermissions Bitmask of permissions that must be held to receive
621  *     this message, and will be attributed to the recipient. Primarily relevant
622  *     when the destination endpoint is an Android application. Refer to
623  *     CHRE_MESSAGE_PERMISSIONS.
624  * @param freeCallback Invoked when the system no longer needs the memory
625  *     holding the message. Note that this does not necessarily mean that the
626  *     message has been delivered. If message is non-NULL, this must be
627  *     non-NULL, and if message is NULL, this must be NULL.
628  *
629  * @return true if the message was accepted for transmission, false otherwise.
630  *     Note that even if this method returns false, the freeCallback will be
631  *     invoked, if non-NULL. In either case, the freeCallback may be invoked
632  *     synchronously, so it must not call chreMsgSend() to avoid recursion.
633  *
634  * @since v1.11
635  */
636 bool chreMsgSend(void *message, size_t messageSize, uint32_t messageType,
637                  uint16_t sessionId, uint32_t messagePermissions,
638                  chreMessageFreeFunction *freeCallback);
639 
640 #ifdef __cplusplus
641 }
642 #endif
643 
644 #endif /* _CHRE_MSG_H_ */
645