fixes
[lcr.git] / cause.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** cause database                                                            **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include "stdio.h"
13 #include "sys/types.h"
14 #include "string.h"
15 #include "main.h"
16
17 struct isdn_cause isdn_cause[128] = {
18                         /********************************* - **/ /*38*/
19         { /*0*/         "<No cause>",
20                         "<Kein Grund>" },
21         { /*1*/         "Unallocated number",
22                         "Nummer nicht vergeben" },
23         { /*2*/         "No route to transit network",
24                         "Keine Verbindung zum Netz" },
25         { /*3*/         "No route to destination",
26                         "Zielnummer nicht erreichbar" },
27         { /*4*/         "<Listen to announcement...>",
28                         "<Ansage hoeren...>" },
29         { /*5*/         "Misdialed trunk prefix.",
30                         "Falscher Carrier-Code" },
31         { /*6*/         "Channel unacceptable",
32                         "Kanal nicht akzeptiert" },
33         { /*7*/         "",
34                         "" },
35         { /*8*/         "Preemption",
36                         "Vorkauf" },
37         { /*9*/         "Preemption - circuit reserved",
38                         "Vorkauf - Gasse reserviert" },
39         { /*10*/        "",
40                         "" },
41         { /*11*/        "",
42                         "" },
43         { /*12*/        "",
44                         "" },
45         { /*13*/        "",
46                         "" },
47         { /*14*/        "",
48                         "" },
49         { /*15*/        "",
50                         "" },
51         { /*16*/        "Normal call clearing",
52                         "Normaler Verbindungsabbau" },
53         { /*17*/        "User busy",
54                         "Teilnehmer besetzt" },
55         { /*18*/        "No user responding",
56                         "Teilnehmer antwortet nicht" },
57         { /*19*/        "No answer from user",
58                         "Teilnehmer nimmt nicht ab" },
59         { /*20*/        "Subscriber absent",
60                         "Teilnehmer nicht anwesend" },
61         { /*21*/        "Call rejected",
62                         "Gespraech abgewiesen" },
63         { /*22*/        "Number changed",
64                         "Rufnummer hat sich geaendert" },
65         { /*23*/        "",
66                         "" },
67         { /*24*/        "",
68                         "" },
69         { /*25*/        "",
70                         "" },
71         { /*26*/        "Non-selected user clearing",
72                         "Gespraech woanders angenommen" },
73         { /*27*/        "Destination out of order",
74                         "Gegenstelle ausser Betrieb" },
75         { /*28*/        "Invalid number (incomplete)",
76                         "Fehlerhafte Nummer (n. komplett)" },
77         { /*29*/        "Facility rejected",
78                         "Funktion nicht verfuegbar" },
79         { /*30*/        "",
80                         "" },
81         { /*31*/        "Normal, unspecified",
82                         "Normal, unspezifisch" },
83         { /*32*/        "",
84                         "" },
85         { /*33*/        "",
86                         "" },
87         { /*34*/        "No circuit/channel available",
88                         "Keine Gasse/Kanal verfuegbar" },
89         { /*35*/        "",
90                         "" },
91         { /*36*/        "",
92                         "" },
93         { /*37*/        "",
94                         "" },
95         { /*38*/        "",
96                         "" },
97         { /*39*/        "",
98                         "" },
99         { /*40*/        "",
100                         "" },
101         { /*41*/        "Temporary failure",
102                         "Vorruebergehende Fehlfunktion" },
103         { /*42*/        "Switchting equipment congestion",
104                         "Vermittlungstelle ueberlastet" },
105         { /*43*/        "Access informationen discarded",
106                         "Zugriffsinformationen geloescht" },
107         { /*44*/        "No requested circuit/channel",
108                         "Keine angeforderte Gasse/Kanal" },
109         { /*45*/        "",
110                         "" },
111         { /*46*/        "Precedence call blocked",
112                         "Vorverkaufanruf gesperrt" },
113         { /*47*/        "Resource unavailable, unspecified",
114                         "" },
115         { /*48*/        "",
116                         "" },
117         { /*49*/        "Quality of service not available",
118                         "Qualitaetsmerkmal nicht verfuegbar" },
119         { /*50*/        "Requested facility not subscribed",
120                         "Funktion nicht freigeschaltet" },
121         { /*51*/        "",
122                         "" },
123         { /*52*/        "",
124                         "" },
125         { /*53*/        "Outgoing calls barred within CUG",
126                         "CUG erlaubt keine gehenden Rufe" },
127         { /*54*/        "",
128                         "" },
129         { /*55*/        "Incoming calls barred within CUG",
130                         "CUG erlaubt keine kommenden Rufe" },
131         { /*56*/        "",
132                         "" },
133         { /*57*/        "Bearer capability not authorized",
134                         "Verbindungseigenschaft verboten" },
135         { /*58*/        "Bearer capability not present",
136                         "Verb.eigenschaft n. verfuegbar" },
137         { /*59*/        "",
138                         "" },
139         { /*60*/        "",
140                         "" },
141         { /*61*/        "",
142                         "" },
143         { /*62*/        "",
144                         "" },
145         { /*63*/        "Service or option not available",
146                         "Dienst oder Merkmal nicht verf." },
147         { /*64*/        "",
148                         "" },
149         { /*65*/        "Bearer capability not implement.",
150                         "Verb.eigenschaft nicht unterstue." },
151         { /*66*/        "Channel type not implemented",
152                         "Kanalart nicht unterstuetzt" },
153         { /*67*/        "",
154                         "" },
155         { /*68*/        "",
156                         "" },
157         { /*69*/        "Requested facility not implement.",
158                         "Funktion nicht unterstuetzt" },
159         { /*70*/        "restricted digital informat. only",
160                         "Nur eingeschraenkte digitale inf." },
161         { /*71*/        "",
162                         "" },
163         { /*72*/        "",
164                         "" },
165         { /*73*/        "",
166                         "" },
167         { /*74*/        "",
168                         "" },
169         { /*75*/        "",
170                         "" },
171         { /*76*/        "",
172                         "" },
173         { /*77*/        "",
174                         "" },
175         { /*78*/        "",
176                         "" },
177         { /*79*/        "Service or option not implemented",
178                         "Dienst oder Merkmal n. unterstue." },
179         { /*80*/        "",
180                         "" },
181         { /*81*/        "Invalid call reference value",
182                         "Falsche call reference" },
183         { /*82*/        "Identified channel does not exist",
184                         "Erkannter Kanal existiert nicht" },
185         { /*83*/        "No suspended call with this id",
186                         "Kein geparktes Gespr. f. diese ID" },
187         { /*84*/        "Call identity in use",
188                         "ID in gebrauch" },
189         { /*85*/        "No call suspended",
190                         "Kein geparktes Gespraech" },
191         { /*86*/        "Suspended call has been cleared",
192                         "Geparktes Gespraech wurde beendet" },
193         { /*87*/        "User not member of CUG",
194                         "Teilnehmer nicht in der CUG" },
195         { /*88*/        "Incompatibel destination",
196                         "Gegenstelle nicht kompatibel" },
197         { /*89*/        "",
198                         "" },
199         { /*90*/        "Non-existent CUG",
200                         "CUG existiert nicht" },
201         { /*91*/        "Invalid transit network selection",
202                         "Falscher Carrier-Code" },
203         { /*92*/        "",
204                         "" },
205         { /*93*/        "",
206                         "" },
207         { /*94*/        "",
208                         "" },
209         { /*95*/        "Invalid message, unspecified",
210                         "Fehlerhafte Daten, unbekannt" },
211         { /*96*/        "Information element missing",
212                         "Information wird vermisst" },
213         { /*97*/        "Message type non-existent",
214                         "Message exisitiert nicht" },
215         { /*98*/        "Message not compatible with state",
216                         "Message nicht komatibel" },
217         { /*99*/        "Information element not impl.",
218                         "Information nicht implementiert" },
219         { /*100*/       "Invalid info element contents",
220                         "Fehlerhafterhafte Information" },
221         { /*101*/       "Message not compatible with state",
222                         "Message not kompatibel" },
223         { /*102*/       "Recovery on timer expiry",
224                         "Fehler durch Zeitueberschreitung" },
225         { /*103*/       "Parameter non-existent",
226                         "Parameter fehlt" },
227         { /*104*/       "",
228                         "" },
229         { /*105*/       "",
230                         "" },
231         { /*106*/       "",
232                         "" },
233         { /*107*/       "",
234                         "" },
235         { /*108*/       "",
236                         "" },
237         { /*109*/       "",
238                         "" },
239         { /*110*/       "",
240                         "" },
241         { /*111*/       "Protocol error, unspecified",
242                         "Protokollfehler, unbekannt" },
243         { /*112*/       "",
244                         "" },
245         { /*113*/       "",
246                         "" },
247         { /*114*/       "",
248                         "" },
249         { /*115*/       "",
250                         "" },
251         { /*116*/       "",
252                         "" },
253         { /*117*/       "",
254                         "" },
255         { /*118*/       "",
256                         "" },
257         { /*119*/       "",
258                         "" },
259         { /*120*/       "",
260                         "" },
261         { /*121*/       "",
262                         "" },
263         { /*122*/       "",
264                         "" },
265         { /*123*/       "",
266                         "" },
267         { /*124*/       "",
268                         "" },
269         { /*125*/       "",
270                         "" },
271         { /*126*/       "",
272                         "" },
273         { /*127*/       "Interworking, unspecified",
274                         "Zusammenspiel, unbekannt" },
275 };
276
277 struct isdn_cause isdn_cause_class[8] = {
278                         /********************************* - **/ /*38*/
279         { /*0*/         "(Normal class)",
280                         "(Normale Fehlerklasse)" },
281         { /*16*/        "(Normal class)",
282                         "(Normale Fehlerklasse)" },
283         { /*32*/        "(Resource unavailable class)",
284                         "(Ressourcen nicht verfuegbar)" },
285         { /*48*/        "(Service or option unavailable)",
286                         "(Dienst oder Merkmal n. verfueg.)" },
287         { /*64*/        "(Service or option n.implemented)",
288                         "(Dienst oder Merkmal n. vorhand.)" },
289         { /*80*/        "(Invalid message class)",
290                         "(Fehlerhafte Message)" },
291         { /*96*/        "(Protocol error class)",
292                         "(Klasse der Protokollfehler)" },
293         { /*112*/       "(Interworking class)",
294                         "(Klasse des Zusammenspiels)" },
295 };
296
297 struct isdn_location isdn_location[16] = {
298         { /*0*/         "User",
299                         "Endgerät" },
300         { /*1*/         "Private (Local)",
301                         "Anlage (Lokal)" },
302         { /*2*/         "Public (Local)",
303                         "Vermittlung (Lokal)" },
304         { /*3*/         "Transit",
305                         "Knotenvermittlung" },
306         { /*4*/         "Public (Remote)",
307                         "Vermittlung (Gegenstelle)" },
308         { /*5*/         "Private (Remote)",
309                         "Anlage (Gegenstelle)" },
310         { /*6*/         "",
311                         "" },
312         { /*7*/         "International",
313                         "Fernvermittlung" },
314         { /*8*/         "",
315                         "" },
316         { /*9*/         "",
317                         "" },
318         { /*10*/        "Beyond Interworking",
319                         "Nicht verfuegbar" },
320         { /*11*/        "",
321                         "" },
322         { /*12*/        "",
323                         "" },
324         { /*13*/        "",
325                         "" },
326         { /*14*/        "",
327                         "" },
328         { /*15*/        "",
329                         "" },
330 };
331
332 char *get_isdn_cause(int cause, int location, int type)
333 {
334         static char result[128];
335
336         /* protect us */
337         if (cause<0 || cause>127)
338                 cause = 0;
339
340         switch(type)
341         {
342                 case DISPLAY_CAUSE_NUMBER:
343                 SPRINT(result, "Cause %d", cause);
344                 break;
345
346                 case DISPLAY_CAUSE_ENGLISH:
347                 if (isdn_cause[cause].english[0])
348                         SPRINT(result, "%d - %s", cause, isdn_cause[cause].english);
349                 else    SPRINT(result, "%d - %s", cause, isdn_cause_class[cause>>4].english);
350                 break;
351
352                 case DISPLAY_CAUSE_GERMAN:
353                 if (isdn_cause[cause].german[0])
354                         SPRINT(result, "%d - %s", cause, isdn_cause[cause].german);
355                 else    SPRINT(result, "%d - %s", cause, isdn_cause_class[cause>>4].german);
356                 break;
357
358                 case DISPLAY_LOCATION_ENGLISH:
359                 if (isdn_location[location].english[0])
360                         SPRINT(result, "%d - %s", cause, isdn_location[location].english);
361                 else    SPRINT(result, "%d - Location code %d", cause, location);
362                 break;
363
364                 case DISPLAY_LOCATION_GERMAN:
365                 if (isdn_location[location].german[0])
366                         SPRINT(result, "%d - %s", cause, isdn_location[location].german);
367                 else    SPRINT(result, "%d - Lokationscode %d", cause, location);
368                 break;
369
370                 default:
371                 result[0] = '\0';
372         }
373
374         return(result);
375 }
376
377 /*
378  * collect cause for multipoint
379  * used by Process, Endpoint and Join instance when multiplexing
380  */
381 void collect_cause(int *multicause, int *multilocation, int newcause, int newlocation)
382 {
383         if (newcause == CAUSE_REJECTED) /* call rejected */
384         {
385                 *multicause = newcause;
386                 *multilocation = newlocation;
387         } else
388         if (newcause==CAUSE_NORMAL && *multicause!=CAUSE_REJECTED) /* reject via hangup */
389         {
390                 *multicause = newcause;
391                 *multilocation = newlocation;
392         } else
393         if (newcause==CAUSE_BUSY && *multicause!=CAUSE_REJECTED && *multicause!=CAUSE_NORMAL) /* busy */
394         {
395                 *multicause = newcause;
396                 *multilocation = newlocation;
397         } else
398         if (newcause==CAUSE_OUTOFORDER && *multicause!=CAUSE_BUSY && *multicause!=CAUSE_REJECTED && *multicause!=CAUSE_NORMAL) /* no L1 */
399         {
400                 *multicause = newcause;
401                 *multilocation = newlocation;
402         } else
403         if (newcause!=CAUSE_NOUSER && *multicause!=CAUSE_OUTOFORDER && *multicause!=CAUSE_BUSY && *multicause!=CAUSE_REJECTED && *multicause!=CAUSE_NORMAL) /* anything but not 18 */
404         {
405                 *multicause = newcause;
406                 *multilocation = newlocation;
407         } else
408         if (newcause==CAUSE_NOUSER && *multicause==CAUSE_NOUSER) /* cause 18, use the location */
409         {
410                 *multilocation = newlocation;
411         } else
412         if (*multicause==0) /* no cause yet, use newcause (should be 18) */
413         {
414                 *multicause = newcause;
415                 *multilocation = newlocation;
416         }
417 }
418