#define VCHIQ_MSG_DSTPORT(msgid) \
((unsigned short)(msgid) & 0xfff)
+#define MAKE_CONNECT (VCHIQ_MSG_CONNECT << TYPE_SHIFT)
+#define MAKE_OPEN(srcport) \
+ ((VCHIQ_MSG_OPEN << TYPE_SHIFT) | ((srcport) << 12))
+#define MAKE_OPENACK(srcport, dstport) \
+ ((VCHIQ_MSG_OPENACK << TYPE_SHIFT) | ((srcport) << 12) | ((dstport) << 0))
+#define MAKE_CLOSE(srcport, dstport) \
+ ((VCHIQ_MSG_CLOSE << TYPE_SHIFT) | ((srcport) << 12) | ((dstport) << 0))
+#define MAKE_DATA(srcport, dstport) \
+ ((VCHIQ_MSG_DATA << TYPE_SHIFT) | ((srcport) << 12) | ((dstport) << 0))
+#define MAKE_PAUSE (VCHIQ_MSG_PAUSE << TYPE_SHIFT)
+#define MAKE_RESUME (VCHIQ_MSG_RESUME << TYPE_SHIFT)
+#define MAKE_REMOTE_USE (VCHIQ_MSG_REMOTE_USE << TYPE_SHIFT)
+#define MAKE_REMOTE_USE_ACTIVE (VCHIQ_MSG_REMOTE_USE_ACTIVE << TYPE_SHIFT)
+
/* Ensure the fields are wide enough */
static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
== 0);
if (queue_message_sync(
state,
NULL,
- VCHIQ_MAKE_MSG(
- VCHIQ_MSG_OPENACK,
- service->localport,
- remoteport),
+ MAKE_OPENACK(service->localport,
+ remoteport),
memcpy_copy_callback,
&ack_payload,
sizeof(ack_payload),
} else {
if (queue_message(state,
NULL,
- VCHIQ_MAKE_MSG(
- VCHIQ_MSG_OPENACK,
+ MAKE_OPENACK(
service->localport,
remoteport),
memcpy_copy_callback,
fail_open:
/* No available service, or an invalid request - send a CLOSE */
- if (queue_message(state, NULL,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
+ if (queue_message(state, NULL, MAKE_CLOSE(0, VCHIQ_MSG_SRCPORT(msgid)),
NULL, NULL, 0, 0) == VCHIQ_RETRY)
goto bail_not_ready;
}
if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
/* Send a PAUSE in response */
- if (queue_message(state, NULL,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
+ if (queue_message(state, NULL, MAKE_PAUSE,
NULL, NULL, 0, QMFLAGS_NO_MUTEX_UNLOCK)
== VCHIQ_RETRY)
goto bail_not_ready;
break;
case VCHIQ_CONNSTATE_PAUSING:
- if (queue_message(state, NULL,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
+ if (queue_message(state, NULL, MAKE_PAUSE,
NULL, NULL, 0,
QMFLAGS_NO_MUTEX_UNLOCK)
!= VCHIQ_RETRY) {
break;
case VCHIQ_CONNSTATE_RESUMING:
- if (queue_message(state, NULL,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
+ if (queue_message(state, NULL, MAKE_RESUME,
NULL, NULL, 0, QMFLAGS_NO_MUTEX_LOCK)
!= VCHIQ_RETRY) {
vchiq_set_conn_state(state,
service->client_id = client_id;
vchiq_use_service_internal(service);
status = queue_message(service->state,
- NULL,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN,
- service->localport,
- 0),
+ NULL, MAKE_OPEN(service->localport),
memcpy_copy_callback,
&payload,
sizeof(payload),
} else {
/* Shutdown mid-open - let the other side know */
status = queue_message(state, service,
- VCHIQ_MAKE_MSG
- (VCHIQ_MSG_CLOSE,
- service->localport,
+ MAKE_CLOSE(service->localport,
VCHIQ_MSG_DSTPORT(service->remoteport)),
NULL, NULL, 0, 0);
}
if (status == VCHIQ_SUCCESS)
status = queue_message(state, service,
- VCHIQ_MAKE_MSG
- (VCHIQ_MSG_CLOSE,
- service->localport,
+ MAKE_CLOSE(service->localport,
VCHIQ_MSG_DSTPORT(service->remoteport)),
NULL, NULL, 0, QMFLAGS_NO_MUTEX_UNLOCK);
}
if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
- if (queue_message(state, NULL,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, NULL,
+ if (queue_message(state, NULL, MAKE_CONNECT, NULL, NULL,
0, QMFLAGS_IS_BLOCKING) == VCHIQ_RETRY)
return VCHIQ_RETRY;
switch (service->srvstate) {
case VCHIQ_SRVSTATE_OPEN:
status = queue_message(service->state, service,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
- service->localport,
+ MAKE_DATA(service->localport,
service->remoteport),
copy_callback, context, size, 1);
break;
case VCHIQ_SRVSTATE_OPENSYNC:
status = queue_message_sync(service->state, service,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
- service->localport,
+ MAKE_DATA(service->localport,
service->remoteport),
copy_callback, context, size, 1);
break;
if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED)
return VCHIQ_RETRY;
- return queue_message(state, NULL,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
- NULL, NULL, 0, 0);
+ return queue_message(state, NULL, MAKE_REMOTE_USE, NULL, NULL, 0, 0);
}
enum vchiq_status vchiq_send_remote_use_active(struct vchiq_state *state)
if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED)
return VCHIQ_RETRY;
- return queue_message(state, NULL,
- VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
+ return queue_message(state, NULL, MAKE_REMOTE_USE_ACTIVE,
NULL, NULL, 0, 0);
}