Share From: http://www.ucunleashed.com/?p=138
A person calls up other party. Ringing happens. Before other party picks up the phone, the calling party decides to hang-up. So the existing transaction has to be cancelled. Here is the use of another message in SIP called CANCEL.
SIP CANCEL operation is used to nullify the existing operation. Ideally it should have been for all the methods available in SIP such as INVITE, REFER, INFO, MESSAGE, BYE.. But it is not very useful for any other operation than INVITE. INVITE is used for initiation a call with second party. It involves the step of ringing and user responding with willingness to talk. That means there is human interaction involved in the transaction. It is for this reason that provisional responses have been used in INVITE. Provisional responses make calling party aware of the call state.
100 TRYING: is the first provisional response of INVITE. It is returned by immediate transaction stateful proxy. When SIP client receives 100 TRYING in response to INVITE, it comes to conclusion that someone has understood the request and created a transaction at its end.
CANCEL operation is valid only after provisional response have been received. This requirement makes it impossible to be used with other operations as INVITE is the only one that uses provisional responses. This reasoning for CANCEL operation is not in vain. It has two reason for this.
1] If 100 Trying has been received that means there is transaction created somewhere in the network. So, if calling user hangs up that means CANCEL must be send to nullify that transaction.
2] Waiting for 100 Trying, before sending CANCEL avoids this race condition.
SIP is a IP based protocol that means messages get travelled over IP. Packets may take different routes. It is possible that the packet that originated before may reach destination later because of different network congestions on different routes. If CANCEL operation is send before 100 Trying is received then it may so happen that destination receives CANCEL operation even before INVITE itself. So meaning of CANCEL may not be served.
If 200 OK has been received from the called party then CANCEL cannot be issued. In such case ACK should be send then session be closed by sending BYE.