2 * IUCV special message driver
4 * Copyright 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/errno.h>
25 #include <linux/device.h>
26 #include <net/iucv/iucv.h>
27 #include <asm/cpcmd.h>
28 #include <asm/ebcdic.h>
31 struct smsg_callback
{
32 struct list_head list
;
35 void (*callback
)(char *from
, char *str
);
39 ("(C) 2003 IBM Corporation by Martin Schwidefsky (schwidefsky@de.ibm.com)");
40 MODULE_DESCRIPTION ("Linux for S/390 IUCV special message driver");
42 static struct iucv_path
*smsg_path
;
44 static DEFINE_SPINLOCK(smsg_list_lock
);
45 static struct list_head smsg_list
= LIST_HEAD_INIT(smsg_list
);
47 static int smsg_path_pending(struct iucv_path
*, u8 ipvmid
[8], u8 ipuser
[16]);
48 static void smsg_message_pending(struct iucv_path
*, struct iucv_message
*);
50 static struct iucv_handler smsg_handler
= {
51 .path_pending
= smsg_path_pending
,
52 .message_pending
= smsg_message_pending
,
55 static int smsg_path_pending(struct iucv_path
*path
, u8 ipvmid
[8],
58 if (strncmp(ipvmid
, "*MSG ", sizeof(ipvmid
)) != 0)
60 /* Path pending from *MSG. */
61 return iucv_path_accept(path
, &smsg_handler
, "SMSGIUCV ", NULL
);
64 static void smsg_message_pending(struct iucv_path
*path
,
65 struct iucv_message
*msg
)
67 struct smsg_callback
*cb
;
68 unsigned char *buffer
;
69 unsigned char sender
[9];
72 buffer
= kmalloc(msg
->length
+ 1, GFP_ATOMIC
| GFP_DMA
);
74 iucv_message_reject(path
, msg
);
77 rc
= iucv_message_receive(path
, msg
, 0, buffer
, msg
->length
, NULL
);
79 buffer
[msg
->length
] = 0;
80 EBCASC(buffer
, msg
->length
);
81 memcpy(sender
, buffer
, 8);
83 /* Remove trailing whitespace from the sender name. */
84 for (i
= 7; i
>= 0; i
--) {
85 if (sender
[i
] != ' ' && sender
[i
] != '\t')
89 spin_lock(&smsg_list_lock
);
90 list_for_each_entry(cb
, &smsg_list
, list
)
91 if (strncmp(buffer
+ 8, cb
->prefix
, cb
->len
) == 0) {
92 cb
->callback(sender
, buffer
+ 8);
95 spin_unlock(&smsg_list_lock
);
100 int smsg_register_callback(char *prefix
,
101 void (*callback
)(char *from
, char *str
))
103 struct smsg_callback
*cb
;
105 cb
= kmalloc(sizeof(struct smsg_callback
), GFP_KERNEL
);
109 cb
->len
= strlen(prefix
);
110 cb
->callback
= callback
;
111 spin_lock_bh(&smsg_list_lock
);
112 list_add_tail(&cb
->list
, &smsg_list
);
113 spin_unlock_bh(&smsg_list_lock
);
117 void smsg_unregister_callback(char *prefix
,
118 void (*callback
)(char *from
, char *str
))
120 struct smsg_callback
*cb
, *tmp
;
122 spin_lock_bh(&smsg_list_lock
);
124 list_for_each_entry(tmp
, &smsg_list
, list
)
125 if (tmp
->callback
== callback
&&
126 strcmp(tmp
->prefix
, prefix
) == 0) {
131 spin_unlock_bh(&smsg_list_lock
);
135 static struct device_driver smsg_driver
= {
140 static void __exit
smsg_exit(void)
142 cpcmd("SET SMSG IUCV", NULL
, 0, NULL
);
143 iucv_unregister(&smsg_handler
, 1);
144 driver_unregister(&smsg_driver
);
147 static int __init
smsg_init(void)
151 if (!MACHINE_IS_VM
) {
152 rc
= -EPROTONOSUPPORT
;
155 rc
= driver_register(&smsg_driver
);
158 rc
= iucv_register(&smsg_handler
, 1);
160 printk(KERN_ERR
"SMSGIUCV: failed to register to iucv");
161 rc
= -EIO
; /* better errno ? */
164 smsg_path
= iucv_path_alloc(255, 0, GFP_KERNEL
);
169 rc
= iucv_path_connect(smsg_path
, &smsg_handler
, "*MSG ",
172 printk(KERN_ERR
"SMSGIUCV: failed to connect to *MSG");
173 rc
= -EIO
; /* better errno ? */
176 cpcmd("SET SMSG IUCV", NULL
, 0, NULL
);
180 iucv_path_free(smsg_path
);
182 iucv_unregister(&smsg_handler
, 1);
184 driver_unregister(&smsg_driver
);
189 module_init(smsg_init
);
190 module_exit(smsg_exit
);
191 MODULE_LICENSE("GPL");
193 EXPORT_SYMBOL(smsg_register_callback
);
194 EXPORT_SYMBOL(smsg_unregister_callback
);